summaryrefslogtreecommitdiff
path: root/wasp/manager.py
diff options
context:
space:
mode:
authorDaniel Thompson <daniel@redfelineninja.org.uk>2020-03-08 10:18:08 (GMT)
committerDaniel Thompson <daniel@redfelineninja.org.uk>2020-03-08 10:18:08 (GMT)
commitb5b96bd7760f76d9bb476eb835f49b3c9586ca5c (patch)
tree2c9f5e9d4682a1efc870754d2e37d680f33925a2 /wasp/manager.py
parent753a1e68f114772cd0fce765c7ec4770c8e34036 (diff)
wasp: Integrate the touch driver
At this point we are starting to bring an event model for applications but there's still a long way to go!
Diffstat (limited to 'wasp/manager.py')
-rw-r--r--wasp/manager.py74
1 files changed, 68 insertions, 6 deletions
diff --git a/wasp/manager.py b/wasp/manager.py
index 879c3f2..6e45518 100644
--- a/wasp/manager.py
+++ b/wasp/manager.py
@@ -1,30 +1,69 @@
import clock
+import flashlight
+import testapp
import gc
import machine
-EVENT_TICK = 0x100
-EVENT_KEYMASK = 0xff
+DOWN = 1
+UP = 2
+LEFT = 3
+RIGHT = 4
+
+EVENT_TOUCH = 0x0001
+EVENT_BUTTON = 0x0002
class Manager(object):
def __init__(self, watch):
self.watch = watch
self.app = None
- self.switch(clock.ClockApp())
+
+ self.applications = [
+ clock.ClockApp(),
+ flashlight.FlashlightApp(),
+ testapp.TouchTestApp()
+ ]
+
+ self.watch.display.poweron()
+ self.switch(self.applications[0])
+ self.watch.backlight.set(2)
+
self.sleep_at = watch.rtc.uptime + 90
self.charging = True
def switch(self, app):
if self.app:
- self.app.background(self)
+ self.app.background()
# Clear out any configuration from the old application
+ self.event_mask = 0
self.tick_period_ms = 0
self.tick_expiry = None
self.app = app
app.foreground(self)
+ def navigate(self, direction=None):
+ """Navigate between different applications.
+
+ Currently the direction is ignored.
+ """
+ app_list = self.applications
+
+ if direction == DOWN:
+ i = app_list.index(self.app) + 1
+ if i >= len(app_list):
+ i = 0
+ self.switch(app_list[i])
+ elif direction == UP:
+ i = app_list.index(self.app) - 1
+ if i < 0:
+ i = len(app_list)-1
+ self.switch(app_list[i])
+
+ def request_event(self, event_mask):
+ self.event_mask |= event_mask
+
def request_tick(self, period_ms=None):
"""Request (and subscribe to) a periodic tick event.
@@ -34,6 +73,14 @@ class Manager(object):
self.tick_period_ms = period_ms
self.tick_expiry = self.watch.rtc.get_uptime_ms() + period_ms
+ def handle_event(self, event):
+ self.sleep_at = self.watch.rtc.uptime + 15
+
+ if event[0] < 5:
+ self.navigate(event[0])
+ elif event[0] == 5 and self.event_mask & EVENT_TOUCH:
+ self.app.touch(event)
+
def tick(self):
rtc = self.watch.rtc
@@ -51,8 +98,15 @@ class Manager(object):
if self.watch.button.value():
self.sleep_at = self.watch.rtc.uptime + 15
+ event = self.watch.touch.get_event()
+ if event:
+ self.handle_event(event)
+
if self.watch.rtc.uptime > self.sleep_at:
self.watch.backlight.set(0)
+ if not self.app.sleep():
+ self.switch(self.applications[0])
+ self.app.sleep()
self.watch.display.poweroff()
self.charging = self.watch.battery.charging()
self.sleep_at = None
@@ -64,13 +118,21 @@ class Manager(object):
charging = self.watch.battery.charging()
if self.watch.button.value() or self.charging != charging:
self.watch.display.poweron()
- self.app.tick(None)
+ self.app.wake()
self.watch.backlight.set(2)
- self.sleep_at = self.watch.rtc.uptime + 15
+ # Discard any pending touch events
+ _ = self.watch.touch.get_event()
+ self.sleep_at = self.watch.rtc.uptime + 15
def run(self):
+ """Run the system manager synchronously.
+
+ This allows all watch management activities to handle in the
+ normal execution context meaning any exceptions and other problems
+ can be observed interactively via the console.
+ """
while True:
self.tick()
machine.deepsleep()