1
0
Fork 0

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).
pull/5/head
Daniel Thompson 2020-02-03 19:24:09 +00:00
parent fc74f7e37b
commit 3892f07e62
6 changed files with 98 additions and 18 deletions

11
TODO.md
View File

@ -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

View File

@ -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

View File

@ -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)

43
wasp/clock.py 100644
View File

@ -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

View File

@ -1,4 +1 @@
import machine
while True
machine.deepsleep()
wasp.run()

42
wasp/manager.py 100644
View File

@ -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()