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 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_text_input_sequence(startx, chars, colour, reverse=False): length = len(chars) step = FONT_WIDTH + 1 curx = startx if reverse: for i in range(length - 1, -1, -1): rgb.text(chars[i], colour, (curx, 0)) curx -= step else: for i in range(length): rgb.text(chars[i], colour, (curx, 0)) curx += step
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)
tick = 0 try: connect_wifi() print('retrieving result') result = urequests.get(WEATHER_API_SERVER) disconnect_wifi() if result.status_code == 200: rgb.pixel((0, 255, 0), (31, 7)) # green for new data try: print(gc.mem_free()) weather = result.json() except: print('Error during json parse') print(result.text()) rgb.pixel((255, 0, 0), (31, 7)) # red for error else: print('Status: ' + result.status_code) rgb.pixel((255, 0, 0), (31, 7)) # red for error rgb.text('E {}'.format(result.status_code)) except Exception as e: text = str(e) print(text) wifi.disconnect() rgb.pixel((255, 0, 0), (31, 0)) # red for error rgb.setfont(1) rgb.text('No wifi') sleep(10) rgb.text(str(int(weather["main"]["temp"])), (255, 255, 255), (11, 1))
if timezone is None: timezone = 'CET-1CEST-2,M3.5.0/02:00:00,M10.5.0/03:00:00' machine.RTC().timezone(timezone) def input_B(pressed): global direction direction = defines.BTN_B buttons.register(defines.BTN_B, input_B) gifd = [0, 0x00FFFFFF, 0, 0, 0, 0x00FFFFFF, 0, 0, 0, 0, 0, 0, 0, 0] tmold = 70 rgb.background((0, 0, 0)) rgb.clear() rgb.framerate(1) while direction != defines.BTN_B: th = '%02d' % rtc.now()[3] tm = '%02d' % rtc.now()[4] if tm != tmold: rgb.clear() rgb.text(th, (255, 255, 255), (3, 0)) rgb.text(tm, (255, 255, 255), (18, 0)) rgb.gif(gifd, (15, 0), (1, 7), 2) rgb.gif(gifd, (16, 0), (1, 7), 2) tmold = tm time.sleep(0.2) system.reboot()
counter = 0 daysindex = 0 for day in days: if day['doy'] == today: daysindex = counter counter += 1 eventtype = ['Compo', 'Activity'] while True: menu = [] rgb.clear() # if not daysindex in days or 'date' not in days[daysindex]: # system.start('activities') rgb.text(days[daysindex]['date'], (0, 255, 255), (6, 1)) rgb.setfont(rgb.FONT_6x3) utime.sleep(0.5) for event in days[daysindex]['events']: time_utc = int(event['time']) time_local = time_utc + 60 * 60 * 2 hour = str(utime.localtime(time_local)[3]) minute = str(utime.localtime(time_local)[4]) if len(minute) != 2: minute = '0' + minute menu.append(hour + ':' + minute + ' ' + event['name']) eventindex = uinterface.menu(menu, 0, call_left, call_right) print(eventindex) if eventindex != None: event = days[daysindex]['events'][eventindex]
def draw_error(e): rgb.clear() rgb.pixel((255, 0, 0), (REFRESH_RATE, 7)) # red for error rgb.text('E {}'.format(e))
def input_B(pressed): if pressed: rgb.clear() rgb.text("Bye!") sleep(0.5) system.reboot()
buttons.register(UP, input_up) buttons.register(DOWN, input_down) buttons.register(LEFT, input_left) buttons.register(RIGHT, input_right) buttons.register(B, input_B) buttons.register(A, input_A) rgb.setfont(rgb.FONT_6x3) rgb.framerate(10) # second updates REFRESH_RATE = 31 # times framerate updates. # wifi connect if not wifi.status(): if not uinterface.connect_wifi(): system.reboot() rgb.text('Hi!') # main loop count = REFRESH_RATE - 1 # start fast while True: if not wifi.status(): if not uinterface.connect_wifi(): system.reboot() if count < REFRESH_RATE and stat == old_stat: gc.collect() sleep(0.1) rgb.pixel((150, 150, 0), (count, 7)) # refresh counter count += 1 continue else: