Toggle Navigation
Hatchery
Eggs
1_test_app
tmpmod.py
Users
Badges
Login
Register
MCH2022 badge?
go to mch2022.badge.team
tmpmod.py
raw
Content
# File: splash.py # Version: 6.6.6 # Description: Homescreen for SHA2017 badge # License: MIT # Authors: Renze Nicolai <renze@rnplus.nl> # Thomas Roos <?> import ugfx, time, badge, machine, deepsleep, gc import appglue, virtualtimers import easydraw, easywifi, easyrtc import tasks.powermanagement as pm import tasks.otacheck as otac import tasks.resourcescheck as resc import tasks.sponsorscheck as spoc import tasks.services as services import tasks.badgeeventreminder as ber # Graphics def draw(mode, goingToSleep=False): while 1: ugfx.clear(ugfx.WHITE) time.sleep(1) ugfx.clear(ugfx.BLACK) time.sleep(1) # About def splash_about_countdown_reset(): global splashAboutCountdown splashAboutCountdown = badge.nvs_get_u8('splash', 'about.amount', 10) 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)+"...") # Button input def splash_input_start(pressed): # Pressing start always starts the launcher if pressed: appglue.start_app("launcher", False) def splash_input_a(pressed): if pressed: splash_about_countdown_trigger() pm.feed() def splash_input_select(pressed): if pressed: if otac.available(False): appglue.start_ota() pm.feed() def splash_input_other(pressed): if pressed: pm.feed() def splash_input_init(): print("[SPLASH] Inputs attached") # Power management def onSleep(idleTime): draw(False, True) services.force_draw(True) draw(True, True) ### PROGRAM # Calibrate battery voltage drop if badge.battery_charge_status() == False and badge.usb_volt_sense() > 4500 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() splash_about_countdown_reset() # 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) # RTC === if time.time() < 1482192000: easyrtc.configure() # ======= if not easywifi.failure(): resc.check() # Check resources if not easywifi.failure(): spoc.show(False) # Check sponsors services.setup(draw) # Start services draw(False) services.force_draw() draw(True) easywifi.disable() gc.collect() virtualtimers.debug(True) virtualtimers.activate(25) pm.callback(onSleep) pm.feed() ber.enable() print("----") print("WARNING: POWER MANAGEMENT ACTIVE") print("To use shell type 'import shell' within 5 seconds.") print("----")