def step2(): term.header(True, "Security question") key = term.prompt("Name of the hacker event that took place between christmas 2018 and the start of 2019?\nHint: CCC organizes this event. It takes place in Leipzig.\n\n4 characters", 1, 5, "") if (key!="35C3") and (key!="35c3"): message = "Invalid answer." items = ["Exit"] callbacks = [appglue.home] callbacks[term.menu("Download more memory!", items, 0, message)]() if badge.remove_bpp_partition(int("0x"+key)): message = "The partition table has been updated succesfully. Enjoy the extra storage space!" items = ["Exit"] callbacks = [appglue.home] callbacks[term.menu("Download more memory!", items, 0, message)]() else: print("Failure in badge.remove_bpp_partition()! Good luck.")
def show_category(i = None): system.serialWarning() global category if i != None: slug = repo.categories[i]["slug"] name = repo.categories[i]["name"] showMessage("Loading "+slug+"...") try: category = repo.getCategory(slug) except: showMessage("Failed to open category "+slug+"!", True) time.sleep(1) return gc.collect() else: if category == None: print("Internal error.") return try: opt = [] for package in category: opt.append("%s rev. %s" % (package["name"], package["revision"])) opt.append("< Back to categories") while True: sel = term.menu("Installer - "+name, opt) if sel == len(category): return install_app(sel) except BaseException as e: sys.print_exception(e) showMessage(e, True) time.sleep(1) return
def install_app(app): latest = False import woezel selected_app = app["slug"] try: woezel.install(selected_app) except woezel.LatestInstalledError: latest = True except: print('Failed to install!') time.sleep(2) return gc.collect() header = "Installer" if latest: header += (" - You already have the latest version of %s" % app['name']) else: header += (" - app %s installed" % app[name]) items = ["Run %s" % app['name'], "Go back"] option = term.menu(header, items) if option == 0: appglue.start_app(app['slug']) else: return gc.collect()
def menu_main(self): items = ["Python shell", "Apps", "Installer", "Settings", "About", "Check for updates", "Power off"] callbacks = [self.drop_to_shell, self.opt_launcher, self.opt_installer, self.menu_settings, self.opt_about, self.opt_ota_check, self.go_to_sleep] message = "Welcome!\nYour badge is running firmware version "+str(version.build)+": "+version.name+"\n" cb = term.menu("Main menu", items, 0, message) self.menu = callbacks[cb] return
def show_category(i): system.serialWarning() global category slug = categories[i]["slug"] name = categories[i]["name"] showMessage("Loading " + slug + "...") try: try: category = woezel.get_category(slug) except: showMessage("Failed to open category " + slug + "!", True) time.sleep(1) show_categories() gc.collect() opt = [] for package in category: opt.append("%s rev. %s" % (package["name"], package["revision"])) opt.append("< Back to categories") sel = term.menu("Installer - " + name, opt) if sel == len(category): show_categories() install_app(sel, i) except BaseException as e: sys.print_exception(e) showMessage(e, True) time.sleep(1) show_categories()
def list_categories(): global categories while (1): try: categories except: update_repo() cat_list = [] for category in categories: if category['eggs'] > 0: cat_list.append(category["name"]) cat_list.append("< Back") option = term.menu("Installer - Select a category", cat_list) if option != len(cat_list) - 1: catsel = None for category in categories: if category['name'] == cat_list[option]: catsel = category break if catsel is not None: open_category(catsel) else: return gc.collect()
def menu_main(self): message = "Welcome!\nYour badge is running firmware version " + str( consts.INFO_FIRMWARE_BUILD ) + ": " + consts.INFO_FIRMWARE_NAME + "\n" cb = term.menu("Main menu", self.menu_items, 0, message) self.menu = self.menu_fun[cb] return
def show_category(slug, name): system.serialWarning() showMessage("Loading "+slug+"...") try: category = repo.getCategory(slug) except BaseException as e: showMessage("Failed to open category "+slug+"!", True) sys.print_exception(e) time.sleep(1) return gc.collect() try: opt = [] for package in category: opt.append("%s rev. %s" % (package["name"], package["revision"])) opt.append("< Back to categories") sel = term.menu("Installer - "+name, opt) if sel == len(opt)-1: return slug = category[sel]["slug"] category = None gc.collect() install_app(slug) except BaseException as e: sys.print_exception(e) showMessage(e, True) time.sleep(1) return
def menu_safe(self): items = ["Main menu"] callbacks = [self.menu_main] cb = term.menu( "You have started the badge in safe mode.\nServices are disabled.", items) self.menu = callbacks[cb]
def menu_settings(self): items = ["Change nickname", "Configure WiFi", "< Return to main menu"] callbacks = [ self.opt_change_nickname, self.opt_configure_wifi, self.menu_main ] cb = term.menu("Settings", items) self.menu = callbacks[cb]
def menu_main(self): items = ["Python shell", "Apps", "Installer", "Settings", "About", "Check for updates", self.power_off_label] callbacks = [self.drop_to_shell, self.opt_launcher, self.opt_installer, self.menu_settings, self.opt_about, self.opt_ota_check, self.go_to_sleep] message = "Welcome!\nYour badge is running firmware version "+str(consts.INFO_FIRMWARE_BUILD)+": "+consts.INFO_FIRMWARE_NAME+"\n" cb = term.menu("Main menu", items, 0, message) self.menu = callbacks[cb] return
def show_categories(): system.serialWarning() opt = [] for category in categories: opt.append(category["name"]) opt.append("< Back to launcher") sel = term.menu("Installer - Categories", opt) if sel == len(categories): system.launcher(True) show_category(sel)
def show_app(app,category): term.empty_lines() term.header(True, "Installer - %s"%app['name']) items=["Install app %s"%app['name'], "Go back"] option=term.menu("Installer %s %s"%(app['name'],app['description']), items) if option==0: install_app(app) else: return gc.collect()
def menu_settings(self): items = [ "Change nickname", "WiFi configuration", "Update firmware", "< Return to main menu" ] callbacks = [ self.opt_change_nickname, self.opt_configure_wifi, self.opt_ota, self.menu_main, self.menu_main ] cb = term.menu("Settings", items) self.menu = callbacks[cb]
def show_categories(): system.serialWarning() while True: opt = [] for category in repo.categories: opt.append(category["name"]) opt.append("< Back to launcher") sel = term.menu("Installer - Categories", opt) if sel == len(repo.categories): system.launcher(True) opt = [] gc.collect() show_category(repo.categories[sel]["slug"], repo.categories[sel]["name"])
def menu_settings(self): items = [ "Change nickname", "Configure WiFi", "Set default orientation", "Update firmware", "(Reclaim unused flash space)", "< Return to main menu" ] callbacks = [ self.opt_change_nickname, self.opt_configure_wifi, self.opt_configure_orientation, self.opt_ota, self.opt_downloadmorerom, self.menu_main, self.menu_main ] cb = term.menu("Settings", items) self.menu = callbacks[cb]
def scan(): term.header(True, "WiFi setup") print("Scanning...") sta_if = network.WLAN(network.STA_IF) sta_if.active(True) ssid_result = sta_if.scan() ssid_list = [] for ssid in ssid_result: ssid_list.append(ssid[0].decode('utf-8', 'ignore')) ssid_list.append("< Back") option = term.menu("WiFi setup - Select a network", ssid_list) if option != len(ssid_list)-1: password(ssid_result[option][0].decode('utf-8', 'ignore'), ssid_result[option][4])
def menu_settings(self): items = [ "Change nickname", "Configure WiFi", "Set default orientation", "Homescreen services (beta)", "Homescreen LED animation", "Homescreen logo", "Update firmware", "< Return to main menu" ] callbacks = [ self.opt_change_nickname, self.opt_configure_wifi, self.opt_configure_orientation, self.opt_configure_services, self.opt_configure_led, self.opt_configure_picture, self.opt_ota, self.menu_main, self.menu_main ] cb = term.menu("Settings", items) self.menu = callbacks[cb]
def manual(): term.header(True, "WiFi setup - Enter SSID") print("Enter the SSID for the network you want to connect to, ") print("or leave blank to go back. Press RETURN to continue.") ssid = term.prompt("SSID", 1,5) if (len(ssid) >= 1): items = ["WEP / WPA / WPA2", "Open network", "WPA / WPA2 Enterprise", "Return to main menu"] option = term.menu("WiFi setup - Authentication method", items) if option == 0: password(ssid, 1) elif option == 1: password(ssid, 0) elif option == 2: password(ssid, 5)
def menu_settings(self): items = [ "Change nickname", "Change picture", "WiFi configuration", "Change display orientation", "Homescreen configuration", "Calibrate touch buttons", "Update firmware", "< Return to main menu" ] callbacks = [ self.opt_change_nickname, self.opt_configure_picture, self.opt_configure_wifi, self.opt_configure_orientation, self.opt_configure_homescreen, self.opt_configure_calibrate, self.opt_ota, self.menu_main, self.menu_main ] cb = term.menu("Settings", items) self.menu = callbacks[cb]
def menu_main(self): items = [ "Python shell", "Apps", "Installer", "Settings", "Tools", "Check for updates" ] if self.gts: items.append(self.power_off_label) callbacks = [ self.drop_to_shell, self.opt_launcher, self.opt_installer, self.menu_settings, self.menu_tools, self.opt_ota_check, self.go_to_sleep ] message = "" cb = term.menu("Main menu", items, 0, message) self.menu = callbacks[cb] return
def open_category(category): while 1: apps_in_cat = list_apps(category['slug']) if apps_in_cat is None: return app_list = [] for app in apps_in_cat: app_list.append(app["name"]) app_list.append("< Back") option = term.menu("Installer - Select an app", app_list) if option != len(app_list) - 1: appsel = None for app in apps_in_cat: if app['name'] == app_list[option]: appsel = app break if appsel is not None: show_app(app, category) else: return gc.collect()
else: print("You are up-to-date!") easydraw.msg("Up-to-date!") easydraw.msg_nosplit(str(version.build) + ") " + version.name) easydraw.msg("Update anyway?") title = "Up-to-date" message = "You are up-to-date.\n" message += "Currently installed: " + version.name + " (Build " + str( version.build) + ")\n" message += "Available : " + info[ "name"] + " (Build " + str(info["build"]) + ")" else: print("An error occured!") easydraw.msg("Check failed.") easydraw.msg_nosplit(str(version.build) + ") " + version.name) easydraw.msg("Update anyway?") title = "Update check" message = "An error occured while fetching information. You can still choose to start the OTA procedure." else: easydraw.msg("No WiFi!") easydraw.msg_nosplit(str(version.build) + ") " + version.name) easydraw.msg("Update anyway?") title = "Update check" message = "Could not connect to the WiFi network. You can still choose to start the OTA procedure." ugfx.input_attach(ugfx.BTN_START, start) items = ["Cancel", "Start OTA update"] callbacks = [appglue.home, appglue.start_ota] callbacks[term.menu(title, items, 0, message)]()
if "ledsrv.py" in uos.listdir('/lib/' + app): services.append(app) current = machine.nvs_getstr('splash', 'ledApp') while True: options = [] for service in services: title = service if service == current: title += " [Enabled]" options.append(title) options.append(" None (disable LED services)") options.append("< Exit") selected = term.menu("Services", options, 0, "") if selected > len(services): system.home(True) if selected == len(services): current = None try: machine.nvs_erase('splash', 'ledApp') except: pass term.header(True, "Services") print("LED services disabled") time.sleep(1) else: current = services[selected] machine.nvs_setstr('splash', 'ledApp', current) term.header(True, "Services")
def main(): items = ["Install apps", "Update repository", "Return to main menu"] callbacks = [list_categories, update_repo, home] callbacks[term.menu("Installer", items)]()
items = ["Exit"] callbacks = [appglue.home] callbacks[term.menu("Download more memory!", items, 0, message)]() if badge.remove_bpp_partition(int("0x"+key)): message = "The partition table has been updated succesfully. Enjoy the extra storage space!" items = ["Exit"] callbacks = [appglue.home] callbacks[term.menu("Download more memory!", items, 0, message)]() else: print("Failure in badge.remove_bpp_partition()! Good luck.") if (badge.remove_bpp_partition(0x00)): message = "You have already updated the partition table. Enjoy the extra storage space!" items = ["Exit"] callbacks = [appglue.home] callbacks[term.menu("Download more memory!", items, 0, message)]() else: message = "This application updates the partition table to allocate more flash space for storage." message += "\n" message += "Warning:\n" message += "Powering off the badge during the update process will result in a brick.\n" message += "You need to re-flash the badge using a computer in order to recover from such a brick.\n" message += "We provide no guarantee that nothing will go wrong. This new feature is largely UNTESTED.\n" message += "\n" message += " - Make sure you have inserted full batteries\n" message += " - Leave your badge connected to a computer while running this function\n" message += " - This function updates the partition table, it might result in a brick\n" items = ["Cancel", "Continue"] callbacks = [appglue.home, step2]
system.serialWarning() def getOrientationString(currentValue): orientationString = str(currentValue) if currentValue == 0: orientationString = "Landscape" if currentValue == 90: orientationString = "Portrait" if currentValue == 180: orientationString = "Landscape inverted" if currentValue == 270: orientationString = "Portrait inverted" return orientationString items = ["Landscape", "Portrait", "Landscape inverted", "Portrait inverted", "< Back"] options = [0, 90, 180, 270, -1, -1] currentValue = orientation.getDefault() orientationString = getOrientationString(currentValue) message = "Current orientation: "+orientationString+"\n" newValue = options[term.menu("Configure orientation", items, 0, message)] if newValue < 0: system.home(True) term.header(True, "Configure orientation") if orientation.setDefault(newValue): print("Default orientation changed to "+getOrientationString(newValue)) else: print("Default orientation could not be changed to "+getOrientationString(newValue)) time.sleep(1) system.home(True)
def main(): term.empty_lines() items = ["Scan for networks", "Manual SSID entry", "Return to main menu"] callbacks = [scan, manual, home] callbacks[term.menu("WiFi setup", items)]()
def menu_safe(self): items = ["Main menu"] callbacks = [self.menu_main] cb = term.menu("You have started the badge in safe mode!", items) self.menu = callbacks[cb]
def menu_tools(self): items = ["File downloader", "< Return to main menu"] callbacks = [self.opt_downloader, self.menu_main, self.menu_main] cb = term.menu("Tools", items) self.menu = callbacks[cb]