def pm_task(): ''' The power management task [internal function] ''' global requestedStandbyTime idleTime = virtualtimers.idle_time() #print("[Power management] Next task wants to run in "+str(idleTime)+" ms.") if idleTime > 30000 and not badge.safe_mode() and not ( usb_attached() and badge.nvs_get_u8('badge', 'usb_stay_awake', 0) != 0): global onSleepCallback if not onSleepCallback == None: print("[Power management] Running onSleepCallback...") try: onSleepCallback(idleTime) except BaseException as e: print("[ERROR] An error occured in the on sleep callback.") sys.print_exception(e) if idleTime >= 86400000: # One day print("[Power management] Sleeping forever...") deepsleep.start_sleeping() else: print("[Power management] Sleeping for " + str(idleTime) + " ms...") deepsleep.start_sleeping(idleTime) global userResponseTime return userResponseTime
def pm_task(): ''' The power management task [internal function] ''' global requestedStandbyTime global timeout global disabled if disabled: return timeout idleTime = virtualtimers.idle_time() if idleTime > 30000 and not badge.safe_mode() and not ( usb_attached() and badge.nvs_get_u8('badge', 'usb_stay_awake', 0) != 0): global onSleepCallback if not onSleepCallback == None: print("[Power management] Running onSleepCallback...") try: onSleepCallback(idleTime) except BaseException as e: print("[ERROR] An error occured in the on sleep callback.") sys.print_exception(e) deepsleep.start_sleeping(idleTime) return timeout
def start(): if badge.safe_mode(): splash = 'splash' else: splash = badge.nvs_get_str('boot', 'splash', 'splash') 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)
def draw(mode, goingToSleep=False): ugfx.orientation(0) if mode: # We flush the buffer and wait ugfx.flush(ugfx.LUT_FULL) badge.eink_busy_wait() else: # We prepare the screen refresh ugfx.clear(ugfx.WHITE) if goingToSleep: info1 = 'Sleeping...' info2 = 'Press any key to wake up' else: info1 = 'Press start to open the launcher' if otac.available(False): info2 = 'Press select to start OTA update' else: info2 = '' def disp_string_right(y, s): l = ugfx.get_string_width(s, "Roboto_Regular12") ugfx.string(296 - l, y, s, "Roboto_Regular12", ugfx.BLACK) disp_string_right(0, info1) disp_string_right(12, info2) if badge.safe_mode(): disp_string_right(92, "Safe Mode - services disabled") disp_string_right(104, "Sleep disabled - will drain battery quickly") disp_string_right(116, "Press Reset button to exit") nickname() on_usb = pm.usb_attached() vBatt = badge.battery_volt_sense() vBatt += vDrop charging = badge.battery_charge_status() battery(on_usb, vBatt, charging) if vBatt > 500: ugfx.string(52, 0, str(round(vBatt / 1000, 1)) + 'v', 'Roboto_Regular12', ugfx.BLACK)
def draw(mode, goingToSleep=False): info1 = '' info2 = '' if mode: # We flush the buffer and wait ugfx.flush(ugfx.GREYSCALE) else: # We prepare the screen refresh ugfx.clear(ugfx.WHITE) easydraw.nickname() if goingToSleep: info = 'Sleeping...' elif badge.safe_mode(): info = "(Services disabled!)" elif otac.available(False): info = 'Update available!' else: info = '' easydraw.disp_string_right_bottom(0, info)
# This file is executed on every boot (including wake-boot from deepsleep) import badge, machine, esp, ugfx, sys, time badge.init() ugfx.init() ugfx.input_init() esp.rtcmem_write(0, 0) esp.rtcmem_write(1, 0) # setup timezone timezone = badge.nvs_get_str('system', 'timezone', 'CET-1CEST-2,M3.5.0/02:00:00,M10.5.0/03:00:00') time.settimezone(timezone) if badge.safe_mode(): splash = 'splash' else: splash = badge.nvs_get_str('boot', 'splash', 'splash') if machine.reset_cause() != machine.DEEPSLEEP_RESET: print('[BOOT] Cold boot') else: print("[BOOT] Wake from sleep") load_me = esp.rtcmem_read_string() if load_me: splash = load_me print("starting %s" % load_me) esp.rtcmem_write_string("") try: if not splash == "shell":
# 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() # ======= print('[BOOT] Choosing boot mode') if badge.safe_mode(): print('[BOOT] Safe mode') # draw(False) # services.force_draw() # draw(True) else: print('[BOOT] Normal boot mode') print('[BOOT] Finding services') have_services = services.setup() # Start services if not have_services: print('[BOOT] No services found') # draw(False) # services.force_draw() # draw(True) print('[BOOT] Disabling WiFi and running garbage collection')
install_path = None ugfx.input_attach(ugfx.BTN_A, input_a) ugfx.input_attach(ugfx.BTN_B, input_b) ugfx.input_attach(ugfx.BTN_SELECT, input_select) ugfx.input_attach(ugfx.JOY_UP, input_other) ugfx.input_attach(ugfx.JOY_DOWN, input_other) ugfx.input_attach(ugfx.JOY_LEFT, input_other) ugfx.input_attach(ugfx.JOY_RIGHT, input_other) ugfx.input_attach(ugfx.BTN_START, input_other) populate_apps() populate_category() populate_options() # do a greyscale flush on start ugfx.flush(ugfx.GREYSCALE) start() init_power_management() def goToSleep(unused_variable=None): system.home() import term_menu umenu = term_menu.UartMenu(goToSleep, pm, badge.safe_mode(), "< Back") umenu.main()
cfg_shell = badge.nvs_get_u8('splash', 'shell', False) 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()
virtualtimers.new(0, drawTask, True) # Free up space in RAM gc.collect() # Set the RTC if needed and WiFi is allowed if not rtc.isSet() and cfg_wifi: wifi.connect( ) #Connecting to WiFi automatically sets the time using NTP (see wifiTask) # LED animation if cfg_led_animation != None: badge.leds_init() badge.leds_enable() try: led_app = __import__('/lib/' + cfg_led_animation + '/ledsrv') try: led_app.init() except: pass virtualtimers.new(0, led_app.step) except: pass # Terminal menu if cfg_term_menu: umenu = term_menu.UartMenu(onSleep, pm, badge.safe_mode()) umenu.main()
draw(False, True) services.force_draw(True) draw(True, True) ### PROGRAM # Calibrate battery voltage drop 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() splash_about_countdown_reset() if not badge.safe_mode(): services.setup(draw) # Start services draw(False) services.force_draw() draw(True) gc.collect() virtualtimers.activate(25) pm.callback(onSleep) pm.feed()
def start(): ugfx.input_init() ugfx.set_lut(ugfx.LUT_FASTER) ugfx.clear(ugfx.WHITE) if badge.safe_mode(): still = "SAFE" anyway = "Mode" else: still = "STILL" anyway = "Anyway" ugfx.string_box(148, 0, 148, 26, still, "Roboto_BlackItalic24", ugfx.BLACK, ugfx.justifyCenter) ugfx.string_box(148, 23, 148, 23, "Hacking", "PermanentMarker22", ugfx.BLACK, ugfx.justifyCenter) ugfx.string_box(148, 48, 148, 26, anyway, "Roboto_BlackItalic24", ugfx.BLACK, ugfx.justifyCenter) #the line under the text str_len = ugfx.get_string_width("Hacking", "PermanentMarker22") line_begin = 148 + int((148 - str_len) / 2) line_end = str_len + line_begin ugfx.line(line_begin, 46, line_end, 46, ugfx.BLACK) #the cursor past the text cursor_pos = line_end + 5 ugfx.line(cursor_pos, 22, cursor_pos, 44, ugfx.BLACK) # Instructions ugfx.line(148, 78, 296, 78, ugfx.BLACK) ugfx.string_box(148, 78, 148, 18, " A: Run", "Roboto_Regular12", ugfx.BLACK, ugfx.justifyLeft) ugfx.string_box(148, 78, 148, 18, " B: Return to home", "Roboto_Regular12", ugfx.BLACK, ugfx.justifyRight) ugfx.string_box(148, 92, 148, 18, " SELECT: Uninstall", "Roboto_Regular12", ugfx.BLACK, ugfx.justifyLeft) ugfx.line(148, 110, 296, 110, ugfx.BLACK) ugfx.string_box(148, 110, 148, 18, " " + version.name, "Roboto_Regular12", ugfx.BLACK, ugfx.justifyLeft) global options global install_path options = None install_path = None ugfx.input_attach(ugfx.BTN_A, input_a) ugfx.input_attach(ugfx.BTN_B, input_b) ugfx.input_attach(ugfx.BTN_SELECT, input_select) ugfx.input_attach(ugfx.JOY_UP, input_other) ugfx.input_attach(ugfx.JOY_DOWN, input_other) ugfx.input_attach(ugfx.JOY_LEFT, input_other) ugfx.input_attach(ugfx.JOY_RIGHT, input_other) ugfx.input_attach(ugfx.BTN_START, input_other) populate_apps() populate_category() populate_options() # do a greyscale flush on start ugfx.flush(ugfx.GREYSCALE)