Toggle Navigation
Hatchery
Eggs
Just My Test App
testapp1.py
Users
Badges
Login
Register
testapp1.py
raw
Content
import badge, ugfx, appglue, time, woezel, deepsleep, network, wifi badge.init() ugfx.init() ugfx.input_init() badge.leds_init() badge.leds_enable() brightness = badge.nvs_get_u8('justmytestapp', 'brightness', 5) def draw_screen(): global brightness ugfx.clear(ugfx.BLACK) ugfx.clear(ugfx.WHITE) ugfx.clear(ugfx.BLACK) #ugfx.thickline(1, 1, 100, 100, ugfx.WHITE, 10, 5) #ugfx.box(30, 30, 50, 50, ugfx.WHITE) ugfx.string(150, 25, "FERDI's", "Roboto_BlackItalic24", ugfx.WHITE) ugfx.string(140, 50, "Hacking", "PermanentMarker22", ugfx.WHITE) ugfx.string(170, 75, "App ({})".format(brightness), "Roboto_BlackItalic24", ugfx.WHITE) #len = ugfx.get_string_width("App", "Roboto_BlackItalic24") try: badge.eink_png(32,32,'/lib/just_my_test_app/icon-bw.png') except: pass ugfx.flush() badge.eink_busy_wait() def nightrider(): global brightness for i in range(6): #badge.leds_send_data(b''.join([ b'\0\0\0\0' ] * i + [ binary('\0\5\0\0' ] + [ b'\0\0\0\0' ] * (5-i)), 24) badge.leds_send_data(bytes([0,0,0,0] * i + [0,brightness,0,0] + [ 0,0,0,0 ] * (5-i)), 24) time.sleep(.2) for i in range(5,-1,-1): #badge.leds_send_data(b''.join([ b'\0\0\0\0' ] * i + [ b'\0\5\0\0' ] + [ b'\0\0\0\0' ] * (5-i)), 24) badge.leds_send_data(bytes([0,0,0,0] * i + [0,brightness,0,0] + [ 0,0,0,0 ] * (5-i)), 24) time.sleep(.2) def home(pressed): if pressed: badge.vibrator_init() badge.vibrator_activate(1) appglue.home() def adjust_brightness_slow(pressed): if pressed: adjust_brightness(1) def adjust_brightness_fast(pressed): if pressed: adjust_brightness(25) def adjust_brightness(step): global brightness brightness += step if brightness > 255: brightness = 0 badge.nvs_set_u8('justmytestapp', 'enabled', 0) else: badge.nvs_set_u8('justmytestapp', 'enabled', 1) badge.nvs_set_u8('justmytestapp', 'brightness', brightness) draw_screen() def update_app(pressed): if not pressed: return 0 wifi.init() time.sleep(5) if wifi.sta_if.isconnected(): print('[JustMyTestApp] Start update'); woezel.install('just_my_test_app') appglue.start_app('just_my_test_app') else: print('[JustMyTestApp] No Wifi No Update'); ugfx.input_attach(ugfx.BTN_A, adjust_brightness_fast) ugfx.input_attach(ugfx.BTN_B, adjust_brightness_slow) ugfx.input_attach(ugfx.BTN_START, home) ugfx.input_attach(ugfx.BTN_SELECT, update_app) draw_screen() while True: nightrider()