mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-01-31 01:41:18 +00:00
experiment with touch event multiplexing
Now we can have 2 buttons!
This commit is contained in:
parent
e8122cc975
commit
af482d3da1
@ -3,6 +3,50 @@ from trezor import ui
|
|||||||
from trezor.utils import unimport_func
|
from trezor.utils import unimport_func
|
||||||
|
|
||||||
|
|
||||||
|
def multiplex_touch_events(gens):
|
||||||
|
while True:
|
||||||
|
e, (x, y) = yield loop.Wait([
|
||||||
|
loop.EVT_TSTART,
|
||||||
|
loop.EVT_TMOVE,
|
||||||
|
loop.EVT_TEND,
|
||||||
|
])
|
||||||
|
for gen in gens:
|
||||||
|
gen.send((e, (x, y)))
|
||||||
|
|
||||||
|
|
||||||
|
def in_area(pos, area):
|
||||||
|
x, y = pos
|
||||||
|
ax, ay, aw, ah = area
|
||||||
|
return ax <= x <= ax + aw and ay <= y <= ay + ah
|
||||||
|
|
||||||
|
|
||||||
|
def click_in(area, enter, leave):
|
||||||
|
while True:
|
||||||
|
e, pos = yield
|
||||||
|
if e is not loop.EVT_TSTART or not in_area(pos, area):
|
||||||
|
continue
|
||||||
|
|
||||||
|
inside = True
|
||||||
|
enter()
|
||||||
|
|
||||||
|
while True:
|
||||||
|
e, pos = yield
|
||||||
|
if e is loop.EVT_TMOVE:
|
||||||
|
if in_area(pos, area):
|
||||||
|
if not inside:
|
||||||
|
enter()
|
||||||
|
inside = True
|
||||||
|
else:
|
||||||
|
if inside:
|
||||||
|
leave()
|
||||||
|
inside = False
|
||||||
|
elif e is loop.EVT_TEND:
|
||||||
|
if in_area(pos, area):
|
||||||
|
return
|
||||||
|
else:
|
||||||
|
break
|
||||||
|
|
||||||
|
|
||||||
def layout_tap_to_confirm(address, amount, currency):
|
def layout_tap_to_confirm(address, amount, currency):
|
||||||
|
|
||||||
ui.display.bar(0, 0, 240, 40, ui.GREEN)
|
ui.display.bar(0, 0, 240, 40, ui.GREEN)
|
||||||
@ -16,18 +60,35 @@ def layout_tap_to_confirm(address, amount, currency):
|
|||||||
|
|
||||||
f = open('apps/playground/tap_64.toig', 'rb')
|
f = open('apps/playground/tap_64.toig', 'rb')
|
||||||
bg = ui.WHITE
|
bg = ui.WHITE
|
||||||
|
style = ui.NORMAL
|
||||||
|
|
||||||
|
def enter():
|
||||||
|
nonlocal style
|
||||||
|
style = ui.BOLD
|
||||||
|
|
||||||
|
def leave():
|
||||||
|
nonlocal style
|
||||||
|
style = ui.NORMAL
|
||||||
|
|
||||||
def func(fg):
|
def func(fg):
|
||||||
ui.display.text(68, 212, 'TAP TO CONFIRM', ui.BOLD, fg, bg)
|
ui.display.text(68, 212, 'TAP TO CONFIRM', style, fg, bg)
|
||||||
f.seek(0)
|
f.seek(0)
|
||||||
ui.display.icon(3, 170, f.read(), bg, fg)
|
ui.display.icon(3, 170, f.read(), bg, fg)
|
||||||
|
|
||||||
animation = ui.animate_pulse(func, ui.BLACK, ui.GREY, speed=200000)
|
animation = ui.animate_pulse(func, ui.BLACK, ui.GREY, speed=200000)
|
||||||
|
click_up = click_in((0, 0, 240, 40), enter, leave)
|
||||||
|
click_down = click_in((0, 200, 240, 40), enter, leave)
|
||||||
|
|
||||||
yield loop.Wait([
|
next(click_down)
|
||||||
|
next(click_up)
|
||||||
|
|
||||||
|
yield loop.Wait((
|
||||||
animation,
|
animation,
|
||||||
loop.EVT_TSTART,
|
multiplex_touch_events((
|
||||||
])
|
click_down,
|
||||||
|
click_up,
|
||||||
|
)),
|
||||||
|
))
|
||||||
|
|
||||||
|
|
||||||
@unimport_func
|
@unimport_func
|
||||||
|
@ -26,14 +26,14 @@ if __debug__:
|
|||||||
log_delay_rb = array.array('i', [0] * log_delay_rb_len)
|
log_delay_rb = array.array('i', [0] * log_delay_rb_len)
|
||||||
|
|
||||||
|
|
||||||
def __schedule(gen, time=None):
|
def __schedule(gen, args=(), time=None):
|
||||||
if __debug__:
|
if __debug__:
|
||||||
log.debug(__name__, 'Scheduling %s %s', time, gen)
|
log.debug(__name__, 'Scheduling %s %s', time, gen)
|
||||||
|
|
||||||
if not time:
|
if not time:
|
||||||
time = utime.ticks_us()
|
time = utime.ticks_us()
|
||||||
|
|
||||||
heappush(time_queue, (time, gen))
|
heappush(time_queue, (time, gen, args))
|
||||||
|
|
||||||
|
|
||||||
class Wait():
|
class Wait():
|
||||||
@ -59,7 +59,7 @@ class Wait():
|
|||||||
self.received += 1
|
self.received += 1
|
||||||
|
|
||||||
if self.received == self.wait_for:
|
if self.received == self.wait_for:
|
||||||
__schedule(self.callback)
|
__schedule(self.callback, (gen, result))
|
||||||
self.callback = None
|
self.callback = None
|
||||||
|
|
||||||
if self.exit_others:
|
if self.exit_others:
|
||||||
@ -88,7 +88,7 @@ def run_forever(start_gens):
|
|||||||
while True:
|
while True:
|
||||||
|
|
||||||
if time_queue:
|
if time_queue:
|
||||||
t, _ = time_queue[0]
|
t, _, _ = time_queue[0]
|
||||||
delay = t - utime.ticks_us()
|
delay = t - utime.ticks_us()
|
||||||
else:
|
else:
|
||||||
delay = delay_max
|
delay = delay_max
|
||||||
@ -109,18 +109,17 @@ def run_forever(start_gens):
|
|||||||
if not gen:
|
if not gen:
|
||||||
log.info(__name__, 'No handler for event: %s', event)
|
log.info(__name__, 'No handler for event: %s', event)
|
||||||
continue
|
continue
|
||||||
if not args:
|
|
||||||
args = None
|
|
||||||
else:
|
else:
|
||||||
if time_queue:
|
if time_queue:
|
||||||
# Run something from the time queue
|
# Run something from the time queue
|
||||||
_, gen = heappop(time_queue)
|
_, gen, args = heappop(time_queue)
|
||||||
args = None
|
|
||||||
else:
|
else:
|
||||||
# Sleep again
|
# Sleep again
|
||||||
delay = delay_max
|
delay = delay_max
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
if not args:
|
||||||
|
args = None
|
||||||
try:
|
try:
|
||||||
ret = gen.send(args)
|
ret = gen.send(args)
|
||||||
|
|
||||||
@ -134,13 +133,12 @@ def run_forever(start_gens):
|
|||||||
|
|
||||||
if isinstance(ret, int) and ret >= 0:
|
if isinstance(ret, int) and ret >= 0:
|
||||||
# Sleep until ret, call us later
|
# Sleep until ret, call us later
|
||||||
__schedule(gen, ret)
|
__schedule(gen, (), ret)
|
||||||
|
|
||||||
elif isinstance(ret, int) and ret in event_handlers:
|
elif isinstance(ret, int) and ret in event_handlers:
|
||||||
# Wait for event
|
# Wait for event
|
||||||
if event_handlers[ret]:
|
if event_handlers[ret]:
|
||||||
raise Exception('Already waiting for %s: %s' %
|
event_handlers[ret].close()
|
||||||
(ret, event_handlers[ret]))
|
|
||||||
event_handlers[ret] = gen
|
event_handlers[ret] = gen
|
||||||
|
|
||||||
elif isinstance(ret, Wait):
|
elif isinstance(ret, Wait):
|
||||||
|
Loading…
Reference in New Issue
Block a user