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).
This commit is contained in:
parent
fc74f7e37b
commit
3892f07e62
6 changed files with 98 additions and 18 deletions
11
TODO.md
11
TODO.md
|
@ -17,11 +17,9 @@ to allow a PineTime case to be confidently glued shut.
|
||||||
## MicroPython
|
## MicroPython
|
||||||
|
|
||||||
* [X] Basic board ports (PineTime, DS-D6, 96Boards Nitrogen)
|
* [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
|
- [X] Feed dog from REPL polling loop
|
||||||
- [ ] Feed dog from a tick interrupt
|
- [X] Feed dog from a tick interrupt
|
||||||
* [ ] Basic (WFI) power saving
|
|
||||||
* [ ] Implement machine.RTC for nrf52
|
|
||||||
|
|
||||||
## WASP
|
## WASP
|
||||||
|
|
||||||
|
@ -31,9 +29,11 @@ to allow a PineTime case to be confidently glued shut.
|
||||||
- [X] RLE coder and decoder
|
- [X] RLE coder and decoder
|
||||||
- [ ] Optimized RLE inner loops
|
- [ ] Optimized RLE inner loops
|
||||||
* [X] Backlight driver
|
* [X] Backlight driver
|
||||||
* [ ] Button driver (interrupt based)
|
* [X] Button driver (polling)
|
||||||
* [X] Battery/charger driver
|
* [X] Battery/charger driver
|
||||||
* [ ] Simple clock and battery level application
|
* [ ] Simple clock and battery level application
|
||||||
|
* [X] Basic (WFI) power saving
|
||||||
|
* [X] Implement simple RTC for nrf52
|
||||||
|
|
||||||
# M2: Great developer experience
|
# M2: Great developer experience
|
||||||
|
|
||||||
|
@ -58,6 +58,7 @@ applications.
|
||||||
|
|
||||||
## WASP
|
## WASP
|
||||||
|
|
||||||
|
* [ ] Button driver (interrupt based)
|
||||||
* [ ] Touch sensor driver
|
* [ ] Touch sensor driver
|
||||||
* [ ] Event driven application framework
|
* [ ] Event driven application framework
|
||||||
* [ ] Stopwatch app
|
* [ ] Stopwatch app
|
||||||
|
|
|
@ -1,12 +1,16 @@
|
||||||
freeze('../..',
|
freeze('../..',
|
||||||
(
|
(
|
||||||
'boot.py',
|
'boot.py',
|
||||||
|
'clock.py',
|
||||||
'demo.py',
|
'demo.py',
|
||||||
'drivers/battery.py',
|
'drivers/battery.py',
|
||||||
'drivers/nrf_rtc.py',
|
'drivers/nrf_rtc.py',
|
||||||
'drivers/signal.py',
|
'drivers/signal.py',
|
||||||
'drivers/st7789.py',
|
'drivers/st7789.py',
|
||||||
'drivers/vibrator.py',
|
'drivers/vibrator.py',
|
||||||
|
'fonts.py',
|
||||||
|
'main.py',
|
||||||
|
'manager.py',
|
||||||
'logo.py',
|
'logo.py',
|
||||||
),
|
),
|
||||||
opt=3
|
opt=3
|
||||||
|
|
11
wasp/boot.py
11
wasp/boot.py
|
@ -1,10 +1,3 @@
|
||||||
import logo
|
import manager
|
||||||
import watch
|
import watch
|
||||||
import time
|
wasp = manager.Manager(watch)
|
||||||
|
|
||||||
# Splash screen
|
|
||||||
watch.display.rleblit(logo.pine64, fg=0xffff)
|
|
||||||
|
|
||||||
time.sleep(5)
|
|
||||||
watch.backlight.set(0)
|
|
||||||
watch.display.poweroff()
|
|
||||||
|
|
43
wasp/clock.py
Normal file
43
wasp/clock.py
Normal 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
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1 @@
|
||||||
import machine
|
wasp.run()
|
||||||
|
|
||||||
while True
|
|
||||||
machine.deepsleep()
|
|
||||||
|
|
42
wasp/manager.py
Normal file
42
wasp/manager.py
Normal 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()
|
Loading…
Reference in a new issue