wasp: testapp: Extend with a string render test
This commit is contained in:
parent
a864a93706
commit
cfffeddd77
2 changed files with 41 additions and 11 deletions
|
@ -4,18 +4,20 @@ import manager
|
||||||
|
|
||||||
from draw565 import Draw565
|
from draw565 import Draw565
|
||||||
|
|
||||||
class TouchTestApp(object):
|
class TestApp():
|
||||||
"""Simple application to visualize touch events.
|
"""Simple test application.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
pass
|
self.tests = ('Touch', 'String')
|
||||||
|
self.test = self.tests[0]
|
||||||
|
self.drawable = Draw565(watch.display)
|
||||||
|
|
||||||
def foreground(self, system, effect=None):
|
def foreground(self, system, 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 )
|
||||||
self.draw(effect)
|
self.draw(effect)
|
||||||
system.request_event(manager.EVENT_TOUCH)
|
system.request_event(manager.EVENT_TOUCH | manager.EVENT_SWIPE_LEFTRIGHT)
|
||||||
|
|
||||||
def background(self):
|
def background(self):
|
||||||
"""De-activate the application (without losing state)."""
|
"""De-activate the application (without losing state)."""
|
||||||
|
@ -24,12 +26,31 @@ class TouchTestApp(object):
|
||||||
def sleep(self):
|
def sleep(self):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
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()
|
||||||
|
|
||||||
def touch(self, event):
|
def touch(self, event):
|
||||||
draw = Draw565(watch.display)
|
draw = self.drawable
|
||||||
draw.string('({}, {})'.format(event[1], event[2]),
|
if self.test == 'Touch':
|
||||||
0, 180, width=240)
|
draw.string('({}, {})'.format(event[1], event[2]),
|
||||||
|
0, 180, width=240)
|
||||||
|
elif self.test == 'String':
|
||||||
|
watch.display.fill(0, 0, 30, 240, 240-30)
|
||||||
|
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)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def draw(self, effect=None):
|
def draw(self, effect=None):
|
||||||
"""Redraw the display from scratch."""
|
"""Redraw the display from scratch."""
|
||||||
watch.display.fill(0)
|
watch.display.fill(0)
|
||||||
|
self.drawable.string('{} test'.format(self.test),
|
||||||
|
0, 6, width=240)
|
||||||
|
|
|
@ -3,7 +3,7 @@ import machine
|
||||||
|
|
||||||
from apps.clock import ClockApp
|
from apps.clock import ClockApp
|
||||||
from apps.flashlight import FlashlightApp
|
from apps.flashlight import FlashlightApp
|
||||||
from apps.testapp import TouchTestApp
|
from apps.testapp import TestApp
|
||||||
|
|
||||||
DOWN = 1
|
DOWN = 1
|
||||||
UP = 2
|
UP = 2
|
||||||
|
@ -11,7 +11,9 @@ LEFT = 3
|
||||||
RIGHT = 4
|
RIGHT = 4
|
||||||
|
|
||||||
EVENT_TOUCH = 0x0001
|
EVENT_TOUCH = 0x0001
|
||||||
EVENT_BUTTON = 0x0002
|
EVENT_SWIPE_LEFTRIGHT = 0x0002
|
||||||
|
EVENT_SWIPE_UPDOWN = 0x0004
|
||||||
|
EVENT_BUTTON = 0x0008
|
||||||
|
|
||||||
class Manager(object):
|
class Manager(object):
|
||||||
def __init__(self, watch):
|
def __init__(self, watch):
|
||||||
|
@ -22,7 +24,7 @@ class Manager(object):
|
||||||
self.applications = [
|
self.applications = [
|
||||||
ClockApp(),
|
ClockApp(),
|
||||||
FlashlightApp(),
|
FlashlightApp(),
|
||||||
TouchTestApp()
|
TestApp()
|
||||||
]
|
]
|
||||||
|
|
||||||
self.watch.display.poweron()
|
self.watch.display.poweron()
|
||||||
|
@ -79,8 +81,15 @@ class Manager(object):
|
||||||
def handle_event(self, event):
|
def handle_event(self, event):
|
||||||
self.sleep_at = self.watch.rtc.uptime + 15
|
self.sleep_at = self.watch.rtc.uptime + 15
|
||||||
|
|
||||||
|
event_mask = self.event_mask
|
||||||
if event[0] < 5:
|
if event[0] < 5:
|
||||||
self.navigate(event[0])
|
updown = event[0] == 1 or event[0] == 2
|
||||||
|
if (bool(event_mask & EVENT_SWIPE_UPDOWN) and updown) or \
|
||||||
|
(bool(event_mask & EVENT_SWIPE_LEFTRIGHT) and not updown):
|
||||||
|
if not self.app.swipe(event):
|
||||||
|
self.navigate(event[0])
|
||||||
|
else:
|
||||||
|
self.navigate(event[0])
|
||||||
elif event[0] == 5 and self.event_mask & EVENT_TOUCH:
|
elif event[0] == 5 and self.event_mask & EVENT_TOUCH:
|
||||||
self.app.touch(event)
|
self.app.touch(event)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue