def install(): easydraw.msg("Installing resources...") if not easywifi.status(): if not easywifi.enable(): return False import woezel woezel.install("resources") appglue.home()
def install(): if not easywifi.status(): if not easywifi.enable(): return False print("[SPONSORS] Installing...") easydraw.msg("Installing sponsors...") import woezel woezel.install("sponsors") easydraw.msg("OK")
def configure(): import easywifi import easydraw import ntp if not easywifi.status(): if not easywifi.enable(): return False easydraw.msg("Configuring clock...") ntp.set_NTP_time() easydraw.msg("Done") return True
def available(update=False): if update: if not easywifi.status(): if not easywifi.enable(): return badge.nvs_get_u8('badge', 'OTA.ready', 0) info = download_info() 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)
import ugfx, woezel, easywifi, easydraw, appglue, time, os def stop(): time.sleep(2) appglue.start_app("launcher") easydraw.msg("Welcome!", "Updating...", True) if not easywifi.status(): if not easywifi.enable(): stop() try: apps = os.listdir('lib') except OSError: easydraw.msg("There are no apps installed.") stop() for app in apps: easydraw.msg("Updating '" + app + "'...") try: woezel.install(app) easydraw.msg("Done!") except: print("failed update. Already newest version?") easydraw.msg("All your apps are now up-to-date!") stop()
def setup(drawCb=None): global services global drawCallbacks if drawCb: print("[SERVICES] Draw callback registered") global drawCallback drawCallback = drawCb #This might need a better name... # Status of wifi wifiFailed = False #Check if lib folder exists and get application list, else stop try: apps = uos.listdir('lib') except OSError: return [False, False] #For each app... for app in apps: print("APP: " + app) try: #Try to open and read the json description fd = open('/lib/' + app + '/service.json') description = ujson.loads(fd.read()) fd.close() except: print("[SERVICES] No description found for " + app) continue #Or skip the app try: #Try to open the service itself fd = open('/lib/' + app + '/service.py') fd.close() except: print("[SERVICES] No script found for " + app) continue #Or skip the app rtcRequired = False # True if RTC should be set before starting service loopEnabled = False # True if loop callback is requested drawEnabled = False # True if draw callback is requested wifiInSetup = False # True if wifi needed in setup wifiInLoop = False # True if wifi needed in loop try: if description['apiVersion'] != 2: print("[SERVICES] Service for " + app + " is not compatible with current firmware") continue #Skip the app wifiInSetup = description['wifi']['setup'] wifiInLoop = description['wifi']['setup'] rtcRequired = description['rtc'] loopEnabled = description['loop'] drawEnabled = description['draw'] except: print("[SERVICES] Could not parse description of app " + app) continue #Skip the app print("[SERVICES] Found service for " + app) # Import the service.py script try: srv = __import__('lib/' + app + '/service') except BaseException as e: print("[SERVICES] Could not import service of app " + app + ": ") sys.print_exception(e) continue #Skip the app if wifiInSetup or wifiInLoop: if wifiFailed: print( "[SERVICES] Service of app " + app + " requires wifi and wifi failed so the service has been disabled." ) continue if not easywifi.status(): if not easywifi.enable(): wifiFailed = True print("[SERVICES] Could not connect to wifi!") continue # Skip the app if rtcRequired and time.time() < 1482192000: if not wifiFailed: print("[SERVICES] RTC required, configuring...") easyrtc.configure() else: print( "[SERVICES] RTC required but not available. Skipping service." ) continue # Skip the app (because wifi failed and rtc not available) try: srv.setup() except BaseException as e: print("[SERVICES] Exception in service setup " + app + ":") sys.print_exception(e) continue if loopEnabled: try: virtualtimers.new(1, srv.loop) except: print("[SERVICES] Loop requested but not defined in service " + app) if drawEnabled and drawCb: drawCallbacks.append(srv) # Add the script to the global service list services.append(srv) handleDraw = False if len(drawCallbacks) > 0 and drawCb: print("[SERVICES] The service subsystem now handles screen redraws") handleDraw = True virtualtimers.new(1, draw_task, True) return handleDraw