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 drawApp(app, position, amount): display.drawFill(0x000000) display.drawRect(0, 0, display.width(), 10, True, 0xFFFFFF) display.drawText(2, 0, "RECOVERY", 0x000000, "org18") 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") titleHeight = display.getTextHeight(app["name"], "7x5") display.drawText((display.width() - titleWidth) // 2, (display.height() - titleHeight) // 2, app["name"], 0xFFFFFF, "7x5") 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(display.FLAG_LUT_FASTEST)
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 drawMessageBox(text): width = display.getTextWidth(text, "org18") height = display.getTextHeight(text, "org18") display.drawRect((display.width() - width - 4) // 2, (display.height() - height - 4) // 2, width + 2, height + 2, True, 0xFFFFFF) display.drawText((display.width() - width) // 2, (display.height() - height) // 2 - 2, text, 0x000000, "org18")
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 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 drawMessageBox(text): global extended_menu oneFourthWidth = display.width() // 4 width = display.getTextWidth(text, "org18") height = display.getTextHeight(text, "org18") display.drawRect( (oneFourthWidth * (3 if extended_menu else 2) - width - 4) // 2, (display.height() - height - 4) // 2, width + 2, height + 2, True, 0xFFFFFF) display.drawText( (oneFourthWidth * (3 if extended_menu else 2) - width) // 2, (display.height() - height) // 2 - 2, text, 0x000000, "org18")
def draw(): global cx, cy, text, cursorPos, title, mode, xpos display.drawFill(0xFFFFFF) display.drawRect(0, 0, display.width(), 14, True, 0x000000) display.drawText(0, 0, title, 0xFFFFFF, keyFont) modeText = "keyboard" if mode == 1: modeText = "cursor" if mode == 2: modeText = "actions" if cursorPos > len(text): cursorPos = len(text) if cursorPos < 0: cursorPos = 0 textWithCursor = text[:cursorPos] + "|" + text[cursorPos:] textWithCursorLines = textWithCursor.split("\n") for i in range(len(textWithCursorLines)): display.drawText(0, 17 + i * 13, textWithCursorLines[i], 0x000000, textFont) offset = xpos if offset < 4: offset = 4 if offset > (len(charMap[mode]) - 4): offset = len(charMap[mode]) - 4 - 9 if mode < 7: for i in range(9): item = (offset - 4 + i) print(item, len(charMap[mode]), xpos) if xpos == item: display.drawRect(i * 14, display.height() - 14, 14, 14, True, 0x000000) display.drawText(i * 14 + 3, display.height() - 14, charMap[mode][item], 0xFFFFFF, keyFont) else: display.drawRect(i * 14, display.height() - 14, 14, 14, False, 0x000000) display.drawText(i * 14 + 3, display.height() - 14, charMap[mode][item], 0x000000, keyFont) display.flush(display.FLAG_LUT_FASTEST)
def drawPageIndicator(amount, position): x = 5 size = 4 offset = 6 for i in range(amount): display.drawCircle(x, display.height()-8, size, 0, 359, i==position, COLOR_FG) x+= size + offset
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 drawNickname(): owner = machine.nvs_getstr("owner", "name") or "BADGE.TEAM" display.drawFill(0xFFFF00) x = (display.width()-display.getTextWidth(owner, "ocra16"))//2 y = (display.height()-display.getTextHeight(owner, "ocra16"))//2 display.drawText(x,y,owner,0x000000,"ocra16") display.flush() # Send the new buffer to the display display.backlight(0xFF) # Turn on backlight
def msg_nosplit(message, title='Loading...', reset=False): """Show a terminal style loading screen with title title can be optionaly set when resetting or first call """ global messageHistory, lastTitle num_lines = ((display.height() - 16) // display.getTextHeight(" ", version.font_default)) - 2 if reset: lastTitle = title try: messageHistory if reset: raise exception except: display.drawFill(0xFFFFFF) messageHistory = [] lastTitle = title lineHeight = int(display.getTextHeight(" ", version.font_default) / 2) + 5 if len(messageHistory) < num_lines: display.drawText(0, 16 + (len(messageHistory) * lineHeight), message, 0x000000, version.font_default) messageHistory.append(message) else: messageHistory.pop(0) messageHistory.append(message) display.drawRect(0, 16, display.width(), display.height() - 15, True, 0xFFFFFF) for i, message in enumerate(messageHistory): display.drawText(0, 16 + (i * lineHeight), message, 0x000000, version.font_default) display.drawRect(0, 0, display.width(), 14, True, 0) display.drawText(0, 0, lastTitle, 0xFFFFFF, "Roboto_Regular12") #h = display.getTextHeight(" ", version.font_header) #display.drawLine(0, h, display.width(), h, 0x000000) display.flush(display.FLAG_LUT_FASTEST) return len(messageHistory) >= num_lines - 1
def scrollerTask(): global scrollerPos, scrollerEndPos, scrollerStartPos, offsetTest display.windowMove("scroller", scrollerPos, display.height() - 22 - offsetTest) scrollerPos -= 3 if scrollerPos < scrollerEndPos: scrollerPos = scrollerStartPos display.flush() return 25
def draw(vbatt, vusb): display.drawFill(0x000000) display.drawText(0,0,"Battery") display.drawText(0,15,"USB") display.drawText(50,0,str(vbatt)+"v") display.drawText(50,15,str(vusb)+"v") dataPoints.pop(0) dataPoints.append(round(vbatt*8)) for i in range(64): display.drawPixel(i,display.height()-1-dataPoints[i],0xFFFFFF) dataPoints2.pop(0) dataPoints2.append(round(vusb*8)) for i in range(64): display.drawPixel(64+i,display.height()-1-dataPoints2[i],0xFFFFFF) display.flush()
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 msg_nosplit(message, title='Loading...', reset=False): """Show a terminal style loading screen with title title can be optionaly set when resetting or first call """ global messageHistory, lastTitle num_lines = ((display.height() - 11) // display.getTextHeight(" ", "7x5")) if reset: lastTitle = title try: messageHistory if reset: raise exception except: display.drawFill(0x000000) messageHistory = [] lastTitle = title lineHeight = display.getTextHeight(" ", "7x5") if len(messageHistory) < num_lines: display.drawText(0, 11 + (len(messageHistory) * lineHeight), message, 0xFFFFFF, "7x5") messageHistory.append(message) else: messageHistory.pop(0) messageHistory.append(message) display.drawRect(0, 11, display.width(), display.height() - 15, True, 0x000000) for i, message in enumerate(messageHistory): display.drawText(0, 11 + (i * lineHeight), message, 0xFFFFFF, "7x5") display.drawRect(0, 0, display.width(), 10, True, 0xFFFFFF) display.drawText(2, 0, lastTitle, 0x000000, "org18") display.flush(display.FLAG_LUT_FASTEST) return len(messageHistory) >= num_lines - 1
def scrollerThread(): scrollerStartPos = 129 scrollerEndPos = -display.getTextWidth(cfg_nick_text, "permanentmarker22") - 128 scrollerPos = scrollerStartPos global stopThreads while not stopThreads: display.windowMove("scroller", scrollerPos, display.height()-22) scrollerPos-=4 if scrollerPos < scrollerEndPos: scrollerPos = scrollerStartPos display.flush() time.sleep_ms(40)
def msg(message, title = "Loading...", reset = False, wait = 0): num_lines = ((display.height() - 16)//display.getTextHeight(" ", version.font_default)) - 2 scroll = False try: lines = lineSplit(str(message)) for i in range(len(lines)): if i > 0: scroll = msg_nosplit(lines[i]) else: scroll = msg_nosplit(lines[i], title, reset) if (i > 1) and (wait > 0): time.sleep(wait) except BaseException as e: print("!!! Exception in easydraw.msg !!!") print(e) return scroll
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 messageCentered(message, firstLineTitle=True, png=None): #try: if 1: font1 = "Roboto_Regular18" font2 = "Roboto_Regular12" color = 0x000000 display.fill(0xFFFFFF) parts = message.split("\n") lines = [] font = font1 for part in parts: if len(part) < 1: lines.append("") else: lines.extend(lineSplit(part, display.width(), font)) if firstLineTitle: font = font2 offset_y = int(display.height() / 2) #Half of the screen height offset_y -= 9 #Height of the first line divided by 2 if firstLineTitle: offset_y -= 6 * len(lines) - 1 #Height of font1 divided by 2 else: offset_y -= 9 * len(lines) - 1 #Height of font2 divided by 2 if png != None: try: img_info = badge.png_info(png) offset_y -= int(img_info[1] / 2) + 4 img_x = int((display.width() - img_info[0]) / 2) display.png(img_x, offset_y, png) offset_y += img_info[1] + 8 except: pass lineCentered(offset_y, lines[0], font1, color) offset_y += 18 for i in range(len(lines) - 1): if not firstLineTitle: lineCentered(offset_y, lines[i + 1], font1, color) offset_y += 18 else: lineCentered(offset_y, lines[i + 1], font2, color) offset_y += 12 display.flush()
def msg_nosplit(message, title='Loading...', reset=False): global NUM_LINES """Show a terminal style loading screen with title title can be optionaly set when resetting or first call """ global messageHistory try: messageHistory if reset: raise exception except: display.greyscale(False) display.fill(0xFFFFFF) display.textColor(0x000000) display.font(version.font_header) display.cursor(0, 0) display.print(title) messageHistory = [] display.font(version.font_default) lineHeight = display.get_string_height(" ") if len(messageHistory) < NUM_LINES: display.textColor(0x000000) display.cursor(0, 19 + (len(messageHistory) * lineHeight)) display.print(message) messageHistory.append(message) else: messageHistory.pop(0) messageHistory.append(message) display.rect(0, 15, display.width(), display.height() - 15, True, 0xFFFFFF) for i, message in enumerate(messageHistory): display.textColor(0x000000) display.font(version.font_default) display.cursor(0, 19 + (i * lineHeight)) display.print(message) 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] 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 disp_string_right_bottom(y, s, font="freesans9"): display.font(font) l = display.get_string_width(s) display.cursor(display.width() - l, display.height() - (y + 1) * 14) display.textColor(0x000000) display.print(s)
def draw(): global cx, cy, text, cursorPos, title, yOffset, mode display.drawFill(0xFFFFFF) display.drawRect(0, yOffset - 12, display.width(), 12, True, 0x000000) display.drawRect(0, yOffset, display.width(), display.height() - yOffset, False, 0x000000) modeText = "keyboard" if mode == 1: modeText = "cursor" if mode == 2: modeText = "actions" display.drawText(0, yOffset - 12, "[SELECT] " + modeText, 0xFFFFFF, "Roboto_Regular12") display.drawRect(0, 0, display.width(), 14, True, 0) display.drawText(0, 0, title, 0xFFFFFF, "Roboto_Regular12") if cursorPos > len(text): cursorPos = len(text) if cursorPos < 0: cursorPos = 0 textWithCursor = text[:cursorPos] + "|" + text[cursorPos:] textWithCursorLines = textWithCursor.split("\n") for i in range(len(textWithCursorLines)): display.drawText(0, 17 + i * 13, textWithCursorLines[i], 0x000000, textFont) for y in range(3): for x in range(10): xOffset = 0 width = 29 widthOffset = width if y == 1: xOffset = 6 if y == 2 and x == 0: width *= 2 if y == 2 and x == 1: continue if y == 1 and x == 0: width += xOffset xOffset = 0 if y == 2 and x == 9: width += 6 if x == 0 and y == 1 and shift == 4: width *= 2 if x == 1 and y == 1 and shift == 4: width = 0 selected = False if x == cx and y == cy: selected = True if width > 0: display.drawRect( x * widthOffset + xOffset, y * 20 + yOffset, width, 20, True, 0xFFFFFF, ) display.drawRect( x * widthOffset + xOffset, y * 20 + yOffset, width, 20, selected, 0x000000, ) color = 0 if selected: color = 0xFFFFFF offset = shift * 3 cxo = xOffset + charOffsetX # if x == 0 and y == 1: # cxo = xOffset+charOffsetXDouble display.drawText( x * widthOffset + cxo, y * 20 + yOffset + charOffsetY, charMap[y + offset][x], color, keyFont, ) if mode == 2: display.drawRect( 8, yOffset + 8, display.width() - 16, display.height() - yOffset - 16, True, 0xFFFFFF, ) display.drawRect( 8, yOffset + 8, display.width() - 16, display.height() - yOffset - 16, False, 0x000000, ) display.drawText(12, yOffset + 12, "Press A to accept input", 0x000000, "Roboto_Regular12") display.drawText(12, yOffset + 12 + 14, "Press B to cancel", 0x000000, "Roboto_Regular12") display.flush(display.FLAG_LUT_FASTEST)
import display, buttons shift = 0 # 0 = lower, 1 = upper, 2 = caps, 3 = numbers, 4 = symbols mode = 0 # 0 = keyboard, 1 = select, 2 = buttons keyFont = "roboto_regular12" textFont = "roboto_regular18" yOffset = display.height() - 20 * 3 charWidth = display.getTextWidth("X", keyFont) charHeight = display.getTextHeight("X", keyFont) charOffsetX = int((20 - charWidth)) charOffsetXDouble = int((20 - charWidth * 1.5)) charOffsetY = 5 charMap = [] charMap.append(["q", "w", "e", "r", "t", "y", "u", "i", "o", "p"]) charMap.append([" ", "a", "s", "d", "f", "g", "h", "j", "k", "l"]) charMap.append(["SHIFT", " ", "z", "x", "c", "v", "b", "n", "m", "<<"]) # Uppercase charMap.append(["Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P"]) charMap.append([" ", "A", "S", "D", "F", "G", "H", "J", "K", "L"]) charMap.append(["CAPS", " ", "Z", "X", "C", "V", "B", "N", "M", "<<"]) # Caps-lock charMap.append(["Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P"]) charMap.append([" ", "A", "S", "D", "F", "G", "H", "J", "K", "L"]) charMap.append(["1 2 3", " ", "Z", "X", "C", "V", "B", "N", "M", "<<"]) # Numbers charMap.append(["1", "2", "3", "4", "5", "6", "7", "8", "9", "0"]) charMap.append([" ", "@", "#", "$", "%", "^", "&", "*", "(", ")"]) charMap.append(["!@#$", " ", ".", ",", "=", "+", "[", "]", "?", "<<"]) # Numbers 2
def start(): ugfx.input_init() ugfx.set_lut(ugfx.LUT_FASTER) ugfx.clear(ugfx.WHITE) # Instructions if orientation.isLandscape(): x0 = int(display.width() / 2) currentY = 20 display.drawText( x0 + ((display.width() - x0) // 2) - (display.getTextWidth("BADGE.TEAM", "fairlight12") // 2), currentY, "BADGE.TEAM\n", 0x000000, "fairlight12") currentY += display.getTextHeight("BADGE.TEAM", "fairlight12") display.drawText( x0 + int((display.width() - x0) / 2) - int( display.getTextWidth("ESP32 platform", "roboto_regular12") / 2), currentY, "ESP32 platform\n", 0x000000, "roboto_regular12") display.drawLine(x0, 0, x0, display.height() - 1, 0x000000) pixHeight = display.getTextHeight(" ", "roboto_regular12") currentY = pixHeight * 5 lineY = display.height() - pixHeight * 6 - pixHeight // 2 display.drawLine(x0, lineY, display.width() - 1, lineY, 0x000000) display.drawText(x0 + 5, display.height() - pixHeight * 6, "A: Run\n", 0x000000, "roboto_regular12") display.drawText(x0 + 5, display.height() - pixHeight * 5, "START: Return to home\n", 0x000000, "roboto_regular12") display.drawText(x0 + 5, display.height() - pixHeight * 4, "SELECT: Uninstall app\n", 0x000000, "roboto_regular12") lineY = display.height() - pixHeight * 2 - pixHeight // 2 display.drawLine(x0, lineY, display.width() - 1, lineY, 0x000000) display.drawText(x0 + 5, display.height() - pixHeight * 2, consts.INFO_FIRMWARE_NAME, 0x000000, "roboto_regular12") display.drawText(x0 + 5, display.height() - pixHeight, "Build " + str(consts.INFO_FIRMWARE_BUILD), 0x000000, "roboto_regular12") else: pixHeight = display.getTextHeight(" ", "roboto_regular12") display.drawLine(0, display.height() - 18 * 4, display.width(), display.height() - 18 * 4, ugfx.BLACK) display.drawText(0, display.height() - pixHeight * 6, "A: Run\n", 0x000000, "roboto_regular12") display.drawText(0, display.height() - pixHeight * 5, "START: Home\n", 0x000000, "roboto_regular12") display.drawText(0, display.height() - pixHeight * 4, "SELECT: Uninstall\n", 0x000000, "roboto_regular12") lineY = display.height() - pixHeight * 2 - pixHeight // 2 display.drawLine(0, lineY, display.width() - 1, lineY, 0x000000) display.drawText(0, display.height() - pixHeight * 2, consts.INFO_FIRMWARE_NAME, 0x000000, "roboto_regular12") display.drawText(0, display.height() - pixHeight, "Build " + str(consts.INFO_FIRMWARE_BUILD), 0x000000, "roboto_regular12") global options global install_path options = None install_path = None ugfx.input_attach(ugfx.BTN_A, input_a) ugfx.input_attach(ugfx.BTN_B, input_b) ugfx.input_attach(ugfx.BTN_SELECT, input_select) ugfx.input_attach(ugfx.JOY_UP, input_other) ugfx.input_attach(ugfx.JOY_DOWN, input_other) ugfx.input_attach(ugfx.JOY_LEFT, input_other) ugfx.input_attach(ugfx.JOY_RIGHT, input_other) ugfx.input_attach(ugfx.BTN_START, input_start) populate_apps() populate_category() populate_options() # do a greyscale flush on start ugfx.flush(ugfx.GREYSCALE)
def start(): ugfx.input_init() ugfx.set_lut(ugfx.LUT_FASTER) ugfx.clear(ugfx.WHITE) # Instructions if orientation.isLandscape(): x0 = int(display.width() / 2) display.font("fairlight8") currentY = 20 display.cursor( x0 + int((display.width() - x0) / 2) - int(display.get_string_width("BADGE.TEAM") / 2), currentY) display.print("BADGE.TEAM\n") display.font("pixelade9") (_, currentY) = display.cursor() display.cursor( x0 + int((display.width() - x0) / 2) - int(display.get_string_width("ESP32 platform") / 2), currentY) display.print("ESP32 platform\n") display.line(x0, 0, x0, display.height() - 1, 0x000000) display.textColor(0x000000) display.font("pixelade9") currentY = display.get_string_height(" ") * 5 - 5 display.line(x0, currentY, display.width() - 1, currentY, 0x000000) display.cursor(x0 + 5, currentY + 5) display.print("A: Run\n") display.print("B: Return to home\n") display.print("SELECT: Uninstall app\n") (_, currentY) = display.cursor() display.line(x0, currentY, display.width() - 1, currentY, 0x000000) _ = display.cursor(x0 + 5, currentY + 5) display.print(consts.INFO_FIRMWARE_NAME) else: ugfx.line(0, ugfx.height() - 18 * 4, ugfx.width(), ugfx.height() - 18 * 4, ugfx.BLACK) ugfx.string_box(0, ugfx.height() - 18 * 4, ugfx.width(), 18, " A: Run", "Roboto_Regular12", ugfx.BLACK, ugfx.justifyLeft) ugfx.string_box(0, ugfx.height() - 18 * 3, ugfx.width(), 18, " B: Return to home", "Roboto_Regular12", ugfx.BLACK, ugfx.justifyLeft) ugfx.string_box(0, ugfx.height() - 18 * 2, ugfx.width(), 18, " SELECT: Uninstall", "Roboto_Regular12", ugfx.BLACK, ugfx.justifyLeft) ugfx.line(0, ugfx.height() - 18 * 1, ugfx.width(), ugfx.height() - 18 * 1, ugfx.BLACK) ugfx.string_box(0, ugfx.height() - 18 * 1, ugfx.width(), 18, " " + consts.INFO_FIRMWARE_NAME, "Roboto_Regular12", ugfx.BLACK, ugfx.justifyLeft) global options global install_path options = None install_path = None ugfx.input_attach(ugfx.BTN_A, input_a) ugfx.input_attach(ugfx.BTN_B, input_b) ugfx.input_attach(ugfx.BTN_SELECT, input_select) ugfx.input_attach(ugfx.JOY_UP, input_other) ugfx.input_attach(ugfx.JOY_DOWN, input_other) ugfx.input_attach(ugfx.JOY_LEFT, input_other) ugfx.input_attach(ugfx.JOY_RIGHT, input_other) ugfx.input_attach(ugfx.BTN_START, input_other) populate_apps() populate_category() populate_options() # do a greyscale flush on start ugfx.flush(ugfx.GREYSCALE)
def disp_string_right_bottom(y, s, font="Roboto_Regular12"): l = display.getTextWidth(s, font) display.drawText(display.width() - l, display.height() - (y + 1) * 14, s, 0x000000, font)
display.flush(display.FLAG_LUT_NORMAL) return 1000 virtualtimers.new(0, drawTask, True) # Free up space in RAM gc.collect() # Set the RTC if needed and WiFi is allowed if not rtc.isSet() and cfg_wifi: wifi.connect() #Connecting to WiFi automatically sets the time using NTP (see wifiTask) # Text scroller display.windowCreate("scroller", 512, 32) #Workaround!!! windows get corrupted when size is not in units of 8 display.windowShow("scroller") display.windowMove("scroller", 65, display.height()-22) # Move out of visible screen display.drawFill("scroller", COLOR_BG) display.drawText("scroller", 0, 0, cfg_nick_text, COLOR_FG, "permanentmarker22") def scrollerThread(): scrollerStartPos = 129 scrollerEndPos = -display.getTextWidth(cfg_nick_text, "permanentmarker22") - 128 scrollerPos = scrollerStartPos global stopThreads while not stopThreads: display.windowMove("scroller", scrollerPos, display.height()-22) scrollerPos-=4 if scrollerPos < scrollerEndPos: scrollerPos = scrollerStartPos display.flush() time.sleep_ms(40)