diff options
| author | Daniel Thompson <daniel@redfelineninja.org.uk> | 2020-03-08 17:37:43 (GMT) |
|---|---|---|
| committer | Daniel Thompson <daniel@redfelineninja.org.uk> | 2020-03-08 17:39:39 (GMT) |
| commit | 799a66c9b95a1f95eba8b3412c45b6290ec68a73 (patch) | |
| tree | fb731f2a97acda16c95887a1a1ae52f392abfb48 /wasp/apps | |
| parent | b5b96bd7760f76d9bb476eb835f49b3c9586ca5c (diff) | |
wasp: Move the apps into their own directory.
Diffstat (limited to 'wasp/apps')
| -rw-r--r-- | wasp/apps/clock.py | 96 | ||||
| -rw-r--r-- | wasp/apps/flashlight.py | 34 | ||||
| -rw-r--r-- | wasp/apps/testapp.py | 35 |
3 files changed, 165 insertions, 0 deletions
diff --git a/wasp/apps/clock.py b/wasp/apps/clock.py new file mode 100644 index 0000000..5de6271 --- /dev/null +++ b/wasp/apps/clock.py @@ -0,0 +1,96 @@ +import fonts.clock as digits +import watch +import widgets +import manager + +from draw565 import Draw565 + +DIGITS = ( + digits.clock_0, + digits.clock_1, + digits.clock_2, + digits.clock_3, + digits.clock_4, + digits.clock_5, + digits.clock_6, + digits.clock_7, + digits.clock_8, + digits.clock_9 +) + +MONTH = 'JanFebMarAprMayJunJulAugSepOctNovDec' + +class ClockApp(object): + """Simple digital clock application. + + Shows a time (as HH:MM) together with a battery meter and the date. + """ + + def __init__(self): + self.meter = widgets.BatteryMeter() + + def handle_event(self, event_view): + """Process events that the app is subscribed to.""" + if event_view[0] == manager.EVENT_TICK: + self.update() + else: + # TODO: Raise an unexpected event exception + pass + + def foreground(self, manager, effect=None): + """Activate the application.""" + self.on_screen = ( -1, -1, -1, -1, -1, -1 ) + self.draw(effect) + manager.request_tick(1000) + + def tick(self, ticks): + self.update() + + def background(self): + """De-activate the application (without losing state).""" + pass + + def sleep(self): + return True + + def wake(self): + self.update() + + def draw(self, effect=None): + """Redraw the display from scratch.""" + display = watch.display + + display.fill(0) + display.rleblit(digits.clock_colon, pos=(2*48, 80), fg=0xb5b6) + self.on_screen = ( -1, -1, -1, -1, -1, -1 ) + self.update() + self.meter.draw() + + def update(self): + """Update the display (if needed). + + The updates are a lazy as possible and rely on an prior call to + draw() to ensure the screen is suitably prepared. + """ + now = watch.rtc.get_localtime() + if now[3] == self.on_screen[3] and now[4] == self.on_screen[4]: + if now[5] != self.on_screen[5]: + self.meter.update() + self.on_screen = now + return False + + display = watch.display + display.rleblit(DIGITS[now[4] % 10], pos=(4*48, 80)) + display.rleblit(DIGITS[now[4] // 10], pos=(3*48, 80), fg=0xbdb6) + display.rleblit(DIGITS[now[3] % 10], pos=(1*48, 80)) + display.rleblit(DIGITS[now[3] // 10], pos=(0*48, 80), fg=0xbdb6) + self.on_screen = now + + draw = Draw565(display) + month = now[1] - 1 + month = MONTH[month*3:(month+1)*3] + draw.string('{} {} {}'.format(now[2], month, now[0]), + 0, 180, width=240) + + self.meter.update() + return True diff --git a/wasp/apps/flashlight.py b/wasp/apps/flashlight.py new file mode 100644 index 0000000..d71342b --- /dev/null +++ b/wasp/apps/flashlight.py @@ -0,0 +1,34 @@ +import watch +import manager + +from draw565 import Draw565 + +class FlashlightApp(object): + """Trivial flashlight application. + + Shows a pure white screen with the backlight set to maximum. + """ + + def __init__(self): + self.backlight = None + + def foreground(self, manager, effect=None): + """Activate the application.""" + self.on_screen = ( -1, -1, -1, -1, -1, -1 ) + self.draw(effect) + manager.request_tick(1000) + + def background(self): + """De-activate the application (without losing state).""" + pass + + def sleep(self): + return False + + def tick(self, ticks): + pass + + def draw(self, effect=None): + """Redraw the display from scratch.""" + display = watch.display + display.fill(0xffff) diff --git a/wasp/apps/testapp.py b/wasp/apps/testapp.py new file mode 100644 index 0000000..2cf3431 --- /dev/null +++ b/wasp/apps/testapp.py @@ -0,0 +1,35 @@ +import watch +import widgets +import manager + +from draw565 import Draw565 + +class TouchTestApp(object): + """Simple application to visualize touch events. + """ + + def __init__(self): + pass + + def foreground(self, system, effect=None): + """Activate the application.""" + self.on_screen = ( -1, -1, -1, -1, -1, -1 ) + self.draw(effect) + system.request_event(manager.EVENT_TOUCH) + + def background(self): + """De-activate the application (without losing state).""" + pass + + def sleep(self): + return False + + def touch(self, event): + draw = Draw565(watch.display) + draw.string('({}, {})'.format(event[1], event[2]), + 0, 180, width=240) + return True + + def draw(self, effect=None): + """Redraw the display from scratch.""" + watch.display.fill(0) |
