def drawApp(app, position, amount): drawTitle() positionText = "{}/{}".format(position+1, amount) if app["path"].startswith("/sd"): positionText = "SD "+positionText positionWidth = display.getTextWidth(positionText, "org18") display.drawText(display.width()-positionWidth-2, 0, positionText, 0x000000, "org18") titleWidth = display.getTextWidth(app["name"], "7x5") display.drawText((display.width()-titleWidth)//2,display.height()-10, app["name"], 0xFFFFFF, "7x5") try: icon_data = None if app["icon"]: if not app["icon"].startswith(b"\x89PNG"): with open(app["path"]+"/"+app["icon"], "rb") as icon_file: icon_data = icon_file.read() else: icon_data = app["icon"] if not icon_data: display.drawPng(48,15,default_icon) else: info = display.pngInfo(icon_data) if info[0] == 32 and info[1] == 32: display.drawPng(48,15,icon_data) else: drawMessageBox("Invalid icon size\nExpected 32x32!") except BaseException as e: sys.print_exception(e) drawMessageBox("Icon parsing error!") if not position < 1: display.drawText(0, display.height()//2-12, "<", 0xFFFFFF, "roboto_regular18") if not position >= (amount-1): display.drawText(display.width()-10, display.height()//2-12, ">", 0xFFFFFF, "roboto_regular18") display.flush()
def drawLogo(offset = 0, max_height = display.height(), center = True): global cfg_logo try: info = display.pngInfo(cfg_logo) except: return 0 width = info[0] height = info[1] if width > display.width(): print("Image too large (x)") return if height > display.height(): print("Image too large (y)") x = int((display.width() - width) / 2) if center: if max_height - height < 0: #print("Not enough space for logo",max_height,height) #return 0 y = 0 else: y = int((max_height - height) / 2) + offset else: y = offset try: display.drawPng(x,y,cfg_logo) return height except BaseException as e: sys.print_exception(e) return 0
def messageCentered(message, firstLineTitle=True, png=None): try: color = 0x000000 font1 = "Roboto_Regular18" font2 = "Roboto_Regular12" font1Height = 22 #display.getTextHeight(" ", font1) font2Height = 16 #display.getTextHeight(" ", font2) message = message.split("\n") lines = [] for i in range(len(message)): line = message[i] if len(line) < 1: lines.append("") else: if firstLineTitle and i == 0: lines.extend(lineSplit(line, display.width(), font1)) else: lines.extend(lineSplit(line, display.width(), font2)) pngSize = (0, 0) if png != None: try: pngSize = badge.png_info(png) pngSize = [pngSize[0], pngSize[1] + 8] #Little bit of extra offset except BaseException as e: print("Error in PNG height", e) textHeight = len(lines) * font2Height if firstLineTitle: textHeight -= font2Height textHeight += font1Height offset_y = (display.height() - pngSize[1] - textHeight) // 2 display.drawFill() #display.drawLine(0,display.height()//2,display.width()-1,display.height()//2,0) if png != None: try: display.drawPng((display.width() - pngSize[0]) // 2, offset_y, png) offset_y += pngSize[1] except BaseException as e: print("Error in PNG draw", e) for i in range(len(lines)): if firstLineTitle and i == 0: lineCentered(offset_y, lines[i], font1, color) offset_y += font1Height else: lineCentered(offset_y, lines[i], font2, color) offset_y += font2Height display.flush(display.FLAG_LUT_FASTEST) except BaseException as e: print("Error in messageCentered!", e)
def showLoadingScreen(app=""): try: display.drawFill(0x000000) display.drawPng(64, 0, mascot.snek) display.drawText(0, 28, "LOADING APP...", 0xFFFFFF, "org18") display.drawText(0, 52, app, 0xFFFFFF, "org18") display.flush() except: pass
def demoThread(): global demoThreadRunning counter = 0 fpsTrig = False w, h, _, _ = display.pngInfo(mascot.snek) display.drawFill(0xFFFF00) prev = time.ticks_ms() av = [0] * 100 while demoThreadRunning: if counter > 100: fpsTrig = True current = time.ticks_ms() if (current - prev) > 0: fps = 1000 // (current - prev) else: fps = 0 _ = av.pop(0) av.append(fps) fps = 0 for i in range(len(av)): fps += av[i] fps = fps // len(av) display.drawRect(0, 0, display.width() - 1, 20, True, 0xFFFF00) if fpsTrig: display.drawText(0, 0, "{} fps".format(fps), 0x000000, "ocra16") else: display.drawText(0, 0, "Demo time!", 0x000000, "ocra16") my = (display.height() - h) // 2 - (round(math.sin(counter)) - 1) * 10 mx = (display.width() - w) // 2 - (round(math.cos(counter)) - 1) * 10 display.drawPng(mx, my, mascot.snek) #Draw squares display.drawRect(display.width() - 39 - (counter % display.width()), display.height() // 2 - 20, 40, 40, True, 0x00FF00) display.drawRect(counter % display.width(), display.height() // 2 - 10, 20, 20, True, 0xFF0000) #Flush to display display.flush() #Clear away the squares display.drawRect(display.width() - 39 - (counter % display.width()), display.height() // 2 - 20, 40, 40, True, 0xFFFF00) display.drawRect(counter % display.width(), display.height() // 2 - 10, 20, 20, True, 0xFFFF00) #Clear away the mascot display.drawRect(mx, my, w, h, True, 0xFFFF00) #Increment counter counter += 1 #time.sleep(0.01) prev = current drawNickname()
def drawTask(onSleep=False): global gui_redraw, cfg_nickname, gui_apps, gui_app_current, ota_available if gui_redraw or onSleep: gui_redraw = False display.drawFill(COLOR_BG) currHeight = 0 noLine = False if gui_app_current < 0: if cfg_logo: if cfg_nickname: # Logo and nickename enabled, first print nickname display.drawText((display.width()-display.getTextWidth(cfg_nick_text, "roboto_regular12"))//2, currHeight, cfg_nick_text, COLOR_FG, "roboto_regular12") currHeight += display.getTextHeight(cfg_nick_text, "roboto_regular12")#easydraw.nickname() currHeight += 4 display.drawLine(0, currHeight, display.width()-1, currHeight, COLOR_FG) currHeight += 4 #Print logo app_height = display.height()-16-currHeight logoHeight = drawLogo(currHeight, app_height, True) if logoHeight > 0: noLine = True if logoHeight < 1: #Logo enabled but failed to display title = "BADGE.TEAM" subtitle = "PLATFORM" logoHeight = display.getTextHeight(title, "permanentmarker22")+display.getTextHeight(subtitle, "fairlight12") display.drawText((display.width()-display.getTextWidth(title, "permanentmarker22"))//2, currHeight + (app_height - logoHeight)//2,title, COLOR_FG, "permanentmarker22") currHeight += display.getTextHeight(title, "permanentmarker22") display.drawText((display.width()-display.getTextWidth(subtitle, "fairlight12"))//2, currHeight + (app_height - logoHeight)//2,subtitle, COLOR_FG, "fairlight12") currHeight += display.getTextHeight(subtitle, "fairlight12") else: noLine = True display.drawPng(0,0,LOGO) else: display_app(currHeight) if onSleep: info = 'Sleeping...' #elif not rtc.isSet(): # info = "RTC not available" elif ota_available: info = "Update available!" #elif wifi_status_curr: # info = "WiFi connected" else: info = ""#'Press START' if not noLine: display.drawLine(0, display.height()-16, display.width(), display.height()-16, COLOR_FG) easydraw.disp_string_right_bottom(0, info) if len(gui_apps) > 0: drawPageIndicator(len(gui_apps), gui_app_current) if cfg_greyscale: display.flush(display.FLAG_LUT_GREYSCALE) else: display.flush(display.FLAG_LUT_NORMAL) return 1000
def showLoadingScreen(app=""): hourglass = b"\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x005\x00\x00\x00Z\x01\x00\x00\x00\x000?#R\x00\x00\x00jIDAT(\xcf\xad\xd2A\x12\x80 \x08\x05Po\xc0\x95\xbd\xc1\xbf.\xbb\x1f\x91\x8d5\x90:\x15.\xde\x02\xc6\x01\xb4\x94Y\xd0B\x07NB\xbdN\x7f\x10@\xea\x99W\xcdmy!XS\xb9\xcbje2P\x05\x95\xa9t\xed\x12\xf9$\xec\\\xee\x0bZ\x1f\xf4~\xd0\xfa\xba\x0b\x9b\x03}\x9e`\xdf'\x1e\\\xdb\xe3\xea{\x1c\x11m\xf9\xd7\xffm\xfc\xef6\x03^\xc2\x1c\x0eD=\xf5\x00\x00\x00\x00IEND\xaeB`\x82" try: display.drawFill(0xFFFFFF) text = "Loading...\n\n{}".format(app) display.drawText(91, (display.height()-display.getTextHeight(text, "ocra16"))//2, text, 0x000000, "ocra16") display.drawPng(19,19,hourglass) display.flush(display.FLAG_LUT_FASTEST) except: pass
def drawApp(app, position, amount): global extended_menu, appList oneFourthWidth = display.width() // 4 display.drawFill(0x000000) display.drawRect(0, 0, display.width() // (2 if extended_menu else 1), 10, True, 0xFFFFFF) display.drawText(2, 0, "LAUNCHER", 0x000000, "org18") positionText = "{}/{}".format(position + 1, amount) if app["path"].startswith("/sd"): positionText = "SD " + positionText positionWidth = display.getTextWidth(positionText, "org18") display.drawText( display.width() // (2 if extended_menu else 1) - positionWidth - 2, 0, positionText, 0x000000, "org18") titleWidth = display.getTextWidth(app["name"], "7x5") display.drawText( (oneFourthWidth * (3 if extended_menu else 2) - titleWidth // 2), display.height() - 10, app["name"], 0xFFFFFF, "7x5") try: icon_data = None if app["icon"]: if not app["icon"].startswith(b"\x89PNG"): with open(app["path"] + "/" + app["icon"], "rb") as icon_file: icon_data = icon_file.read() else: icon_data = app["icon"] if not icon_data: display.drawPng(oneFourthWidth * (3 if extended_menu else 2) - 16, display.height() // 2 - 16, default_icon) else: info = display.pngInfo(icon_data) if info[0] == 32 and info[1] == 32: display.drawPng( oneFourthWidth * (3 if extended_menu else 2) - 16, display.height() // 2 - 16, icon_data) else: drawMessageBox("Invalid icon size\nExpected 32x32!") except BaseException as e: sys.print_exception(e) drawMessageBox("Icon parsing error!") if not extended_menu: if not position < 1: display.drawText(0, display.height() // 2 - 12, "<", 0xFFFFFF, "roboto_regular18") if not position >= (amount - 1): display.drawText(display.width() - 10, display.height() // 2 - 12, ">", 0xFFFFFF, "roboto_regular18") if appList: appList.draw() display.flush(display.FLAG_LUT_FASTEST)
def start(app, status=False): if status: import term, easydraw, display if app == "" or app == "launcher": term.header(True, "Loading menu...") #easydraw.messageCentered("Loading the menu...", False, "/media/busy.png") else: term.header(True, "Loading application "+app+"...") #easydraw.messageCentered("Loading '"+app+"'...", False, "/media/busy.png") try: info = display.pngInfo("/media/busy.png") display.drawPng((display.width()-info[0])//2, (display.height()-info[1])//2, "/media/busy.png") except: easydraw.messageCentered("Loading...", False, "/media/busy.png") machine.RTC().write_string(app) reboot()
def start(app, status=False): if status: import term, easydraw, display if app == "" or app == "launcher": term.header(True, "Loading menu...") else: term.header(True, "Loading application " + app + "...") try: display.drawFill(0x000000) import mascot display.drawPng(64, 0, mascot.snek) display.drawText(0, 28, "LOADING APP...", 0xFFFFFF, "org18") display.drawText(0, 52, app, 0xFFFFFF, "org18") display.flush() except: easydraw.messageCentered("Loading...", False, "/media/busy.png") machine.RTC().write_string(app) reboot()
def start(app, status=False): for i in range(6): samd.led(i, 0, 0, 0) if status: appName = app if app == "" or app.startswith("dashboard."): term.header(True, "Loading...") appName = "" else: term.header(True, "Loading application " + app + "...") try: display.drawFill() import mascot display.drawPng(64, 0, mascot.snek) display.drawText(0, 28, "LOADING APP...", 0, "org18") display.drawText(0, 52, appName, 0, "org18") display.flush() time.sleep_ms(10) #Give display some time except: easydraw.messageCentered("Loading...", False, "/media/busy.png") machine.RTC().write_string(app) reboot()
def start(app, status=False): if status: appName = app if app == "" or app.startswith("dashboard."): term.header(True, "Loading...") appName = "" else: term.header(True, "Loading application " + app + "...") #easydraw.messageCentered("Loading '"+app+"'...", False, "/media/busy.png") try: #info = display.pngInfo("/media/busy.png") display.drawFill() #display.drawPng((display.width()-info[0])//2, (display.height()-info[1])//2, "/media/busy.png") import mascot display.drawPng(64, 0, mascot.snek) display.drawText(0, 28, "LOADING APP...", 0, "org18") display.drawText(0, 52, appName, 0, "org18") display.flush() except: easydraw.messageCentered("Loading...", False, "/media/busy.png") machine.RTC().write_string(app) reboot()
def drawLogo(offset=0, max_height=display.height(), center=True): global cfg_logo try: info = display.pngInfo(cfg_logo) except: return 0 width = info[0] height = info[1] x = int((display.width() - width) / 2) if center: if max_height - height < 0: y = 0 else: y = int((max_height - height) / 2) + offset else: y = offset try: display.drawPng(x, y, cfg_logo) return height except BaseException as e: sys.print_exception(e) return 0
def display_image(x,y,data): display.drawPng(x,y,data)
def png(x,y,arg): return display.drawPng(x,y,arg)
def eink_png(x,y,img): display.drawPng(x,y,img)
print("~~Updating display~~") lut = BADGE_EINK_LUT_FASTER refreshCounter = refreshCounter + 1 if refreshCounter >= 10: #full deep refresh after 10 normal prints refreshCounter = 0 print("Full screen clear") #display.clear(0xFFFFFF) display.drawFill(0xFFFFFF) lut = BADGE_EINK_LUT_FULL else: lut = BADGE_EINK_LUT_FASTER #ugfx.string_box(0, -8, 128, 30, "BUS TIME", "Roboto_Black22", ugfx.BLACK, ugfx.justifyCenter) #printing title display.drawPng(0, 0, "/lib/luxPublicTransport/busBoardV2.png") display.drawText( 106 - int(display.getTextWidth(temp, "Roboto_Regular18") / 2), 10, temp, 0xFFFFFF, "Roboto_Regular18") display.drawCircle(120, 12, 2, 0, 360, True, 0xFFFFFF) display.drawCircle(120, 12, 1, 0, 360, True, 0x000000) #ugfx.area(0, 45+(0)*65, 128, 55, ugfx.BLACK) #display.drawRect(0, 45+(0)*65, 128, 55,True, 0x000000) display.drawPng(0, 45 + (0) * 65, "/lib/luxPublicTransport/busTablets.png") display.flush(lut)
def drawTask(onSleep=False): global gui_redraw, cfg_nickname, gui_apps, gui_app_current, ota_available if gui_redraw or onSleep: gui_redraw = False display.drawFill(COLOR_BG) currHeight = 0 noLine = False if gui_app_current < 0: if cfg_logo: #Print logo app_height = display.height() - 16 - currHeight logoHeight = drawLogo(currHeight, app_height, True) if logoHeight > 0: noLine = True if logoHeight < 1: #Logo enabled but failed to display title = "BADGE.TEAM" subtitle = "PLATFORM" logoHeight = display.getTextHeight( title, "permanentmarker22") + display.getTextHeight( subtitle, "fairlight12") display.drawText( (display.width() - display.getTextWidth(title, "permanentmarker22")) // 2, currHeight + (app_height - logoHeight) // 2, title, COLOR_FG, "permanentmarker22") currHeight += display.getTextHeight( title, "permanentmarker22") display.drawText( (display.width() - display.getTextWidth(subtitle, "fairlight12")) // 2, currHeight + (app_height - logoHeight) // 2, subtitle, COLOR_FG, "fairlight12") currHeight += display.getTextHeight( subtitle, "fairlight12") else: noLine = True display.drawPng(0, 0, LOGO) else: display_app(currHeight) if onSleep: info = 'Sleeping...' owner = machine.nvs_getstr("owner", "name") fontlist = [ "permanentmarker22", "Roboto_Regular18", "Roboto_Regular12" ] if (owner): display.drawFill(COLOR_BG) for font in fontlist: if font == fontlist[-1]: display.drawText(0, 0, owner, COLOR_FG, font) elif display.getTextWidth(owner, font) <= display.width(): display.drawText( (display.width() - display.getTextWidth(owner, font)) // 2, 0, owner, COLOR_FG, font) break #elif not rtc.isSet(): # info = "RTC not available" elif ota_available: info = "Update available!" #elif wifi_status_curr: # info = "WiFi connected" else: info = "" #'Press START' if not noLine: display.drawLine(0, display.height() - 16, display.width(), display.height() - 16, COLOR_FG) easydraw.disp_string_right_bottom(0, info) if len(gui_apps) > 0: drawPageIndicator(len(gui_apps), gui_app_current) if cfg_greyscale: display.flush(display.FLAG_LUT_GREYSCALE) else: display.flush(display.FLAG_LUT_NORMAL) return 1000
print("sunrise", sunriseSec) print("sunset", sunsetSec) print("night len", nightLen) print("day len", dayLen) print(24 * 3600, ":", dayLen + nightLen) print("now night", nowNight) x = int((nowNight / nightLen) * 296) print("Moon pos:", x) x = int(x - (90 / 2)) print("Moon pos:", x) display.drawFill(0x000000) # Fill the screen with black display.drawPng(x, 8, "/lib/stillsolunaanyway/moon.png") print(display.pngInfo("/lib/stillsolunaanyway/moon.png")) display.drawText(0, 105, sunset, 0xFFFFFF, "Roboto_Regular18") display.drawText(140, 105, nowStr, 0xFFFFFF, "Roboto_Regular18") display.drawText(245, 105, sunrise, 0xFFFFFF, "Roboto_Regular18") display.flush() # Write the contents of the buffer to the display badge.eink_busy_wait() time.sleep(15) #display.drawpng(0,0,moon1.png) except: print( "################################################################################################################################################################"