2020-03-08 11:18:08 +01:00
|
|
|
import watch
|
|
|
|
import widgets
|
|
|
|
import manager
|
2020-03-08 22:22:54 +01:00
|
|
|
import machine
|
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
|
|
|
|
|
|
|
def foreground(self, system, effect=None):
|
|
|
|
"""Activate the application."""
|
|
|
|
self.on_screen = ( -1, -1, -1, -1, -1, -1 )
|
|
|
|
self.draw(effect)
|
2020-03-08 21:48:48 +01:00
|
|
|
system.request_event(manager.EVENT_TOUCH | manager.EVENT_SWIPE_LEFTRIGHT)
|
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-09 00:16:30 +01:00
|
|
|
draw = 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-08 22:31:17 +01:00
|
|
|
watch.display.mute(True)
|
2020-03-09 01:00:13 +01:00
|
|
|
watch.drawable.fill()
|
2020-03-09 00:16:30 +01:00
|
|
|
watch.drawable.string('{} test'.format(self.test),
|
2020-03-08 21:48:48 +01:00
|
|
|
0, 6, width=240)
|
2020-03-08 22:31:17 +01:00
|
|
|
watch.display.mute(False)
|