def _next(): import valuestore ## Start next app by restarting slider print('rebooting into next app: ', next_index) valuestore.save('slider', 'current', next_index) system.start('slider') pass
def choose_apps(): try: userApps = os.listdir('apps') userApps.reverse() except OSError: userApps = [] apps = userApps apps.extend(['snake', 'clock', 'nickname']) prev_selected = store.load('slider', 'apps') or [] uinterface.skippabletext('< > (de)select, A accept, B cancel') selected = uinterface.menu(apps, selected=prev_selected) if selected is not None: store.save('slider', 'apps', selected)
def get(app_slug, default_config): config = valuestore.load(namespace='app', keyname=app_slug) resave = False if config is None: config = default_config resave = True for key in default_config.keys(): if key not in config: config[key] = default_config[key] resave = True if resave: valuestore.save(namespace='app', keyname=app_slug, value=config) return config
def confirm(ssid, password): term.header(True, "WiFi setup") # For OTA nvs.set_blob("wifi.ssid", ssid) nvs.set_blob("wifi.password", password) nvs.commit() # For apps valuestore.save("system", "wifi.ssid", ssid) valuestore.save("system", "wifi.password", password) print("New configuration has been saved.") print("") print("SSID:\t\t" + ssid) if len(password) < 1: print("No password") else: print("PASSWORD:\t" + password) print("") print("Press any key to return to the homescreen") sys.stdin.read(1) system.home(True)
rgb.framerate(20) rgb.setfont(rgb.FONT_7x5) uinterface.skippabletext(message) def ap_requires_password(ap_type): return "OPEN" != ap_type ap_list = scan_access_point_list() ssids = [ap[0] for ap in ap_list] prompt_message("Select network") choice = uinterface.menu(ssids) if not (choice is None): chosen_ssid, chosen_ap_type = ap_list[choice] pw_required = ap_requires_password(chosen_ap_type) if pw_required: prompt_message("Enter password") chosen_pass = uinterface.text_input() if pw_required else '' if not pw_required or chosen_pass: # For OTA nvs = esp32.NVS("system") nvs.set_blob("wifi.ssid", chosen_ssid) nvs.set_blob("wifi.password", chosen_pass) nvs.commit() # For apps valuestore.save("system", "wifi.ssid", chosen_ssid) valuestore.save("system", "wifi.password", chosen_pass) system.reboot()
print("New MQTT msg") rgb.clear() uinterface.skippabletext(msg) uinterface.connect_wifi() import valuestore settings = valuestore.load('mqttclient', 'settings') if settings is None: settings = {"client_id": "badge"} if "mqtt_server" not in settings: uinterface.skippabletext("Specify MQTT host") settings["mqtt_server"] = uinterface.text_input( "abcdefghijklmnopqrstuvwxzy.0123456789") valuestore.save('mqttclient', 'settings', settings) client_id = settings['client_id'] try: mqttc = MQTTClient(client_id, settings["mqtt_server"]) mqttc.set_callback(mqtt_cb) mqttc.connect() except: # Maybe wrong hostname del settings["mqtt_server"] valuestore.save('mqttclient', 'settings', settings) # Might be something different, rethrow to restart... raise #status = client_id + "/status" topic = client_id + "/text"
def set_slider_time(): uinterface.skippabletext('Set seconds to show each app') seconds = uinterface.text_input(uinterface.NUMERIC_CHARSET) if seconds is not None and seconds != '': store.save('slider', 'time', int(seconds))
print('rebooting into next app: ', next_index) valuestore.save('slider', 'current', next_index) system.start('slider') pass ## Set timer for starting next app virtualtimers.new(time * 1000, _next, hfpm=True) if len(apps) == 0: print('No apps set, slider will start normal launcher instead') system.reboot() if current_index is None or current_index < 0 or current_index >= len(apps): print('Current app index %d is out of the bounds of the set slider apps, setting index to 0' % current_index) try: current_index = 0 valuestore.save('slider', 'current', current_index) except BaseException as error: print('Additional error whilst saving index: %s' % error) system.start('launcher') app = apps[current_index] del apps, current_index, valuestore gc.collect() ## Start current app try: print("Starting app '%s'..." % app) system.__current_app__ = app if app: __import__(app) except BaseException as e: