From 799a66c9b95a1f95eba8b3412c45b6290ec68a73 Mon Sep 17 00:00:00 2001 From: Daniel Thompson Date: Sun, 8 Mar 2020 17:37:43 +0000 Subject: wasp: Move the apps into their own directory. diff --git a/docs/wasp.rst b/docs/wasp.rst index 4c0c0ff..bd6e8a3 100644 --- a/docs/wasp.rst +++ b/docs/wasp.rst @@ -11,7 +11,7 @@ System management Applications ------------ -.. automodule:: clock +.. automodule:: apps.clock :members: :undoc-members: 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) diff --git a/wasp/boards/pinetime/manifest.py b/wasp/boards/pinetime/manifest.py index b3e2e17..6a19c1a 100644 --- a/wasp/boards/pinetime/manifest.py +++ b/wasp/boards/pinetime/manifest.py @@ -1,8 +1,10 @@ freeze('.', 'watch.py', opt=3) freeze('../..', ( + 'apps/clock.py', + 'apps/testapp.py', + 'apps/flashlight.py', 'boot.py', - 'clock.py', 'demo.py', 'draw565.py', 'drivers/battery.py', @@ -11,14 +13,12 @@ freeze('../..', 'drivers/signal.py', 'drivers/st7789.py', 'drivers/vibrator.py', - 'flashlight.py', 'fonts/clock.py', 'fonts/sans24.py', 'icons.py', 'logo.py', 'manager.py', 'shell.py', - 'testapp.py', 'widgets.py', ), opt=3 diff --git a/wasp/clock.py b/wasp/clock.py deleted file mode 100644 index 5de6271..0000000 --- a/wasp/clock.py +++ /dev/null @@ -1,96 +0,0 @@ -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/flashlight.py b/wasp/flashlight.py deleted file mode 100644 index d71342b..0000000 --- a/wasp/flashlight.py +++ /dev/null @@ -1,34 +0,0 @@ -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/manager.py b/wasp/manager.py index 6e45518..b9fa084 100644 --- a/wasp/manager.py +++ b/wasp/manager.py @@ -1,9 +1,10 @@ -import clock -import flashlight -import testapp import gc import machine +from apps.clock import ClockApp +from apps.flashlight import FlashlightApp +from apps.testapp import TouchTestApp + DOWN = 1 UP = 2 LEFT = 3 @@ -19,9 +20,9 @@ class Manager(object): self.app = None self.applications = [ - clock.ClockApp(), - flashlight.FlashlightApp(), - testapp.TouchTestApp() + ClockApp(), + FlashlightApp(), + TouchTestApp() ] self.watch.display.poweron() diff --git a/wasp/testapp.py b/wasp/testapp.py deleted file mode 100644 index 2cf3431..0000000 --- a/wasp/testapp.py +++ /dev/null @@ -1,35 +0,0 @@ -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) -- cgit v0.10.2