summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Thompson <daniel@redfelineninja.org.uk>2020-02-03 19:24:09 (GMT)
committerDaniel Thompson <daniel@redfelineninja.org.uk>2020-02-03 19:26:08 (GMT)
commit3892f07e62fcbbac128401f183bec66361f08db1 (patch)
tree877ebbb5d856c8a3539417872f148932fedae75d
parentfc74f7e37b3db9024d6cecf9fabdddf602b88b3c (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).
-rw-r--r--TODO.md11
-rw-r--r--wasp/boards/pinetime/manifest.py4
-rw-r--r--wasp/boot.py11
-rw-r--r--wasp/clock.py43
-rw-r--r--wasp/main.py5
-rw-r--r--wasp/manager.py42
6 files changed, 98 insertions, 18 deletions
diff --git a/TODO.md b/TODO.md
index 2142408..6e8b2d7 100644
--- a/TODO.md
+++ b/TODO.md
@@ -17,11 +17,9 @@ to allow a PineTime case to be confidently glued shut.
## MicroPython
* [X] Basic board ports (PineTime, DS-D6, 96Boards Nitrogen)
- * [ ] Long press reset (conditional feeding of the watchdog)
+ * [X] Long press reset (conditional feeding of the watchdog)
- [X] Feed dog from REPL polling loop
- - [ ] Feed dog from a tick interrupt
- * [ ] Basic (WFI) power saving
- * [ ] Implement machine.RTC for nrf52
+ - [X] Feed dog from a tick interrupt
## WASP
@@ -31,9 +29,11 @@ to allow a PineTime case to be confidently glued shut.
- [X] RLE coder and decoder
- [ ] Optimized RLE inner loops
* [X] Backlight driver
- * [ ] Button driver (interrupt based)
+ * [X] Button driver (polling)
* [X] Battery/charger driver
* [ ] Simple clock and battery level application
+ * [X] Basic (WFI) power saving
+ * [X] Implement simple RTC for nrf52
# M2: Great developer experience
@@ -58,6 +58,7 @@ applications.
## WASP
+ * [ ] Button driver (interrupt based)
* [ ] Touch sensor driver
* [ ] Event driven application framework
* [ ] Stopwatch app
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()