def start(): device = oled.getDevice() font = oled.getFont() brands_font = oled.make_font("fa-brands.ttf", device.height - 30) icon = '\uf7bb' #raspberry-pi if not readConfig(): oled.scPrint(oled.center('ERROR'), '', 'Couldn\'t read config', '', '', oled.center('Script stopped!')) time.sleep(5) exit() if not DEBUG: for i in range(33, 138): #print fancy chars on startup oled.puts(chr(i)) oled.flush() time.sleep(0.025) time.sleep(2) with canvas(device) as draw: w, h = draw.textsize(text=icon, font=brands_font) left = (device.width - w) / 2 draw.text((left, 25), text=icon, font=brands_font) draw.text((0, 0), text=oled.center('StatusPi'), font=font) draw.text((0, 10), text=oled.center('Version ' + VERSION), font=font) time.sleep(5)
def nightMode(): device = oled.getDevice() font = oled.getFont() splash = 5 x = 40 y = 53 while (1): now = datetime.datetime.now() now_time = now.strftime("%H:%M:%S") f = "%H:%M:%S" d_str = '04:00:00' thr_clock = datetime.datetime.strptime(d_str, f) if now.time() > thr_clock.time(): return with canvas(device) as draw: if (splash > 0): draw.text((0, 20), text=oled.center('Night Mode'), font=font, fill="white") splash -= 1 draw.text((x, y), text=now_time, font=font, fill="grey") if (now.strftime("%S") == '59') and (splash == 0): x = random.randint(0, 80) y = random.randint(0, 52) time.sleep(1)
def piholeStatus(): device = oled.getDevice() with canvas(device, dither=None) as draw: queries = pihole.getQueries() blocked = pihole.getBlocked() percentage = pihole.getPercentage() if pihole.getStatus(): ph_status = "(Running)" else: ph_status = "(Stopped)" if ((queries == -1) or (blocked == -1) or (percentage == -1)): oled.oPrint(oled.center("PiHole") + "\n\n" + oled.center("Fehler")) else: fnt = oled.getFont() draw.text((0, 0), font=fnt, text=oled.center("PiHole " + ph_status)) draw.text((0, 20), font=fnt, text=oled.concat("Queries:", queries)) draw.text((0, 30), font=fnt, text=oled.concat("Blocking:", blocked)) draw.text((0, 40), font=fnt, text=oled.concat("Percent:", str(percentage) + "%")) pct_bar = 127 * (percentage / 100) draw.rectangle((pct_bar, 63, 0, 50), fill="white") draw.rectangle((127, 63, 0, 50), outline="grey") time.sleep(INTERVALL)
def piholeStatus(): if (DEBUG): print('piHole Status') device = oled.getDevice() try: piholeip = cfg['pihole']['ip'] except Exception as e: oled.scPrint(oled.center('Error [PiHole]'), '', oled.center('Could not'), oled.center('find config!')) time.sleep(INTERVALL) return for i in range(0, INTERVALL): #refresh every second for INTERVALL times with canvas(device, dither=None) as draw: queries = pihole.getQueries(piholeip) blocked = pihole.getBlocked(piholeip) percentage = pihole.getPercentage(piholeip) if pihole.getStatus(piholeip): ph_status = "(Active)" else: ph_status = "(STOPPED)" if ((queries == -1) or (blocked == -1) or (percentage == -1)): oled.oPrint( oled.center("PiHole") + "\n\n" + oled.center("Fehler")) else: fnt = oled.getFont() draw.text((0, 0), font=fnt, text=oled.center("PiHole " + ph_status)) draw.text((0, 20), font=fnt, text=oled.concat("Queries:", queries)) draw.text((0, 30), font=fnt, text=oled.concat("Blocking:", blocked)) draw.text((0, 40), font=fnt, text=oled.concat("Percentage:", str(percentage) + "%")) pct_bar = 127 * (percentage / 100) draw.rectangle((pct_bar, 63, 0, 50), fill="white") draw.rectangle((127, 63, 0, 50), outline="grey") time.sleep(1)
def weather(): if (DEBUG): print('Weather') MAX_LENGTH = oled.getWidth() device = oled.getDevice() regulator = framerate_regulator(fps=1) weather_font = oled.make_font("fa-solid.ttf", device.height - 40) font = oled.getFont() try: w_in = open("weather.wtd", "r") #Weather City1 name1 = oled.center(w_in.readline().rstrip()) temp1 = w_in.readline().rstrip() condition1 = oled.center(umlaute(w_in.readline().rstrip())) icon1 = w_in.readline().rstrip() #Weather City2 name2 = oled.center(w_in.readline().rstrip()) temp2 = w_in.readline().rstrip() condition2 = oled.center(umlaute(w_in.readline().rstrip())) icon2 = w_in.readline().rstrip() #Forecast f_name = oled.center(w_in.readline().rstrip()) f_icon1 = w_in.readline().rstrip() f_temp1_min = w_in.readline().rstrip() f_temp1_max = w_in.readline().rstrip() f_icon2 = w_in.readline().rstrip() f_temp2_min = w_in.readline().rstrip() f_temp2_max = w_in.readline().rstrip() w_in.close() except Exception as e: oled.scPrint('Error [Weather]', '', str(e)) time.sleep(INTERVALL) else: code1 = getIcon(icon1) code2 = getIcon(icon2) if not condition1: condition1 = oled.center("Error!") code1 = '\uf00d' if not condition2: condition2 = oled.center("Error!") code2 = '\uf00d' #WETTER1 diff = (len(condition1) - MAX_LENGTH) * 6 if diff <= 0: diff = 1 #Print strings that are <21 chars long a = 0 with regulator: for x in range(0, diff): with canvas(device) as draw: w, h = draw.textsize(text=code1, font=weather_font) left = (device.width - w) / 2 top = ((device.height - h) / 2) - 5 draw.text((left, top), text=code1, font=weather_font) draw.text((0, 0), text=name1, font=font) draw.text((a, 43), text=condition1, font=font) draw.text((0, 53), text=oled.center(temp1 + '°C'), font=font) if ( x == 0 ): #Don't scroll in the first seconds, for enough time to read time.sleep(2) if (diff > 0): a -= 1 diff -= 1 time.sleep(INTERVALL / 2) #WETTER2 diff = (len(condition2) - MAX_LENGTH) * 6 if diff <= 0: diff = 1 #Print strings that are <21 chars long a = 0 with regulator: for x in range(0, diff): with canvas(device) as draw: w, h = draw.textsize(text=code2, font=weather_font) left = (device.width - w) / 2 top = ((device.height - h) / 2) - 5 draw.text((left, top), text=code2, font=weather_font) draw.text((0, 0), text=name2, font=font) draw.text((a, 43), text=condition2, font=font) draw.text((0, 53), text=oled.center(temp2 + '°C'), font=font) if ( x == 0 ): #Don't scroll in the first seconds, for enough time to read time.sleep(2) if (diff > 0): a -= 1 diff -= 1 time.sleep(INTERVALL / 2) #Forecast if DEBUG: print('Forecast') with canvas(device) as draw: weather_font = oled.make_font("fa-solid.ttf", device.height - 45) width = device.width height = device.height icon1 = getIcon(f_icon1) icon2 = getIcon(f_icon2) today = datetime.date.today() tomorrow = today + datetime.timedelta(days=1) d_a_tomorrow = tomorrow + datetime.timedelta(days=1) draw.line((63, 20, 63, 64), fill="white") draw.text((0, 0), font=font, text=f_name) w1, h1 = draw.textsize(text=icon1, font=weather_font) left = (width / 4) - (w1 / 2) top = ((height - h1) / 2) - 2 w2, h2 = draw.textsize(text=icon2, font=weather_font) right = ((width / 4) * 3) - (w2 / 2) draw.text((left, top), text=icon1, font=weather_font) draw.text((right, top), text=icon2, font=weather_font) draw.text((0, height - 20), font=font, text=oled.half(f_temp1_max + '/' + f_temp1_min + '°C', f_temp2_max + '/' + f_temp2_min + '°C')) draw.text((0, height - 10), font=font, text=oled.half(findDay(str(tomorrow), True), findDay(str(d_a_tomorrow), True)), fill="orange") time.sleep(INTERVALL)