mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-18 20:38:10 +00:00
proof of concept for waiting for events
This commit is contained in:
parent
b5f8c2303c
commit
d612037eda
@ -2,6 +2,7 @@ from trezor import loop
|
|||||||
from trezor import ui
|
from trezor import ui
|
||||||
from trezor.utils import unimport_func
|
from trezor.utils import unimport_func
|
||||||
|
|
||||||
|
|
||||||
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)
|
||||||
@ -14,15 +15,20 @@ def layout_tap_to_confirm(address, amount, currency):
|
|||||||
ui.display.text(10, 160, address[18:], ui.MONO, ui.BLACK, ui.WHITE)
|
ui.display.text(10, 160, address[18:], ui.MONO, ui.BLACK, ui.WHITE)
|
||||||
|
|
||||||
f = open('apps/playground/tap_64.toig', 'rb')
|
f = open('apps/playground/tap_64.toig', 'rb')
|
||||||
_background = ui.WHITE
|
bg = ui.WHITE
|
||||||
|
|
||||||
def func(foreground):
|
|
||||||
ui.display.text(68, 212, 'TAP TO CONFIRM', ui.BOLD, foreground, _background)
|
|
||||||
|
|
||||||
|
def func(fg):
|
||||||
|
ui.display.text(68, 212, 'TAP TO CONFIRM', ui.BOLD, fg, bg)
|
||||||
f.seek(0)
|
f.seek(0)
|
||||||
ui.display.icon(3, 170, f.read(), _background, foreground)
|
ui.display.icon(3, 170, f.read(), bg, fg)
|
||||||
|
|
||||||
|
animation = ui.animate_pulse(func, ui.BLACK, ui.GREY, speed=200000)
|
||||||
|
|
||||||
|
yield loop.Wait([
|
||||||
|
animation,
|
||||||
|
loop.EVT_TSTART,
|
||||||
|
])
|
||||||
|
|
||||||
yield from ui.animate_pulse(func, ui.BLACK, ui.GREY, speed=200000)
|
|
||||||
|
|
||||||
@unimport_func
|
@unimport_func
|
||||||
def zprava():
|
def zprava():
|
||||||
@ -43,10 +49,12 @@ def zprava():
|
|||||||
# m2 = GetAddress.load(BytesIO(data))
|
# m2 = GetAddress.load(BytesIO(data))
|
||||||
# print(m2.__dict__)
|
# print(m2.__dict__)
|
||||||
|
|
||||||
|
|
||||||
def dispatch():
|
def dispatch():
|
||||||
# Callback for HID messages
|
# Callback for HID messages
|
||||||
print("Dispatch playground")
|
print("Dispatch playground")
|
||||||
|
|
||||||
|
|
||||||
def boot():
|
def boot():
|
||||||
# Initilize app on boot time.
|
# Initilize app on boot time.
|
||||||
# This should hookup HID message types dispatcher() wants to receive.
|
# This should hookup HID message types dispatcher() wants to receive.
|
||||||
|
@ -10,7 +10,7 @@ EVT_TMOVE = const(-2)
|
|||||||
EVT_TEND = const(-3)
|
EVT_TEND = const(-3)
|
||||||
EVT_MSG = const(-4)
|
EVT_MSG = const(-4)
|
||||||
|
|
||||||
evt_handlers = {
|
event_handlers = {
|
||||||
EVT_TSTART: None,
|
EVT_TSTART: None,
|
||||||
EVT_TMOVE: None,
|
EVT_TMOVE: None,
|
||||||
EVT_TEND: None,
|
EVT_TEND: None,
|
||||||
@ -101,19 +101,27 @@ def run_forever(start_gens):
|
|||||||
|
|
||||||
if event:
|
if event:
|
||||||
# Run interrupt handler
|
# Run interrupt handler
|
||||||
log.info(__name__, "Received data: %s", event)
|
event_id, *args = event
|
||||||
|
event_id = -event_id
|
||||||
|
gen = event_handlers.get(event_id, None)
|
||||||
|
event_handlers[event_id] = None
|
||||||
|
if not gen:
|
||||||
|
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 = heappop(time_queue)
|
||||||
|
args = None
|
||||||
else:
|
else:
|
||||||
# Sleep again
|
# Sleep again
|
||||||
delay = delay_max
|
delay = delay_max
|
||||||
continue
|
continue
|
||||||
|
|
||||||
try:
|
try:
|
||||||
ret = gen.send(None)
|
ret = gen.send(args)
|
||||||
|
|
||||||
except StopIteration as e:
|
except StopIteration as e:
|
||||||
log.debug(__name__, '%s finished', gen)
|
log.debug(__name__, '%s finished', gen)
|
||||||
@ -123,13 +131,16 @@ def run_forever(start_gens):
|
|||||||
log.exception(__name__, e)
|
log.exception(__name__, e)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if isinstance(ret, int):
|
if isinstance(ret, int) and ret >= 0:
|
||||||
if ret >= 0:
|
|
||||||
# Sleep until ret, call us later
|
# Sleep until ret, call us later
|
||||||
__call_at(ret, gen)
|
__call_at(ret, gen)
|
||||||
else:
|
|
||||||
|
elif isinstance(ret, int) and ret in event_handlers:
|
||||||
# Wait for event
|
# Wait for event
|
||||||
raise NotImplementedError()
|
if event_handlers[ret]:
|
||||||
|
raise Exception('Already waiting for %s: %s' %
|
||||||
|
(ret, event_handlers[ret]))
|
||||||
|
event_handlers[ret] = gen
|
||||||
|
|
||||||
elif isinstance(ret, Wait):
|
elif isinstance(ret, Wait):
|
||||||
# Register the origin generator as a waiting callback
|
# Register the origin generator as a waiting callback
|
||||||
@ -140,4 +151,4 @@ def run_forever(start_gens):
|
|||||||
__call_at(None, gen)
|
__call_at(None, gen)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
raise Exception("Unhandled result %s by %s" % (ret, gen))
|
raise Exception('Unhandled result %s by %s' % (ret, gen))
|
||||||
|
Loading…
Reference in New Issue
Block a user