diff options
| author | Daniel Thompson <daniel@redfelineninja.org.uk> | 2020-03-28 17:27:09 (GMT) |
|---|---|---|
| committer | Daniel Thompson <daniel@redfelineninja.org.uk> | 2020-04-06 21:04:20 (GMT) |
| commit | b2622b579dfc265850401b44a8b825533ea2ec17 (patch) | |
| tree | 7152b6d100ef339e86306c2ec7ccb7d4d7b28fd3 /wasp/apps | |
| parent | 0cc79876890713b49ff6ed155828707f494e37c2 (diff) | |
wasp: Add button presses to the event system.
Here the biggest changes are in the test application because we
refactor a number of the tests to make better use of the button.
Although applications may consume button events it does have a
default behavior which is to switch to the default application
(usually the clock).
Diffstat (limited to 'wasp/apps')
| -rw-r--r-- | wasp/apps/testapp.py | 60 |
1 files changed, 39 insertions, 21 deletions
diff --git a/wasp/apps/testapp.py b/wasp/apps/testapp.py index 711feda..849ed5f 100644 --- a/wasp/apps/testapp.py +++ b/wasp/apps/testapp.py @@ -9,7 +9,7 @@ class TestApp(): """ def __init__(self): - self.tests = ('Touch', 'String') + self.tests = ('Touch', 'String', 'Button') self.test = self.tests[0] def foreground(self): @@ -17,7 +17,8 @@ class TestApp(): self.on_screen = ( -1, -1, -1, -1, -1, -1 ) self.draw() wasp.system.request_event(wasp.EventMask.TOUCH | - wasp.EventMask.SWIPE_UPDOWN) + wasp.EventMask.SWIPE_UPDOWN | + wasp.EventMask.BUTTON) def background(self): """De-activate the application (without losing state).""" @@ -26,34 +27,51 @@ class TestApp(): def sleep(self): return False + def press(self, button, state): + draw = wasp.watch.drawable + if self.test == 'Touch': + draw.string('Button', 0, 108, width=240) + if self.test == 'String': + self.benchmark_string() + elif self.test == 'Button': + draw.string('{}: {}'.format(button, state), 0, 108, width=240) + def swipe(self, event): tests = self.tests - i = tests.index(self.test) + 1 - if i >= len(tests): - i = 0 + i = tests.index(self.test) + + if event[0] == wasp.EventType.UP: + i += 1 + if i >= len(tests): + i = 0 + else: + i -= 1 + if i < 0: + i = len(tests) - 1 self.test = tests[i] self.draw() def touch(self, event): - draw = wasp.watch.drawable if self.test == 'Touch': - draw.string('({}, {})'.format(event[1], event[2]), - 0, 108, width=240) + wasp.watch.drawable.string('({}, {})'.format( + event[1], event[2]), 0, 108, width=240) elif self.test == 'String': - draw.fill(0, 0, 30, 240, 240-30) - t = machine.Timer(id=1, period=8000000) - t.start() - draw.string("The quick brown", 12, 24+24) - draw.string("fox jumped over", 12, 24+48) - draw.string("the lazy dog.", 12, 24+72) - draw.string("0123456789", 12, 24+120) - draw.string('!"£$%^&*()', 12, 24+144) - elapsed = t.time() - t.stop() - del t - draw.string('{}s'.format(elapsed / 1000000), 12, 24+192) + self.benchmark_string() - return True + def benchmark_string(self): + draw = wasp.watch.drawable + draw.fill(0, 0, 30, 240, 240-30) + t = machine.Timer(id=1, period=8000000) + t.start() + draw.string("The quick brown", 12, 24+24) + draw.string("fox jumped over", 12, 24+48) + draw.string("the lazy dog.", 12, 24+72) + draw.string("0123456789", 12, 24+120) + draw.string('!"£$%^&*()', 12, 24+144) + elapsed = t.time() + t.stop() + del t + draw.string('{}s'.format(elapsed / 1000000), 12, 24+192) def draw(self): """Redraw the display from scratch.""" |
