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 list_categories(): global options global text global categories try: categories except: ugfx.input_init() draw_msg('Getting categories') try: f = urequests.get("https://badge.team/eggs/categories/json", timeout=30) categories = f.json() except: draw_msg('Failed!') draw_msg('Returning to launcher :(') appglue.start_app('launcher', False) f.close() draw_msg('Done!') options = ugfx.List(0, 0, int(ugfx.width() / 2), ugfx.height()) text = ugfx.Textbox(int(ugfx.width() / 2), 0, int(ugfx.width() / 2), ugfx.height()) ugfx.input_attach(ugfx.JOY_UP, lambda pushed: ugfx.flush() if pushed else False) ugfx.input_attach(ugfx.JOY_DOWN, lambda pushed: ugfx.flush() if pushed else False) ugfx.input_attach(ugfx.BTN_A, select_category) ugfx.input_attach( ugfx.BTN_B, lambda pushed: appglue.start_app("launcher", False) if pushed else False) ugfx.input_attach( ugfx.BTN_START, lambda pushed: appglue.start_app("") if pushed else False) ugfx.clear(ugfx.WHITE) ugfx.flush() while options.count() > 0: options.remove_item(0) for category in categories: options.add_item("%s (%d) >" % (category["name"], category["eggs"])) options.selected_index(0) text.text("Install or update eggs from the hatchery here\n\n\n\n") ugfx.string_box(148, 0, 148, 26, "Hatchery", "Roboto_BlackItalic24", ugfx.BLACK, ugfx.justifyCenter) ugfx.line(148, 78, 296, 78, ugfx.BLACK) ugfx.string_box(148, 78, 148, 18, " A: Open category", "Roboto_Regular12", ugfx.BLACK, ugfx.justifyLeft) ugfx.string_box(148, 92, 148, 18, " B: Return to home", "Roboto_Regular12", ugfx.BLACK, ugfx.justifyLeft) ugfx.line(148, 110, 296, 110, ugfx.BLACK) ugfx.string_box(148, 110, 148, 18, " badge.team", "Roboto_Regular12", ugfx.BLACK, ugfx.justifyLeft) ugfx.flush(ugfx.LUT_FULL) gc.collect()
def program_main(): print("--- SPONSORS APP ---") ugfx.init() ugfx.set_lut(ugfx.LUT_FULL) ugfx.clear(ugfx.BLACK) ugfx.flush() show_sponsors() appglue.start_app("") # Return home
def ber_task(): global whenToTrigger now = time.time() if now >= whenToTrigger: badge.nvs_set_u8('badge', 'evrt', 1) print("BADGE EVENT REMINDER ACTIVATED") appglue.start_app("badge_event_reminder") idleFor = whenToTrigger - now if idleFor < 0: idleFor = 0 return idleFor
def splash_about_countdown_trigger(): global splashAboutCountdown try: splashAboutCountdown except: splash_about_countdown_reset() splashAboutCountdown -= 1 if splashAboutCountdown<0: appglue.start_app('magic', False) else: print("[SPLASH] Magic in "+str(splashAboutCountdown)+"...")
def ber_task(): global whenToTrigger # braindead time.time() implementation. it's 2 hours in the # future. now = time.time() - 7200 if now >= whenToTrigger and now < whenToTrigger + 600 + 3600: badge.nvs_set_u8('badge','evrt',1) print("BADGE EVENT REMINDER ACTIVATED") appglue.start_app("badge_event_reminder") idleFor = whenToTrigger - now if idleFor < 0: idleFor = 0 return idleFor * 1000
def install_app(active): if active: global options global text global packages global selected_app index = options.selected_index() ugfx.input_attach(ugfx.JOY_UP, 0) ugfx.input_attach(ugfx.JOY_DOWN, 0) ugfx.input_attach(ugfx.BTN_A, 0) ugfx.input_attach(ugfx.BTN_B, 0) ugfx.input_attach(ugfx.BTN_START, 0) ugfx.clear(ugfx.BLACK) ugfx.string(40, 25, "Installing:", "Roboto_BlackItalic24", ugfx.WHITE) ugfx.string(100, 55, packages[index]["name"], "PermanentMarker22", ugfx.WHITE) ugfx.flush() latest = False import woezel selected_app = packages[index]["slug"] try: woezel.install(selected_app) except woezel.LatestInstalledError: latest = True except: ugfx.string(160, 85, "Failed", "Roboto_BlackItalic24", ugfx.WHITE) ugfx.flush() time.sleep(4) list_categories() return ugfx.clear(ugfx.WHITE) if latest: ugfx.string(40, 25, "Already installed:", "Roboto_BlackItalic24", ugfx.BLACK) else: ugfx.string(40, 25, "Installed:", "Roboto_BlackItalic24", ugfx.BLACK) ugfx.string(100, 55, packages[index]["name"], "PermanentMarker22", ugfx.BLACK) ugfx.string(0, 115, "[ A: START | B: BACK ]", "Roboto_Regular12", ugfx.BLACK) ugfx.input_attach(ugfx.BTN_A, start_app) ugfx.input_attach(ugfx.BTN_B, start_categories) ugfx.input_attach( ugfx.BTN_START, lambda pushed: appglue.start_app("") if pushed else False) ugfx.flush() gc.collect()
def start_self_update(): global is_updating is_updating = True log('+ Starting self update') attempts = 0 attempts_max = 5 log('+ Waiting for network...') while not wifi.sta_if.isconnected(): if attempts > attempts_max: log('+ Giving up wifi... Skipping update!') is_updating = False return time.sleep(1) pass # Attempt to install new version and restart the app if it succeeds try: woezel.install('hackeriet') appglue.start_app('hackeriet') except: log('+ woezel.install failed. May already be up to date.') is_updating = False
def show(force=False): if (not badge.nvs_get_u8('sponsors', 'shown', 0)) or force: needToInstall = True version = 0 try: with open("/lib/sponsors/version", "r") as f: version = int(f.read(99)) print("[SPONSORS] Current version: "+str(version)) except: print("[SPONSORS] Not installed!") if version>=14: needToInstall = False if needToInstall: install() try: with open("/lib/sponsors/version", "r") as f: version = int(f.read(99)) # Now we know for sure that a version of the sponsors app has been installed badge.nvs_set_u8('sponsors', 'shown', 1) appglue.start_app("sponsors") except: pass
def list_categories(): global options global categories try: categories except: ugfx.input_init() easydraw.msg('Getting categories', "Loading...", True) try: f = urequests.get("https://badge.disobey.fi/eggs/categories/json", timeout=30) categories = f.json() except: easydraw.msg('Failed :(') appglue.start_app('launcher', False) f.close() easydraw.msg('Success :)') options = ugfx.List(0, 0, int(ugfx.width()), ugfx.height()) ugfx.input_attach(ugfx.JOY_UP, dummy_button_cb) ugfx.input_attach(ugfx.JOY_DOWN, dummy_button_cb) ugfx.input_attach(ugfx.BTN_START, select_category) ugfx.input_attach( ugfx.BTN_B, lambda pushed: appglue.start_app("launcher", False) if pushed else False) ugfx.clear(ugfx.WHITE) ugfx.flush() while options.count() > 0: options.remove_item(0) for category in categories: options.add_item("%s (%d) >" % (category["name"], category["eggs"])) options.selected_index(0) ugfx.flush(ugfx.LUT_FULL) gc.collect()
def list_apps(slug): global options global text global packages ugfx.input_attach(ugfx.JOY_UP, 0) ugfx.input_attach(ugfx.JOY_DOWN, 0) ugfx.input_attach(ugfx.BTN_A, 0) ugfx.input_attach(ugfx.BTN_B, 0) ugfx.input_attach(ugfx.BTN_START, 0) while options.count() > 0: options.remove_item(0) text.text("Downloading list of eggs...") ugfx.flush(ugfx.LUT_FULL) try: f = urequests.get("https://badge.sha2017.org/eggs/category/%s/json" % slug, timeout=30) try: packages = f.json() finally: f.close() except BaseException as e: print("[Installer] Failed to download list of eggs:") sys.print_exception(e) text.text("Download failed") ugfx.flush(ugfx.LUT_FULL) list_categories() gc.collect() return for package in packages: options.add_item("%s rev. %s" % (package["name"], package["revision"])) options.selected_index(0) ugfx.input_attach(ugfx.JOY_UP, show_description) ugfx.input_attach(ugfx.JOY_DOWN, show_description) ugfx.input_attach(ugfx.BTN_A, install_app) ugfx.input_attach(ugfx.BTN_B, lambda pushed: list_categories() if pushed else False) ugfx.input_attach( ugfx.BTN_START, lambda pushed: appglue.start_app('') if pushed else False) show_description(True) gc.collect()
def install_app(active): if active: global options global text global packages global selected_app index = options.selected_index() ugfx.input_attach(ugfx.JOY_UP, 0) ugfx.input_attach(ugfx.JOY_DOWN, 0) ugfx.input_attach(ugfx.BTN_A, 0) ugfx.input_attach(ugfx.BTN_B, 0) ugfx.input_attach(ugfx.BTN_START, 0) ugfx.clear(ugfx.BLACK) ugfx.string(40, 25, "Installing:", "Roboto_BlackItalic24", ugfx.WHITE) ugfx.string(100, 55, packages[index]["name"], "PermanentMarker22", ugfx.WHITE) ugfx.flush() import woezel selected_app = packages[index]["slug"] woezel.install(selected_app) ugfx.clear(ugfx.WHITE) ugfx.string(40, 25, "Installed:", "Roboto_BlackItalic24", ugfx.BLACK) ugfx.string(100, 55, packages[index]["name"], "PermanentMarker22", ugfx.BLACK) ugfx.string(0, 115, "[ A: START | B: BACK ]", "Roboto_Regular12", ugfx.BLACK) ugfx.input_attach(ugfx.BTN_A, start_app) ugfx.input_attach(ugfx.BTN_B, start_categories) ugfx.input_attach( ugfx.BTN_START, lambda pushed: appglue.start_app("") if pushed else False) ugfx.flush() gc.collect()
appglue.start_app('launcher', False) f.close() easydraw.msg('Success :)') options = ugfx.List(0, 0, int(ugfx.width()), ugfx.height()) ugfx.input_attach(ugfx.JOY_UP, dummy_button_cb) ugfx.input_attach(ugfx.JOY_DOWN, dummy_button_cb) ugfx.input_attach(ugfx.BTN_START, select_category) ugfx.input_attach( ugfx.BTN_B, lambda pushed: appglue.start_app("launcher", False) if pushed else False) ugfx.clear(ugfx.WHITE) ugfx.flush() while options.count() > 0: options.remove_item(0) for category in categories: options.add_item("%s (%d) >" % (category["name"], category["eggs"])) options.selected_index(0) ugfx.flush(ugfx.LUT_FULL) gc.collect() if not connectWiFi(): easydraw.msg('WiFi failure :(') appglue.start_app('launcher', False) else: list_categories()
def splash_input_start(pressed): # Pressing start always starts the launcher if pressed: appglue.start_app("launcher", False)
def run(): global options selected = options.selected_index() options.destroy() global currentListTargets appglue.start_app(currentListTargets[selected]["file"])
if badge.battery_charge_status() == False and pm.usb_attached( ) and badge.battery_volt_sense() > 2500: badge.nvs_set_u16('splash', 'bat.volt.drop', 5200 - badge.battery_volt_sense()) # mV print('Set vDrop to: ' + str(4200 - badge.battery_volt_sense())) vDrop = badge.nvs_get_u16('splash', 'bat.volt.drop', 1000) - 1000 # mV splash_input_init() # post ota script import post_ota setupState = badge.nvs_get_u8('badge', 'setup.state', 0) if setupState == 0: #First boot print("[SPLASH] First boot (start setup)...") appglue.start_app("setup") #elif setupState == 1: # Second boot: Show sponsors # print("[SPLASH] Second boot (show sponsors)...") # badge.nvs_set_u8('badge', 'setup.state', 2) # spoc.show(True) #elif setupState == 2: # Third boot: force OTA check # print("[SPLASH] Third boot (force ota check)...") # badge.nvs_set_u8('badge', 'setup.state', 3) # if not easywifi.failure(): # otac.available(True) #else: # Normal boot # print("[SPLASH] Normal boot... ("+str(machine.reset_cause())+")") # if (machine.reset_cause() != machine.DEEPSLEEP_RESET): # print("... from reset: checking for ota update") # if not easywifi.failure(): # otac.available(True)
def opt_about(self): app.start_app("about")
def opt_downloadmorerom(self): app.start_app("downloadmorerom")
def btn_update(pressed): if pressed: easydraw.msg("Preparing...","Update repo...", True) appglue.start_app("update_woezel_repo", False)
def opt_configure_wifi(self): app.start_app("wifi_setup_term")
def opt_launcher(self): app.start_app("launcher_term")
def opt_installer(self): app.start_app("installer_term")
cfg_services = badge.nvs_get_u8('splash', 'services', True) cfg_logo = badge.nvs_get_str('splash', 'logo', default_logo) cfg_nickname = badge.nvs_get_u8('splash', 'nickname', True) cfg_led_animation = badge.nvs_get_str('splash', 'ledApp', None) # Small hack to install logo if needed try: media = uos.listdir("/media") if not "hackerhotel.png" in media: raise (BaseException("Logo not available")) except: import install_hh_logo # If the user holds down the START button during boot we skip this app and go straight into the launcher if badge.safe_mode() or cfg_disabled: appglue.start_app("launcher", False) # Drop directly into uPython shell if requested if cfg_shell: appglue.start_app("shell", False) # Initialise the default button actions def btn_start(pressed): if pressed: appglue.start_app("launcher", False) def btn_unhandled(pressed): pm.feed()
def btn_start(pressed): if pressed: appglue.start_app("launcher", False)
wifi.connect() wifi.wait() easydraw.msg("Downloading categories...") try: categories = urequests.get("https://badge.team/eggs/categories/json", timeout=30) easydraw.msg("Saving file...") categories_file = open(woezel_repo + '/categories.json', 'w') categories_file.write(categories.text) categories_file.close() easydraw.msg("Loading file...") categories = categories.json() for category in categories: gc.collect() slug = category["slug"] easydraw.msg("Loading '" + category["name"] + "'...") f = urequests.get("https://badge.team/eggs/category/%s/json" % slug, timeout=30) f_file = open(woezel_repo + '/' + slug + '.json', 'w') f_file.write(f.text) f_file.close() easydraw.msg("Done!") appglue.start_app('installer', False) except: easydraw.msg("Failed!") time.sleep(2) appglue.start_app('program_main', False)
def opt_ota_check(self): app.start_app("checkforupdates")
def start_app(pushed): if pushed: global selected_app appglue.start_app(selected_app)
orientation.default() categories = None easydraw.msg("Loading categories...","Installer", True) try: f = open(woezel_repo+"/categories.json") categories = json.loads(f.read()) f.close() gc.collect() easydraw.msg("Done.") except: easydraw.msg("Preparing...","Update repo...", True) appglue.start_app("update_woezel_repo", False) categories_list = ugfx.List(0,0,ugfx.width(),ugfx.height()-48) category_list = ugfx.List(0,0,ugfx.width(),ugfx.height()-48) for category in categories: categories_list.add_item("%s (%d) >" % (category["name"], category["eggs"])) categories_list.selected_index(0) def btn_unhandled(pressed): ugfx.flush() def btn_home(pressed): if pressed: appglue.home()
def stop(): time.sleep(2) appglue.start_app("launcher")
def opt_change_nickname(self): app.start_app("nickname_term")