1
0
Fork 0

wasp: Get the terminology straight

As it turned out Direction was only a Direction because there were things
missing from the enumeration!
This commit is contained in:
Daniel Thompson 2020-03-27 20:09:28 +00:00
parent 0ac2321e82
commit d10f3dbc49
3 changed files with 20 additions and 24 deletions

View file

@ -29,14 +29,6 @@ class ClockApp():
def __init__(self): def __init__(self):
self.meter = wasp.widgets.BatteryMeter() self.meter = wasp.widgets.BatteryMeter()
def handle_event(self, event_view):
"""Process events that the app is subscribed to."""
if event_view[0] == wasp.Event.TICK:
self.update()
else:
# TODO: Raise an unexpected event exception
pass
def foreground(self, effect=None): def foreground(self, effect=None):
"""Activate the application.""" """Activate the application."""
self.on_screen = ( -1, -1, -1, -1, -1, -1 ) self.on_screen = ( -1, -1, -1, -1, -1, -1 )

View file

@ -16,7 +16,8 @@ class TestApp():
"""Activate the application.""" """Activate the application."""
self.on_screen = ( -1, -1, -1, -1, -1, -1 ) self.on_screen = ( -1, -1, -1, -1, -1, -1 )
self.draw(effect) self.draw(effect)
wasp.system.request_event(wasp.Event.TOUCH | wasp.Event.SWIPE_UPDOWN) wasp.system.request_event(wasp.EventMask.TOUCH |
wasp.EventMask.SWIPE_UPDOWN)
def background(self): def background(self):
"""De-activate the application (without losing state).""" """De-activate the application (without losing state)."""

View file

@ -17,19 +17,22 @@ from apps.clock import ClockApp
from apps.flashlight import FlashlightApp from apps.flashlight import FlashlightApp
from apps.testapp import TestApp from apps.testapp import TestApp
class Direction(): class EventType():
"""Enumerated directions. """Enumerated interface actions.
MicroPython does not implement the enum module so Direction MicroPython does not implement the enum module so EventType
is simply a regular object which acts as a namespace. is simply a regular object which acts as a namespace.
""" """
DOWN = 1 DOWN = 1
UP = 2 UP = 2
LEFT = 3 LEFT = 3
RIGHT = 4 RIGHT = 4
TOUCH = 5
class Event(): HOME = 256
"""Enumerated event types
class EventMask():
"""Enumerated event masks.
""" """
TOUCH = 0x0001 TOUCH = 0x0001
SWIPE_LEFTRIGHT = 0x0002 SWIPE_LEFTRIGHT = 0x0002
@ -96,18 +99,18 @@ class Manager():
Left/right navigation is used to switch between applications in the Left/right navigation is used to switch between applications in the
quick application ring. Applications on the ring are not permitted quick application ring. Applications on the ring are not permitted
to subscribe to :py:data`Event.SWIPE_LEFTRIGHT` events. to subscribe to :py:data`EventMask.SWIPE_LEFTRIGHT` events.
:param int direction: The direction of the navigation :param int direction: The direction of the navigation
""" """
app_list = self.applications app_list = self.applications
if direction == Direction.LEFT: if direction == EventType.LEFT:
i = app_list.index(self.app) + 1 i = app_list.index(self.app) + 1
if i >= len(app_list): if i >= len(app_list):
i = 0 i = 0
self.switch(app_list[i]) self.switch(app_list[i])
elif direction == Direction.RIGHT: elif direction == EventType.RIGHT:
i = app_list.index(self.app) - 1 i = app_list.index(self.app) - 1
if i < 0: if i < 0:
i = len(app_list)-1 i = len(app_list)-1
@ -156,21 +159,21 @@ class Manager():
self.keep_awake() self.keep_awake()
def _handle_event(self, event): def _handle_touch(self, event):
"""Process an event. """Process a touch event.
""" """
self.keep_awake() self.keep_awake()
event_mask = self.event_mask event_mask = self.event_mask
if event[0] < 5: if event[0] < 5:
updown = event[0] == 1 or event[0] == 2 updown = event[0] == 1 or event[0] == 2
if (bool(event_mask & Event.SWIPE_UPDOWN) and updown) or \ if (bool(event_mask & EventMask.SWIPE_UPDOWN) and updown) or \
(bool(event_mask & Event.SWIPE_LEFTRIGHT) and not updown): (bool(event_mask & EventMask.SWIPE_LEFTRIGHT) and not updown):
if not self.app.swipe(event): if self.app.swipe(event):
self.navigate(event[0]) self.navigate(event[0])
else: else:
self.navigate(event[0]) self.navigate(event[0])
elif event[0] == 5 and self.event_mask & Event.TOUCH: elif event[0] == 5 and self.event_mask & EventMask.TOUCH:
self.app.touch(event) self.app.touch(event)
def _tick(self): def _tick(self):
@ -198,7 +201,7 @@ class Manager():
event = watch.touch.get_event() event = watch.touch.get_event()
if event: if event:
self._handle_event(event) self._handle_touch(event)
if watch.rtc.uptime > self.sleep_at: if watch.rtc.uptime > self.sleep_at:
self.sleep() self.sleep()