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 string_box(x, y, w, h, text, font, color, align, testMode=False, newHeight=0): lines = wordWrap(text, w, font).split("\n") if len(lines) < 1: return for i in range(len(lines)): textWidth = display.getTextWidth(lines[i], font) textHeight = display.getTextHeight(lines[0], font) text_x = x + w // 2 - textWidth // 2 text_y = y + h // 2 - textHeight // 2 + textHeight * i - ( textHeight * (len(lines) - 1)) // 2 if testMode: print("Components", y, h // 2, textHeight // 2, textHeight * i, (textHeight * (len(lines) - 1)) // 2) print("Line", i, lines[i], text_x, text_y) display.drawText(text_x, text_y, lines[i], color, font) if testMode: display.drawRect(text_x, text_y, textWidth, textHeight, 0, 0) display.drawRect(text_x, text_y, textWidth, newHeight, 0, 0)
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 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 draw_message_label(pos, label): if not label: return center_x, center_y = pos padding = 4 label_w, label_h = display.getTextWidth( label), display.getTextHeight(label) + 4 area_x, area_y = center_x - label_w // 2 - padding, center_y - label_h // 2 - padding display.drawRect(area_x, area_y, label_w + padding * 2, label_h + padding * 2, True, 0) display.drawText(area_x + padding, area_y + padding, label, 0xffffff)
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 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 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 _draw(self): if self._visible: display.drawRect(self.x, self.y, self.w, self.h, True, 0x000000) display.drawRect(self.x, self.y, self.w, self.h, False, 0xFFFFFF) cursor = (self.x + 1, self.y + 1) totalHeight = 0 for i in range(len(self.items) - self.offset): cursor = (self.x + 1, cursor[1]) item = self.items[self.offset + i] lineHeight = display.getTextHeight(item, "roboto_regular12") while display.getTextWidth(item, "roboto_regular12") > self.w: item = item[:-1] totalHeight += lineHeight + 6 if totalHeight >= self.h: break color = 0xFFFFFF if self.offset + i == self.selected: display.drawRect(self.x, cursor[1], self.w, lineHeight + 6, True, 0xFFFFFF) color = 0x000000 cursor = (self.x, cursor[1] + 3) display.drawText(cursor[0] + 2, cursor[1], item + "\n", color, "roboto_regular12") cursor = ( self.x, cursor[1] + 3 + display.getTextHeight(item + "\n", "roboto_regular12"))
def uninstall(path): print("Uninstall", path) flist = os.listdir(path) print("files", flist) for i in range(len(flist)): f = flist[i] display.drawFill(0x000000) display.drawRect(0,0,display.width(), 10, True, 0xFFFFFF) display.drawText(2, 0, "UNINSTALL", 0x000000, "org18") drawMessageBox("Removing file...\n{}".format(f)) display.flush() os.remove(path+"/"+f) display.drawFill(0x000000) display.drawRect(0,0,display.width(), 10, True, 0xFFFFFF) display.drawText(2, 0, "UNINSTALL", 0x000000, "org18") drawMessageBox("Removing folder...") display.flush() os.rmdir(path) display.drawFill(0x000000) display.drawRect(0,0,display.width(), 10, True, 0xFFFFFF) display.drawText(2, 0, "UNINSTALL", 0x000000, "org18") drawMessageBox("App removed!") display.flush() time.sleep(2) showMenu()
def __drawThread(): global text, cursorPos, title, __drawChanged, active while active: if __drawChanged: __drawChanged = False display.drawFill(0xFFFFFF) 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) display.flush(display.FLAG_LUT_FASTEST) time.sleep(0.1)
def drawApp(app, position, amount): display.drawFill(0x000000) display.drawRect(0,0,display.width(), 10, True, 0xFFFFFF) display.drawText(2, 0, "UNINSTALL", 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") 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 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 drawTitle(): display.drawFill(0x000000) display.drawRect(0,0,display.width(), 10, True, 0xFFFFFF) display.drawText(2, 0, "SD card tool", 0x000000, "org18")
def _draw(): global _TEXT, _CURSOR_X, _CURSOR_Y, _TITLE, _MODE, _XPOS, _LASTPARTMOVEUP, _VISIBLELINE _MODE_TEXT = "INP" if _MODE == 1: _MODE_TEXT = "CUR" if _MODE == 2: _MODE_TEXT = "ACT" _display.drawFill(0xFFFFFF) _display.drawRect(0, 0, _display.width(), 14, True, 0x000000) _display.drawText(0, 0, _TITLE, 0xFFFFFF, _FONT_KEY) _display.drawText(128 - 24, 0, _MODE_TEXT, 0xFFFFFF, _FONT_KEY) offsetX1 = 0 arrow1 = False offsetX2 = 0 arrow2 = False cursorPos = _calcPos() _TEXTWithCursor = _TEXT[:cursorPos] + "|" + _TEXT[cursorPos:] _TEXTWithCursorLines = _TEXTWithCursor.split("\n") _TEXTWithCursorLines.append("") lineWithCursorLength = _display.getTextWidth( _TEXTWithCursorLines[_CURSOR_Y], _FONT_TEXT) lineWithCursorLengthUntilCursor = _display.getTextWidth( _TEXTWithCursorLines[_CURSOR_Y][:_CURSOR_X], _FONT_TEXT) if (lineWithCursorLength < _display.width()): offsetX = 0 else: offsetX = lineWithCursorLengthUntilCursor + _display.getTextWidth( " ", _FONT_TEXT) - _display.width() // 2 if offsetX < -_display.getTextWidth(" ", _FONT_TEXT): offsetX = -_display.getTextWidth(" ", _FONT_TEXT) arrow = lineWithCursorLength - offsetX > _display.width() if _VISIBLELINE + 1 < _CURSOR_Y: _VISIBLELINE = _CURSOR_Y - 1 if _VISIBLELINE < 0: _VISIBLELINE = 0 if _CURSOR_Y < _VISIBLELINE: _VISIBLELINE = _CURSOR_Y for i in range(len(_TEXTWithCursorLines)): v = "-" if i == _VISIBLELINE: v = ">" arrow1L = False arrow2L = False if _CURSOR_Y == _VISIBLELINE: offsetX1 = offsetX if offsetX > 0: arrow1L = True if arrow: arrow1 = True else: if _display.getTextWidth(_TEXTWithCursorLines[_VISIBLELINE], _FONT_TEXT) > _display.width(): arrow1 = True if _CURSOR_Y == _VISIBLELINE + 1: offsetX2 = offsetX if offsetX > 0: arrow2L = True if arrow: arrow2 = True else: if _display.getTextWidth(_TEXTWithCursorLines[_VISIBLELINE + 1], _FONT_TEXT) > _display.width(): arrow2 = True _display.drawText(-offsetX1, 17 + 0 * 13, _TEXTWithCursorLines[_VISIBLELINE], 0x000000, _FONT_TEXT) _display.drawText(-offsetX2, 17 + 1 * 13, _TEXTWithCursorLines[_VISIBLELINE + 1], 0x000000, _FONT_TEXT) if arrow1: _display.drawRect(119, 17 + 0 * 13, 9, _display.getTextHeight(" ", _FONT_TEXT), True, 0x000000) _display.drawText(120, 17 + 0 * 13, ">", 0xFFFFFF, _FONT_TEXT) if arrow2: _display.drawRect(119, 17 + 1 * 13, 9, _display.getTextHeight(" ", _FONT_TEXT), True, 0x000000) _display.drawText(120, 17 + 1 * 13, ">", 0xFFFFFF, _FONT_TEXT) if arrow1L: _display.drawRect(0, 17 + 0 * 13, 9, _display.getTextHeight(" ", _FONT_TEXT), True, 0x000000) _display.drawText(0, 17 + 0 * 13, "<", 0xFFFFFF, _FONT_TEXT) if arrow2L: _display.drawRect(0, 17 + 1 * 13, 9, _display.getTextHeight(" ", _FONT_TEXT), True, 0x000000) _display.drawText(0, 17 + 1 * 13, "<", 0xFFFFFF, _FONT_TEXT) _display.drawRect(0, _display.height() - 15, _display.width(), 15, True, 0x000000) if _MODE == 0: for i in range(9): item = _XPOS + (i - 4) if item < 0: item = len(_CHAR_MAP) + item if item >= len(_CHAR_MAP): item = item % len(_CHAR_MAP) if _XPOS == item: _display.drawRect(i * 14 + 1, _display.height() - 14, 14, 14, True, 0xFFFFFF) _display.drawRect(i * 14 + 1, _display.height() - 14, 14, 14, False, 0x000000) _display.drawText(i * 14 + 1 + 3, _display.height() - 14, _CHAR_MAP[item], 0x000000, _FONT_KEY) else: _display.drawRect(i * 14 + 1, _display.height() - 14, 14, 14, True, 0x000000) _display.drawText(i * 14 + 1 + 3, _display.height() - 14, _CHAR_MAP[item], 0xFFFFFF, _FONT_KEY) elif _MODE == 1: _display.drawText(0, _display.height() - 14, "CURSOR, A: NL, B: RM", 0xFFFFFF, _FONT_KEY) elif _MODE == 2: _display.drawText(0, _display.height() - 14, "A: OK, B: CANCEL", 0xFFFFFF, _FONT_KEY) else: _display.drawText(0, _display.height() - 14, "Processing...", 0xFFFFFF, _FONT_KEY) _display.flush(_display.FLAG_LUT_FASTEST)
def clear_rect(rect): x, y, w, h = rect display.drawRect(x, y, w, h, True, 0xffffff)
def prompt_boolean(text, title="Notice", true_text="Yes", false_text="No", width=None, height=None, font="Roboto_Regular12", cb=None): """A simple one and two-options dialog if 'false_text' is set to None only one button is displayed. If both 'false_text' and 'true_text' are given a boolean is returned, press B for false, A for true. Pass along a 'cb' callback to make the dialog async, which is needed to make input work when used from a callback The caller is responsible for flushing the display after processing the response. """ global wait_for_interrupt, button_pushed, __cb __cb = cb if width == None: width = display.width() if height == None: height = display.height() x = (display.width() - width) // 2 y = (display.height() - height) // 2 if (x < 0): x = 0 if (y < 0): y = 0 display.drawFill(0xFFFFFF) display.drawRect(0, 0, display.width(), 14, True, 0) display.drawText(0, 0, title, 0xFFFFFF, "Roboto_Regular12") if false_text: false_text = "B: " + false_text true_text = "A: " + true_text display.drawText(0, 36, ugfx.wordWrap(text, None, font), 0x000000, font) if false_text: _button(10, height - display.getTextHeight(false_text, font), false_text, 0x000000, font) _button((width - display.getTextWidth(true_text, font) - 10), height - display.getTextHeight(true_text, font), true_text, 0x000000, font) else: _button(width - 10 - display.getTextWidth(true_text, font), height - display.getTextHeight(true_text, font), true_text, 0x000000, font) display.flush() if cb: ugfx.input_attach(ugfx.BTN_A, __asyncSuccess) ugfx.input_attach(ugfx.BTN_B, __asyncCancel) #Done :-) else: ugfx.input_attach(buttons.BTN_A, None) ugfx.input_attach(buttons.BTN_B, None) while True: if buttons.value(buttons.BTN_A): display.drawFill(0xFFFFFF) display.flush() while buttons.value(buttons.BTN_A) or buttons.value( buttons.BTN_B): time.sleep(0.1) return True if buttons.value(buttons.BTN_B): display.drawFill(0xFFFFFF) display.flush() while buttons.value(buttons.BTN_A) or buttons.value( buttons.BTN_B): time.sleep(0.1) return False
# https://docs.badge.team/esp32-app-development/api-reference/display/ print('Test: Display') import display display.flush() display.drawFill(0x000000) display.drawText(10, 10, "LaserTag 2 :D", 0xFFFF00, "permanentmarker22") display.flush() display.drawCircle(60, 60, 50, 0, 360, True, 0xFFFFFF) display.drawCircle(60, 60, 40, 0, 360, True, 0x000000) display.drawCircle(60, 60, 30, 0, 360, True, 0xFFFFFF) display.drawCircle(60, 60, 20, 0, 360, True, 0x000000) display.drawCircle(60, 60, 10, 0, 360, True, 0xFFFFFF) display.drawLine(1, 1, 100, 100, 0xFFFFFF) display.drawRect(30, 30, 50, 50, True, 0xFFFFFF) display.drawText(150, 25, "STILL", 0xFFFFFF, "Roboto_BlackItalic24") display.drawText(130, 50, "Hacking", 0xFFFFFF, "PermanentMarker22") l = display.getTextWidth("Hacking", "PermanentMarker22") display.drawLine(130, 72, 144 + l, 72, 0xFFFFFF) display.drawLine(140 + l, 52, 140 + l, 70, 0xFFFFFF) display.drawText(140, 75, "Anyway", 0xFFFFFF, "Roboto_BlackItalic24") display.flush() print('done')
def demoThread(): global demoThreadRunning counter = 0 fpsTrig = False w, h, _, _ = display.pngInfo(mascot.snek) display.drawFill(0xFFFF00) prev = time.ticks_ms() av = [0]*100 display.orientation(0) 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 display.orientation(90) drawNickname()
display.drawCircle(76, 59 + x * 65, 3, 0, 360, True, 0xffffff) #ugfx.string(4, 45+28+x*65, departureDir[x], "Roboto_Regular18", ugfx.WHITE) # print direction display.drawText(4, 45 + 30 + x * 65, departureDir[x], 0xFFFFFF, "Roboto_Regular18") if x + 1 < numOfDepartures: #ugfx.area(0, 45+(x+1)*65, 128, 55, ugfx.BLACK) #display.drawRect(0, 45+(x+1)*65, 128, 55,True, 0x000000) display.drawPng( 0, 45 + (x + 1) * 65, "/lib/luxPublicTransport/busTablets.png") else: #ugfx.area(0, 45+(x+1)*65, 128, 55, ugfx.WHITE) display.drawRect(0, 45 + (x + 1) * 65, 128, 55, True, 0xFFFFFF) display.flush(BADGE_EINK_LUT_FASTER) else: print("No change in data, no screen update needed") #####################################No data from API############################################### else: #no data from API print("Number of JSON return: ", 0) refreshCounter = refreshCounter + 1 numOfDepartures = 0 #ugfx.clear(ugfx.WHITE) #display.clear(0xFFFFFF) display.drawFill(0xFFFFFF) #ugfx.string_box(0, -8, 128, 30, "BUS TIME", "Roboto_Black22", ugfx.BLACK, ugfx.justifyCenter) display.drawPng(0, 0, "/lib/luxPublicTransport/busBoardV2.png")
def area(x,y,w,h,color): display.drawRect(x,y,w,h,True,color)
def fill_rounded_box(x,y,w,h,r,color): display.drawRect(x,y,w,h,True,color)
def box(x,y,width,height,color): display.drawRect(x,y,width,height,False,color)
display.flush() display.backlight(255) gpios = [2, 12, 15, 13, 32, 33, 27] names = ["U", "D", "L", "R", "A", "B", "C"] thist = [] touch = [] for i in gpios: touch.append(machine.TouchPad(machine.Pin(i))) thist.append([0] * 5) while 1: line = 0 display.drawFill(0x000000) display.drawRect(0, 0, display.width() - 1, 20, True, 0xFFFF00) display.drawText(0, 0, "TOUCH DEMO", 0x000000, "ocra16") for i in touch: value = i.read() color = 0xAAAAAA touched = 0 if value < 300: color = 0xFFFF00 touched = 1 _ = thist[line].pop(0) thist[line].append(touched) touchCount = 0 for i in range(len(thist[line])): touchCount += thist[line][i] if touchCount > 2: color = 0x0000FF
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)
def draw(self): display.drawRect(self.getRect())