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 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 available(update=False, show=False): if update: if not wifi.status(): return badge.nvs_get_u8('badge', 'OTA.ready', 0) info = download_info(show) if info: if info["build"] > version.build: badge.nvs_set_u8('badge', 'OTA.ready', 1) return True badge.nvs_set_u8('badge', 'OTA.ready', 0) return badge.nvs_get_u8('badge', 'OTA.ready', 0)
def available(update=False, show=False): if update: if not wifi.status(): return badge.nvs_get_u8('badge', 'OTA.ready', 0) info = download_info(show) if info: if info["build"] > consts.INFO_FIRMWARE_BUILD: badge.nvs_set_u8('badge', 'OTA.ready', 1) return True badge.nvs_set_u8('badge', 'OTA.ready', 0) return badge.nvs_get_u8('badge', 'OTA.ready', 0)
def settings_set(key, val): print('set', key, val) try: return badge.nvs_set_u8(LARSON_NAMESPACE, key, val) except: pass return settings_get(key)
def loop(): print("> angelshifts loop") last_update = int(badge.nvs_get_str("engel", "update", "0")) print("last update: ", last_update) if api_key: # Perform update if update_interval has passed if last_update + update_interval < easyrtc.time.time(): print("angelshifts: updating...") wifi.init() tries = 0 while not wifi.sta_if.isconnected(): time.sleep(0.1) tries += 1 if tries >= wifi_tries: return wakeup_interval next_shift = get_next_shift(api_key) if next_shift: badge.nvs_set_str("engel", "shift_name", next_shift["name"]) badge.nvs_set_str("engel", "shift_loc", next_shift["Name"]) badge.nvs_set_str("engel", "shift_start", next_shift["start"]) badge.nvs_set_str("engel", "shift_end", next_shift["end"]) badge.nvs_set_u8("engel", "notified", 0) else: badge.nvs_set_str("engel", "shift_name", "") badge.nvs_set_str("engel", "update", str(easyrtc.time.time())) else: print("angelshifts: no update needed") # Notify about upcoming shift if it starts in less than notify_time if badge.nvs_get_str("engel", "shift_name", "") and not bool( badge.nvs_get_u8("engel", "notified")): start = int(badge.nvs_get_str("engel", "shift_start", "")) now = easyrtc.time.time() if start > now and start < now + notify_time: global notified badge.vibrator_init() badge.vibrator_activate(200) ugfx.string( 0, 0, "NEXT SHIFT IN {} MINUTES!".format(notify_time // 60), "PermanentMarker22", ugfx.BLACK) ugfx.flush() return wakeup_interval else: print("no api key set up") return 0
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 asked_nickname(value): if value: badge.nvs_set_str("owner", "name", value) # Do the firstboot magic newState = 1 if badge.nvs_get_u8('badge', 'setup.state', 0) == 0 else 3 badge.nvs_set_u8('badge', 'setup.state', newState) # Show the user that we are done easydraw.msg("Hi " + value + "!", 'Your nick has been stored to flash!') time.sleep(0.5) else: badge.nvs_set_u8('badge', 'setup.state', 2) # Skip the sponsors badge.nvs_set_u8('sponsors', 'shown', 1) appglue.home()
import tasks.otacheck as otacheck, easydraw, term, appglue, time, version, easywifi, badge, ugfx, orientation orientation.default() term.header(True, "Update check") print("Checking for updates...") print("") print("Currently installed:", version.name, "(Build " + str(version.build) + ")") easydraw.msg("Current version:", "Update check", True) easydraw.msg_nosplit(str(version.build) + ") " + version.name) time.sleep(3) available = 0 badge.nvs_set_u8('badge', 'OTA.ready', 0) def start(pressed): if pressed: appglue.start_ota() if not easywifi.status(): if not easywifi.enable(): easydraw.msg("Error: could not connect to WiFi!") title = "Update check" message = "?? Unknown state ??" if easywifi.status():
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)
if splash.startswith('bpp '): splash = splash[4:len(splash)] badge.mount_bpp() elif splash.startswith('sdcard '): splash = splash[7:len(splash)] badge.mount_sdcard() __import__(splash) setupState = badge.nvs_get_u8('badge', 'setup.state', 0) if setupState == 0: #First boot print("First boot (start setup)...") __import__("setup") elif setupState == 1: # Second boot: Show sponsors print("Second boot (show sponsors)...") badge.nvs_set_u8('badge', 'setup.state', 2) spoc.show(True) elif setupState == 2: # Third boot: force OTA check print("Third boot (force ota check)...") badge.nvs_set_u8('badge', 'setup.state', 3) if not easywifi.failure(): otac.available(True) start() else: # Normal boot print("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) start()
import badge, easydraw, version lvl = badge.nvs_get_u8('ota', 'fixlvl', 0) if lvl < 4: badge.nvs_set_u8('ota', 'fixlvl', 4)
def u1to2(): badge.nvs_set_u8('sponsors', 'shown', 0) easydraw.msg("Applied patch 2")
def u0to1(): easydraw.msg("Applied patch 1") def u1to2(): badge.nvs_set_u8('sponsors', 'shown', 0) easydraw.msg("Applied patch 2") # Read current patch level lvl = badge.nvs_get_u8('ota', 'fixlvl', 0) if lvl < 1: easydraw.msg( "Running post OTA scripts...", "Still updating anyways...", ) u0to1() easydraw.msg("Post OTA update completed") badge.nvs_set_u8('ota', 'fixlvl', 1) if lvl < 2: easydraw.msg( "Running post OTA scripts...", "Still updating anyways...", ) u1to2() easydraw.msg("Post OTA update completed") badge.nvs_set_u8('ota', 'fixlvl', 2)
import badge, easydraw, time, appglue easydraw.msg("", "Sweary", True) enabled = badge.nvs_get_u8("sweary", "enable", 0) if enabled: enabled = 0 easydraw.msg("Sweary disabled!") else: enabled = 1 easydraw.msg("Sweary enabled!") easydraw.msg("Go back to the splash and wait...") enabled = badge.nvs_set_u8("sweary", "enable", enabled) time.sleep(5) appglue.home()