def string_box(x, y, w, h, text, font, color, justify): display.textColor(color) display.font(font) if justify == justifyCenter: display.cursor(x + int(display.get_string_width(text) / 2), y + int(display.get_string_height(text) / 2)) elif justify == justifyRight: display.cursor(x + display.get_string_width(text), y + int(display.get_string_height(text) / 2)) else: display.cursor(x, y + int(display.get_string_height(text) / 2)) display.print(text)
def nickname(y=5, font="freesansbold12", color=0x000000, unusedParameter=None): nick = machine.nvs_getstr("owner", "name") if not nick: return y lines = lineSplit(nick, display.width(), font) for i in range(len(lines)): line = lines[len(lines) - i - 1] display.font(font) pos_x = int((display.width() - display.get_string_width(line)) / 2) lineHeight = display.get_string_height(line) display.cursor(pos_x, y + lineHeight * (len(lines) - i - 1)) display.textColor(color) display.print(line) return len(lines) * lineHeight
def do_connect(ssid, password): wlan_sta.active(True) if wlan_sta.isconnected(): return None print('Trying to connect to %s...' % ssid) display.print("Trying to", "connect to", ssid) wlan_sta.connect(ssid, password) for retry in range(100): connected = wlan_sta.isconnected() if connected: break time.sleep(0.1) print('.', end='') if connected: print('\nConnected. Network config: ', wlan_sta.ifconfig()) else: print('\nFailed. Not Connected to: ' + ssid) return connected
def _draw(self): if self._visible: display.rect(self.x, self.y, self.w, self.h, True, 0xFFFFFF) display.rect(self.x, self.y, self.w, self.h, False, 0x000000) display.font("freesans9") _ = display.textColor(0x000000) display.cursor(self.x + 1, self.y + 1) totalHeight = 0 for i in range(self.offset, len(self.items)): display.cursor(self.x + 1, display.cursor()[1]) item = self.items[i] lineHeight = display.get_string_height(item) totalHeight += lineHeight if totalHeight < self.h: if i == self.selected: display.rect(self.x, display.cursor()[1], self.w, lineHeight, True, 0x000000) _ = display.textColor(0xFFFFFF) else: _ = display.textColor(0x000000) display.cursor(self.x + 1, display.cursor()[1] + 3) display.print(item + "\n") display.cursor(self.x + 1, display.cursor()[1] - 3)
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 lineCentered(pos_y, line, font, color): display.font(font) pos_x = int((display.width() - display.get_string_width(line)) / 2) display.cursor(pos_x, pos_y) display.textColor(color) display.print(line)
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 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)
import wifimgr import lights import webserver import display import time try: import usocket as socket except: import socket display.print("", " Lights demo", "") lights.demo() display.print(" Wifi connect", "", "") wlan = wifimgr.get_connection() if wlan is None: print("Could not initialize the network connection.") while True: pass # you shall not pass :D print(wlan.ifconfig()) print('starting web server') display.print(" Start", " Web server", "") webserver.start(wlan.ifconfig()[0])
lcd.setBrightness(10) lcd.clear() lcd.setColor(0xCCCCCC) print('Done!') # lcd.println('M5Stack MicroPython '+VERSION, 0, 0) # lcd.println('Device ID:'+node_id) # lcd.println('Boot Mode:') # lcd.println('Hold button A to boot into SAFE mode.') # lcd.println('Hold button B to boot into OFFLINE mode.') # lcd.print('Boot...', 0, 0) # try: # # lcd.image(0, 0, '/flash/img/m5.jpg') # lcd.image(0, 0, '/flash/img/1-1.jpg') # lcd.rect(0, 190, 320, 50, lcd.WHITE, lcd.WHITE) # lcd.setBrightness(500) # except: # pass if not utils.exists('/flash/img/1-1.jpg'): lcd.print('M5GO resource file not found!\n', 0, 0, color=lcd.RED) lcd.print('Please upload to the Internal Filesystem.\n', color=lcd.RED) lcd.print('https://github.com/m5stack/M5GO\n', color=lcd.RED) lcd.setBrightness(300) # BUTTON buttonA = Button(_BUTTON_A_PIN) buttonB = Button(_BUTTON_B_PIN) buttonC = Button(_BUTTON_C_PIN) # SPEAKER speaker = Speaker()
def string(x, y, text, font, color): if font: display.font(font) _ = display.cursor(x, y) _ = display.textColor(color) display.print(text)