def woezel_callback(text, error): global category_stats rgb.clear() rgb.framerate(20) rgb.setfont(rgb.FONT_7x5) print(text) if 'Connecting to WiFi' in text: data, size, frames = animation_connecting_wifi rgb.framerate(3) rgb.gif(data, (12, 0), size, frames) elif 'Failed to connect to WiFi' in text: data, frames = icon_no_wifi rgb.gif(data, (12, 0), (8, 8), frames) time.sleep(3) system.reboot() elif 'Downloading categories...' in text: data, size, frames = animation_loading rgb.gif(data, (1, 1), size, frames) rgb.scrolltext('Loading', pos=(8, 0), width=(rgb.PANEL_WIDTH - 8)) elif 'Installing' in text: data, size, frames = animation_loading rgb.gif(data, (1, 1), size, frames) rgb.scrolltext(text, pos=(8, 0), width=(rgb.PANEL_WIDTH - 8)) elif "Downloading '" in text: cur, total = text.split('(')[1].split(')')[0].split( '/') # Definitely not proud of this progress = '(%s/%s)' % (cur, total) data, size, frames = animation_loading rgb.gif(data, (1, 1), size, frames) rgb.setfont(rgb.FONT_6x3) rgb.text(progress, pos=(8, 1)) elif 'Done!' in text or 'Failed!' in text: pass
def connect_wifi(duration=None): if wifi.status(): return True rgb.clear() data, size, frames = animation_connecting_wifi rgb.framerate(3) rgb.gif(data, (12, 0), size, frames) wifi.connect() if duration is not None: wifi.wait(duration=duration) else: wifi.wait() if not wifi.status(): data, frames = icon_no_wifi rgb.gif(data, (12, 0), (8, 8), frames) time.sleep(3) rgb.clear() rgb.framerate(20) del data, size, frames gc.collect() return wifi.status()
def do_game_over(self): if self.mode == "multiplayer": # print("Send gameover") self.multiplayer_send_gameover() rgb.enablecomp() rgb.clear() rgb.scrolltext("game over")
def set_nickname(): rgb.clear() uinterface.skippabletext('Set nickname:') new_name = uinterface.text_input() if new_name is not None and new_name != '': machine.nvs_setstr('badge', 'nickname', new_name) system.start('nickname')
def host_on_disconnect(addr): global connected connected = False print("(host) disconnected:" + addr) if badgehelper.on_badge(): rgb.clear() rgb.scrolltext("(host) client disconnected: " + addr, (255, 255, 255))
def host_on_row(): global received_rows print("(host) row added") received_rows += received_rows if badgehelper.on_badge(): rgb.clear() rgb.scrolltext("(host) received row " + str(received_rows), (255, 255, 255))
def render(): rgb.clear() rgb.background((0, 0, 0)) for x, y in snake: rgb.pixel((255, 255, 255), (x, y)) rgb.pixel((0, 255, 200), food)
def draw_text(): global l, color rgb.clear() if l: rgb.pixel((0, 150, 0), (REFRESH_RATE, 7)) # green for new data for i, d in enumerate(l): rgb.text(d, colors[color][i], (ceil(31 / len(l)) * i, 0)) else: rgb.text('E Data')
def draw_ghost(self): rgb.clear() if self.current_direction == self.LEFT: rgb.image(self.PINK_GHOST_8x8_LEFT, (self.current_x, self.START_Y), (self.PAC_WIDTH, self.PAC_HEIGHT)) else: rgb.image(self.PINK_GHOST_8x8_RIGHT, (self.current_x, self.START_Y), (self.PAC_WIDTH, self.PAC_HEIGHT))
def vcc_low(sleepTime=0): term.header(True, "Going to sleep...") rgb.enablecomp() rgb.background((0, 0, 0)) rgb.clear() rgb.scrolltext('BATT LOW!') time.sleep(4) time.sleep(0.1) machine.deepsleep(sleepTime)
def animate_wifi(): if not badgehelper.on_badge(): return False from default_icons import animation_connecting_wifi rgb.clear() data, size, frames = animation_connecting_wifi rgb.framerate(3) rgb.gif(data, (12, 0), size, frames)
def vcc_low(sleepTime=0): import term, rgb, machine term.header(True, "Going to sleep...") rgb.enablecomp() rgb.background((0, 0, 0)) rgb.clear() uinterface.skippabletext('BATT LOW!') time.sleep(0.1) machine.deepsleep(sleepTime)
def scan_access_point_list(): data, size, frames = animation_connecting_wifi rgb.clear() rgb.framerate(3) rgb.gif(data, (12, 0), size, frames) sta_if = network.WLAN(network.STA_IF) sta_if.active(True) sta_if.disconnect() ap_result = sta_if.scan() return [(ap[0].decode("utf-8", "ignore"), ap[5]) for ap in ap_result]
def uninstall(app): if app["category"] == "system": # dialogs.notice("System apps can not be removed!","Can not uninstall '"+currentListTitles[selected]+"'") rgb.clear() uinterface.skippabletext("System apps can't be removed") render_current_app() return machine.nvs_setstr('launcher', 'uninstall_name', app['title']) machine.nvs_setstr('launcher', 'uninstall_file', app['file']) system.start('uninstall')
def animate_no_wifi(): if not badgehelper.on_badge(): return False from default_icons import icon_no_wifi rgb.clear() data, frames = icon_no_wifi rgb.framerate(3) rgb.gif(data, (12, 0), (8, 8), frames) time.sleep(3)
def main(): try: _initialize_display() latest_update = _retrieve_latest_update() if _prompt_user_for_update(latest_update["name"], latest_update["build"]): uinterface.skippabletext("Starting update") system.ota() else: uinterface.skippabletext("Cancelled OTA update") except Exception as e: rgb.clear() uinterface.skippabletext(str(e))
def uninstall(app): global nvs if app["category"] == "system": # dialogs.notice("System apps can not be removed!","Can not uninstall '"+currentListTitles[selected]+"'") rgb.clear() uinterface.skippabletext("System apps can't be removed") render_current_app() return nvs.set_blob('uninstall_name', app['title']) nvs.set_blob('uninstall_file', app['file']) nvs.commit() system.start('uninstall')
def _draw_text_input_state(cursor, text): rgb.clear() before_mid = text[:cursor][-2:] after_mid = text[cursor+1:][:2] mid = text[cursor] step = FONT_WIDTH + 1 midx = int(rgb.PANEL_WIDTH / 2) - int(step / 2) beforex = midx - step afterx = midx + step colour_selected = (150, 50, 10) colour_unselected = (80, 80, 80) _draw_text_input_sequence(beforex, before_mid, colour_unselected, reverse=True) _draw_text_input_sequence(midx, mid, colour_selected) _draw_text_input_sequence(afterx, after_mid, colour_unselected)
def next_check(): if(len(checklist) == 0): rgb.clear() rgb.background((0, 50, 0)) rgb.text("Done!", CYAN, (4, 1)) machine.nvs_setint('system', 'factory_checked', 3) return background, textcolor, x_pos, text, gpio = checklist.pop(0) rgb.clear() rgb.background(background) rgb.text(text, textcolor, (x_pos, 1)) buttons.register(gpio, lambda pressed, gpio=gpio: (buttons.unassign(gpio), next_check()) if not pressed else None)
def connect_wifi(): rgb.pixel((255, 255, 0), (31, 0)) # yellow connecting to wifi if not wifi.status(): wifi.connect() if wifi.wait(): rgb.pixel((0, 255, 0), (31, 0)) # green for wifi rgb.framerate(20) else: rgb.clear() rgb.framerate(20) data, frames = icon_no_wifi rgb.image(data, (12, 0), (8, 8)) time.sleep(3) rgb.clear() machine.reboot()
def start_sleeping(sleepTime=0): term.header(True, "Going to sleep...") rgb.clear() rgb.scrolltext('ZzZz') time.sleep(3) if (sleepTime >= 86400000): # One day sleepTime = 0 if (sleepTime < 1): print("Sleeping until A-button is pressed...") else: print("Sleeping for " + str(sleepTime) + "ms...") time.sleep(0.1) machine.deepsleep(sleepTime)
def connect_wifi(): if wifi.status(): return True rgb.clear() data, size, frames = animation_connecting_wifi rgb.framerate(3) rgb.gif(data, (12, 0), size, frames) wifi.connect() wifi.wait() if not wifi.status(): data, frames = icon_no_wifi rgb.gif(data, (12, 0), (8, 8), frames) time.sleep(3) rgb.clear() rgb.framerate(20) return wifi.status()
def woezel_callback(text, error): global category_stats rgb.clear() rgb.framerate(20) rgb.setfont(rgb.FONT_7x5) print(text) if 'Connecting to WiFi' in text: data, size, frames = animation_connecting_wifi rgb.framerate(3) rgb.gif(data, (12, 0), size, frames) elif 'Failed to connect to WiFi' in text: data, frames = icon_no_wifi rgb.gif(data, (12, 0), (8, 8), frames) time.sleep(3) system.reboot() elif 'Done!' in text or 'Failed!' in text: return else: data, size, frames = animation_loading rgb.gif(data, (1, 1), size, frames) rgb.scrolltext(text, pos=(8, 0), width=(rgb.PANEL_WIDTH - 8))
def show_names(): global names c = False y = 10 term.header(True, "About") print("Developers:") for n in range(0, len(names)): if (names[n] == " "): break print(" - " + names[n]) rgb.clear() rgb.scrolltext("Your badge was made possible by:") time.sleep(10) for n in range(0, len(names)): rgb.clear() uinterface.skippabletext(names[n]) rgb.clear() rgb.scrolltext("Press A or B to quit")
def prompt_message(message): rgb.clear() rgb.framerate(20) rgb.setfont(rgb.FONT_7x5) uinterface.skippabletext(message)
def hijacked_start(app, status=True): import rgb, time rgb.clear() time.sleep(0.1) orig_start(app, status)
def clear(): rgb.clear()
import uinterface, urequests, ujson, ntp, rgb, wifi, buttons, defines, system, machine, gc from default_icons import animation_connecting_wifi, icon_no_wifi from time import sleep rgb.background((0, 0, 0)) rgb.clear() rgb.framerate(20) WEATHER_API_SERVER = 'https://api.openweathermap.org/data/2.5/weather?id=2745726&mode=json&units=metric&appid=100135c6eb0eeba9bde50e165d4021c1' action = 0 weather = None last_update = 0 tick = 0 REFRESH_RATE = 31 rgb.setfont(0) def disconnect_wifi(): if wifi.status(): wifi.disconnect() rgb.pixel((255, 0, 0), (31, 0)) # red for no wifi def connect_wifi(): rgb.pixel((255, 255, 0), (31, 0)) # yellow connecting to wifi if not wifi.status(): wifi.connect()
def hijacked_start(app, status=True): import rgb, time rgb.clear() time.sleep(1 / 20 * 1.1) # 110% of the time of one render frame orig_start(app, status)
def cbSleep(_): rgb.clear() term.header(True, "Going to sleep...") uinterface.skippabletext('ZzZz')