diff options
| author | Daniel Thompson <daniel@redfelineninja.org.uk> | 2020-02-03 19:24:09 (GMT) |
|---|---|---|
| committer | Daniel Thompson <daniel@redfelineninja.org.uk> | 2020-02-03 19:26:08 (GMT) |
| commit | 3892f07e62fcbbac128401f183bec66361f08db1 (patch) | |
| tree | 877ebbb5d856c8a3539417872f148932fedae75d /wasp | |
| parent | fc74f7e37b3db9024d6cecf9fabdddf602b88b3c (diff) | |
wasp: Add simple clock app
At this point both the simulator and a PineTime will come up
and show a clock (although in the case of the PineTime the clock
will just come up at 12:00).
Diffstat (limited to 'wasp')
| -rw-r--r-- | wasp/boards/pinetime/manifest.py | 4 | ||||
| -rw-r--r-- | wasp/boot.py | 11 | ||||
| -rw-r--r-- | wasp/clock.py | 43 | ||||
| -rw-r--r-- | wasp/main.py | 5 | ||||
| -rw-r--r-- | wasp/manager.py | 42 |
5 files changed, 92 insertions, 13 deletions
diff --git a/wasp/boards/pinetime/manifest.py b/wasp/boards/pinetime/manifest.py index ea772ac..58cd241 100644 --- a/wasp/boards/pinetime/manifest.py +++ b/wasp/boards/pinetime/manifest.py @@ -1,12 +1,16 @@ freeze('../..', ( 'boot.py', + 'clock.py', 'demo.py', 'drivers/battery.py', 'drivers/nrf_rtc.py', 'drivers/signal.py', 'drivers/st7789.py', 'drivers/vibrator.py', + 'fonts.py', + 'main.py', + 'manager.py', 'logo.py', ), opt=3 diff --git a/wasp/boot.py b/wasp/boot.py index 49ff56b..baed941 100644 --- a/wasp/boot.py +++ b/wasp/boot.py @@ -1,10 +1,3 @@ -import logo +import manager import watch -import time - -# Splash screen -watch.display.rleblit(logo.pine64, fg=0xffff) - -time.sleep(5) -watch.backlight.set(0) -watch.display.poweroff() +wasp = manager.Manager(watch) diff --git a/wasp/clock.py b/wasp/clock.py new file mode 100644 index 0000000..95ea7da --- /dev/null +++ b/wasp/clock.py @@ -0,0 +1,43 @@ +import fonts + +DIGITS = ( + fonts.clock_0, + fonts.clock_1, + fonts.clock_2, + fonts.clock_3, + fonts.clock_4, + fonts.clock_5, + fonts.clock_6, + fonts.clock_7, + fonts.clock_8, + fonts.clock_9 +) + +class ClockApp(object): + + def __init__(self): + self.on_screen = ( -1, -1 ) + + def draw(self, watch): + display = watch.display + + display.fill(0) + display.rleblit(fonts.clock_colon, pos=(2*48, 80), fg=0xb5b6) + self.update(watch) + + def update(self, watch): + now = watch.rtc.get_time() + if now[0] == self.on_screen[0] and now[1] == self.on_screen[1]: + # Avoid the redraw + return False + + display = watch.display + display.rleblit(DIGITS[now[1] % 10], pos=(4*48, 80)) + display.rleblit(DIGITS[now[1] // 10], pos=(3*48, 80), fg=0xc638) + display.rleblit(DIGITS[now[0] % 10], pos=(1*48, 80)) + display.rleblit(DIGITS[now[0] // 10], pos=(0*48, 80), fg=0xc638) + self.on_screen = now + + return True + + diff --git a/wasp/main.py b/wasp/main.py index f88de60..6b41efa 100644 --- a/wasp/main.py +++ b/wasp/main.py @@ -1,4 +1 @@ -import machine - -while True - machine.deepsleep() +wasp.run() diff --git a/wasp/manager.py b/wasp/manager.py new file mode 100644 index 0000000..ae6c60d --- /dev/null +++ b/wasp/manager.py @@ -0,0 +1,42 @@ +import clock +import gc +import machine + +class Manager(object): + def __init__(self, watch): + self.watch = watch + self.switch(clock.ClockApp()) + self.sleep_at = watch.rtc.uptime + 90 + + def switch(self, app): + self.app = app + app.draw(self.watch) + + def tick(self): + if self.sleep_at: + if self.watch.rtc.update(): + self.app.update(self.watch) + + if self.watch.button.value(): + self.sleep_at = self.watch.rtc.uptime + 15 + + if self.watch.rtc.uptime > self.sleep_at: + self.watch.backlight.set(0) + self.watch.display.poweroff() + self.sleep_at = None + else: + self.watch.rtc.update() + + if self.watch.button.value(): + self.watch.display.poweron() + self.app.update(self.watch) + self.watch.backlight.set(2) + + self.sleep_at = self.watch.rtc.uptime + 15 + + gc.collect() + + def run(self): + while True: + self.tick() + machine.deepsleep() |
