2020-03-22 16:40:18 +01:00
|
|
|
# SPDX-License-Identifier: LGPL-3.0-or-later
|
|
|
|
# Copyright (C) 2020 Daniel Thompson
|
|
|
|
|
2020-03-08 22:22:54 +01:00
|
|
|
import machine
|
2020-03-22 13:37:19 +01:00
|
|
|
import wasp
|
2020-03-08 11:18:08 +01:00
|
|
|
|
2020-03-08 21:48:48 +01:00
|
|
|
class TestApp():
|
|
|
|
"""Simple test application.
|
2020-03-08 11:18:08 +01:00
|
|
|
"""
|
|
|
|
|
|
|
|
def __init__(self):
|
2020-03-08 21:48:48 +01:00
|
|
|
self.tests = ('Touch', 'String')
|
|
|
|
self.test = self.tests[0]
|
2020-03-08 11:18:08 +01:00
|
|
|
|
2020-03-22 13:37:19 +01:00
|
|
|
def foreground(self, effect=None):
|
2020-03-08 11:18:08 +01:00
|
|
|
"""Activate the application."""
|
|
|
|
self.on_screen = ( -1, -1, -1, -1, -1, -1 )
|
|
|
|
self.draw(effect)
|
2020-03-27 21:09:28 +01:00
|
|
|
wasp.system.request_event(wasp.EventMask.TOUCH |
|
|
|
|
wasp.EventMask.SWIPE_UPDOWN)
|
2020-03-08 11:18:08 +01:00
|
|
|
|
|
|
|
def background(self):
|
|
|
|
"""De-activate the application (without losing state)."""
|
|
|
|
pass
|
|
|
|
|
|
|
|
def sleep(self):
|
|
|
|
return False
|
|
|
|
|
2020-03-08 21:48:48 +01:00
|
|
|
def swipe(self, event):
|
|
|
|
tests = self.tests
|
|
|
|
i = tests.index(self.test) + 1
|
|
|
|
if i >= len(tests):
|
|
|
|
i = 0
|
|
|
|
self.test = tests[i]
|
|
|
|
self.draw()
|
|
|
|
|
2020-03-08 11:18:08 +01:00
|
|
|
def touch(self, event):
|
2020-03-22 13:37:19 +01:00
|
|
|
draw = wasp.watch.drawable
|
2020-03-08 21:48:48 +01:00
|
|
|
if self.test == 'Touch':
|
|
|
|
draw.string('({}, {})'.format(event[1], event[2]),
|
2020-03-08 22:22:54 +01:00
|
|
|
0, 108, width=240)
|
2020-03-08 21:48:48 +01:00
|
|
|
elif self.test == 'String':
|
2020-03-09 01:00:13 +01:00
|
|
|
draw.fill(0, 0, 30, 240, 240-30)
|
2020-03-08 22:22:54 +01:00
|
|
|
t = machine.Timer(id=1, period=8000000)
|
|
|
|
t.start()
|
2020-03-08 21:48:48 +01:00
|
|
|
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)
|
2020-03-08 22:22:54 +01:00
|
|
|
elapsed = t.time()
|
|
|
|
t.stop()
|
|
|
|
del t
|
|
|
|
draw.string('{}s'.format(elapsed / 1000000), 12, 24+192)
|
2020-03-08 21:48:48 +01:00
|
|
|
|
2020-03-08 11:18:08 +01:00
|
|
|
return True
|
|
|
|
|
|
|
|
def draw(self, effect=None):
|
|
|
|
"""Redraw the display from scratch."""
|
2020-03-22 13:37:19 +01:00
|
|
|
wasp.watch.display.mute(True)
|
|
|
|
wasp.watch.drawable.fill()
|
|
|
|
wasp.watch.drawable.string('{} test'.format(self.test),
|
2020-03-08 21:48:48 +01:00
|
|
|
0, 6, width=240)
|
2020-03-22 13:37:19 +01:00
|
|
|
wasp.watch.display.mute(False)
|