def waitRelease(i, state): easydraw.messageCentered("ACTION\nRelease " + pinToName[i] + "\n(" + state + ")") print("(" + state + ") ACTION: Release " + pinToName[i]) while mpr121.get(i): time.sleep(0.01) print("OK")
def waitTouch(i, state): easydraw.messageCentered("ACTION\nPress " + pinToName[i] + "\n(" + state + ")") print("(" + state + ") ACTION: Press " + pinToName[i]) while not mpr121.get(i): time.sleep(0.01) print("OK")
def uninstall(): global options selected = options.selected_index() options.destroy() global currentListTitles global currentListTargets if currentListTargets[selected]["category"] == "system": easydraw.messageCentered("Can not uninstall.\nSystem apps can not be removed!",False) time.sleep(2) start() return def perform_uninstall(ok): global install_path if ok: easydraw.msg("Removing "+currentListTitles[selected]+"...", "Uninstalling...",True) install_path = get_install_path() for rm_file in os.listdir("%s/%s" % (install_path, currentListTargets[selected]["file"])): easydraw.msg("Deleting '"+rm_file+"'...") os.remove("%s/%s/%s" % (install_path, currentListTargets[selected]["file"], rm_file)) easydraw.msg("Deleting folder...") os.rmdir("%s/%s" % (install_path, currentListTargets[selected]["file"])) easydraw.msg("Uninstall completed!") start() dialogs.prompt_boolean('Are you sure you want to remove %s?' % currentListTitles[selected], cb=perform_uninstall, title="UNINSTALL")
def serialWarning(): oldOrientation = display.orientation() setDisplayOrientation() easydraw.messageCentered( "NOTICE\n\nThis app can only be controlled using the USB-serial connection.", True, "/media/usb.png") display.orientation(oldOrientation)
def get(url, path): easydraw.messageCentered("Downloading " + path + "\nFrom " + url, True, "/media/busy.png") req = urequests.get(url) f = open(path, "w") f.write(req.raw.read()) f.close() easydraw.messageCentered("Downloaded " + path, True, "/media/ok.png")
def ota(status=False): if status: term.header(True, "Starting update...") easydraw.messageCentered("PLEASE WAIT\nStarting update...", True, "/media/busy.png") rtc = machine.RTC() rtc.write(0, 1) rtc.write(1, 254) reboot()
def _showProgress(msg, error=False, icon_wifi=False): term.header(True, "Installer") print(msg) icon = "/media/busy.png" if error: icon = "/media/alert.png" elif icon_wifi: icon = "/media/wifi.png" easydraw.messageCentered(msg, False, icon)
def ota(status=False): import esp, deepsleep if status: import term, easydraw term.header(True, "Starting update...") easydraw.messageCentered("PLEASE WAIT\nStarting update...", True, "/media/busy.png") esp.rtcmem_write(0, 1) esp.rtcmem_write(1, 254) reboot()
def start(app, status=False): if status: if app == "" or app == "launcher": term.header(True, "Loading menu...") easydraw.messageCentered("PLEASE WAIT\nStarting the menu...", True, "/media/busy.png") else: term.header(True, "Loading application " + app + "...") easydraw.messageCentered("PLEASE WAIT\nStarting '" + app + "'...", True, "/media/busy.png") machine.RTC().write_string(app) reboot()
def passInputDone(password): global chosenSsid machine.nvs_setstr("system", "wifi.ssid", chosenSsid) if password: machine.nvs_setstr("system", "wifi.password", password) else: try: machine.nvs_erase("system", "wifi.password") except: pass easydraw.messageCentered("Settings stored!", True, "/media/ok.png") system.launcher()
def connectClick(pushed): global chosenSsid if pushed: selected = options.selected_text().encode() ssidType = scanResults[ssidList.index(selected)][4] if ssidType == 5: easydraw.messageCentered("WPA Enterprise is not supported yet.", True, "/media/alert.png") system.reboot() chosenSsid = selected if ssidType == 0: passInputDone(None) else: keyboard.show("Password","",passInputDone)
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 install_app(pressed=True): global category if pressed: slug = category[selectBox.selected_index()]["slug"] #Input handling ugfx.input_attach(ugfx.BTN_BACK, btn_unhandled) ugfx.input_attach(ugfx.BTN_OK, btn_unhandled) ugfx.input_attach(ugfx.JOY_UP, btn_unhandled) ugfx.input_attach(ugfx.JOY_DOWN, btn_unhandled) ugfx.input_attach(ugfx.JOY_LEFT, btn_unhandled) ugfx.input_attach(ugfx.JOY_RIGHT, btn_unhandled) category = [] selectBox.clear() easydraw.messageCentered("Installing...\n" + slug, True, "/media/busy.png") with open("/cache/installList", "w") as f: f.write(slug) system.start("dashboard._installer_exec")
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 showMessage(msg, error=False, icon_wifi=False, icon_ok=False): term.header(True, "Installer") print(msg) if error: easydraw.messageCentered("ERROR\n\n"+msg, True, "/media/alert.png") elif icon_wifi: easydraw.messageCentered("PLEASE WAIT\n\n"+msg, True, "/media/wifi.png") elif icon_ok: easydraw.messageCentered(msg, True, "/media/ok.png") else: easydraw.messageCentered("PLEASE WAIT\n\n"+msg, True, "/media/busy.png")
def show_category(pressed=True, fromAppInstall=False): global lastCategory if not pressed: return ugfx.input_attach(ugfx.BTN_BACK, btn_unhandled) ugfx.input_attach(ugfx.BTN_OK, btn_unhandled) ugfx.input_attach(ugfx.JOY_UP, btn_unhandled) ugfx.input_attach(ugfx.JOY_DOWN, btn_unhandled) ugfx.input_attach(ugfx.JOY_LEFT, btn_unhandled) ugfx.input_attach(ugfx.JOY_RIGHT, btn_unhandled) ugfx.clear(ugfx.WHITE) global category if not fromAppInstall: lastCategory = selectBox.selected_index() slug = repo.categories[lastCategory]["slug"] easydraw.messageCentered("Loading category...\n" + slug, True, "/media/busy.png") display.drawFill() selectBox.clear() try: category = repo.getCategory(slug) gc.collect() for package in category: selectBox.add_item(package["name"]) selectBox.visible(True) selectBox.enabled(True) #Input handling ugfx.input_attach(ugfx.BTN_OK, install_app) ugfx.input_attach(ugfx.BTN_BACK, show_categories) ugfx.input_attach(ugfx.JOY_UP, btn_unhandled) ugfx.input_attach(ugfx.JOY_DOWN, btn_unhandled) ugfx.input_attach(ugfx.JOY_LEFT, btn_unhandled) ugfx.input_attach(ugfx.JOY_RIGHT, btn_unhandled) #Flush screen display.flush(display.FLAG_LUT_NORMAL) except BaseException as e: sys.print_exception(e) easydraw.messageCentered("An error occured!", False, "/media/alert.png") display.drawFill() time.sleep(1) show_categories()
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 read(path, render="experimental", begin=0, lines=15): global view, start, read_lines, breaking_mode, parsed_lines, parsed_fonts, article_length, f, eof, first_run, file start = begin read_lines = lines breaking_mode = render parsed_lines = [] parsed_fonts = [] article_length = 0 eof = False first_run = True file = path easydraw.messageCentered( "Loading " + path + "\nFrom " + str(start) + " to " + str(start + lines), True, "/media/busy.png") try: f = open(path, mode='r', encoding='utf-8') easydraw.messageCentered("Rendering", True, "/media/ok.png") read_data() view = create_view(0, "next") except BaseException as e: import sys, system sys.print_exception(e) system.home()
def wait(duration=timeout, showStatus=False): if showStatus: import easydraw, term term.header(True, "Connecting...") print("Connecting to WiFi...") easydraw.messageCentered("Connecting...", True, "/media/wifi.png") while not status(): time.sleep(1) duration -= 1 if duration < 0: if showStatus: term.header(True, "Failed!") print("Could not connect to WiFi.") easydraw.messageCentered("Failed!", True, "/media/alert.png") return False if showStatus: term.header(True, "Connected!") print("Connected to WiFi.") easydraw.messageCentered("Connected!", True, "/media/ok.png") return True
import machine, display, time, system, consts, easydraw, network, neopixel, mpr121, sndmixer, identification PREV_TGT = 2 CURR_TGT = 3 # 1) Introduction currentState = machine.nvs_getint('system', 'factory_checked') or 0 if currentState >= PREV_TGT: machine.nvs_setint('system', 'factory_checked', CURR_TGT) system.home() easydraw.messageCentered( "FACTORY\n" + consts.INFO_FIRMWARE_NAME + "\nBuild " + str(consts.INFO_FIRMWARE_BUILD), True) display.flush() time.sleep(1.5) # 2) Determine badge type easydraw.messageCentered(identification.getName(), True) display.flush() time.sleep(3) # 3) Calibrate the MPR121 import _mpr121calib # 4) Make sure that WiFi works easydraw.messageCentered("WiFi\nScanning...", True) display.flush() sta_if = network.WLAN(network.STA_IF) sta_if.active(True)
import badge, easydraw, woezel, wifi lvl = badge.nvs_get_u8('ota', 'fixlvl', 0) if lvl < 3: if not badge.nvs_get_u16("modaudio", "mixer_ctl_0"): badge.nvs_set_u16("modaudio", "mixer_ctl_0", (0 << 15) + (0 << 8) + (1 << 7) + (32 << 0)) badge.nvs_set_u16("modaudio", "mixer_ctl_1", (0 << 15) + (32 << 8) + (0 << 7) + (32 << 0)) badge.nvs_set_u8('ota', 'fixlvl', 3) if lvl < 5: wifi.connect() if wifi.wait(30, True): for bloatware in [ 'event_schedule', 'de_rode_hack', 'hacker_gallery', 'angry_nerds_podcast' ]: # This is ugly, but if 1 app is already up to date we just try to fill the device with the rest try: easydraw.messageCentered("Updating...\n" + bloatware, True, '/media/flag.png') woezel.install(bloatware) except: pass badge.nvs_set_u8('ota', 'fixlvl', 5)
def crashedWarning(): import easydraw easydraw.messageCentered("FATAL ERROR\nthe app has crashed", False, "/media/alert.png")
def serialWarning(): import easydraw easydraw.messageCentered( "This app can only be controlled using the USB-serial connection!", False, "/media/crown.png")
import term, mpr121, time, display, machine, easydraw, _mpr121mapping try: import buttons buttons.detach(buttons.BTN_START) except: pass pinToName = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11"] try: pinToName = _mpr121mapping.pinToName except: pass easydraw.messageCentered("CALIBRATION\nDo not press any buttons!") time.sleep(1) # ---- try: verification = _mpr121mapping.verification use_verification = True except: verification = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] use_verification = False # ---- mpr121.configure([], 24, 12) # Automatic detection baseLine = [0] * 12
def showMessage(message="", icon=None): easydraw.messageCentered(message, False, icon)
import term, system, time, version, wifi, buttons, orientation, display import tasks.otacheck as otacheck import easydraw orientation.default() term.header(True, "Update check") print("Checking for updates...") print("") print("Currently installed:",version.name,"(Build "+str(version.build)+")") available = 0 easydraw.messageCentered("Connecting to WiFi...", False, "/media/wifi.png") wifi.connect() wifi.wait() if not wifi.status(): easydraw.messageCentered("No WiFi!\n\nPress A to start update\nPress B to cancel", False) title = "Could not connect to WiFi!" message = "Unable to check for updates. You can still attempt to start the OTA update procedure.\n" message += "Currently installed: "+version.name+" (Build "+str(version.build)+")\n" else: info = otacheck.download_info() if info: print("Server has: ",info['name']," (Build "+str(info['build'])+")") if info["build"] > version.build: easydraw.messageCentered("Update available!\n({})\n\nPress A to start update\nPress B to cancel".format(version.build), False) message = "A new firmware version is available. Update?\n" message += "Currently installed: "+version.name+" (Build "+str(version.build)+")\n" message += "Available : "+info["name"]+" (Build "+str(info["build"])+")" elif info["build"] < version.build:
def serialWarning(): import easydraw easydraw.messageCentered( "NOTICE\n\nThis app can only be controlled using the USB-serial connection.", True, "/media/crown.png")
def crashedWarning(): import easydraw easydraw.messageCentered( "An error occured!\n\nThe running app has crashed.", True, "/media/alert.png")
import easydraw, network, machine, system, keyboard, ugfx easydraw.messageCentered("Scanning...", True, "/media/wifi.png") sta_if = network.WLAN(network.STA_IF); sta_if.active(True) scanResults = sta_if.scan() ssidList = [] for AP in scanResults: ssidList.append(AP[0]) ssidSet = set(ssidList) options = ugfx.List(0,0,ugfx.width(),ugfx.height()) for ssid in ssidSet: try: ssidStr = ssid.decode("ascii") options.add_item(ssidStr) except: pass chosenSsid = "" def connectClick(pushed): global chosenSsid if pushed: selected = options.selected_text().encode() ssidType = scanResults[ssidList.index(selected)][4] if ssidType == 5: easydraw.messageCentered("WPA Enterprise is not supported yet.", True, "/media/alert.png") system.reboot()