mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-17 05:03:07 +00:00
WIP wait fix
This commit is contained in:
parent
0e18fcce96
commit
c97db79d14
@ -1,34 +1,29 @@
|
|||||||
import utime
|
|
||||||
|
|
||||||
from trezor import ui
|
from trezor import ui
|
||||||
from trezor import loop
|
from trezor import loop
|
||||||
from trezor import layout
|
|
||||||
from trezor import utils
|
|
||||||
|
|
||||||
def layout_homescreen():
|
def layout_homescreen():
|
||||||
print("Homescreen layout!")
|
print("Homescreen layout!")
|
||||||
|
|
||||||
|
# ui.display.bar(0, 0, 240, 240, ui.WHITE)
|
||||||
|
|
||||||
|
# f = open('apps/homescreen/trezor.toig', 'r')
|
||||||
|
|
||||||
|
# def func(foreground):
|
||||||
|
# f.seek(0)
|
||||||
|
# ui.display.icon(0, 0, f.read(), foreground, ui.BLACK)
|
||||||
|
|
||||||
|
# animation = ui.animate_pulse(func, ui.WHITE, ui.GREY, speed=400000)
|
||||||
|
|
||||||
|
timeout = loop.sleep(1000 * 1000)
|
||||||
|
|
||||||
|
yield loop.wait([timeout])
|
||||||
|
print('back to layout')
|
||||||
|
|
||||||
|
# try:
|
||||||
|
# print(animation.throw(StopIteration()))
|
||||||
|
# except:
|
||||||
|
# pass
|
||||||
|
|
||||||
# from apps import playground
|
# from apps import playground
|
||||||
# loop.call_at(utime.ticks_us() + 5 * 1000000, layout.change(playground.layout_tap_to_confirm('1BitkeyP2nDd5oa64x7AjvBbbwST54W5Zmx2', 110.126967, 'BTC')))
|
# return playground.layout_tap_to_confirm('1BitkeyP2nDd5oa64x7AjvBbbwST54W5Zmx2', 110.126967, 'BTC')
|
||||||
|
|
||||||
ui.display.bar(0, 0, 240, 240, ui.WHITE)
|
|
||||||
|
|
||||||
f = open('apps/homescreen/trezor.toig', 'r')
|
|
||||||
|
|
||||||
def func(foreground):
|
|
||||||
f.seek(0)
|
|
||||||
ui.display.icon(0, 0, f.read(), foreground, ui.BLACK)
|
|
||||||
|
|
||||||
animation = ui.animate_pulse(func, ui.WHITE, ui.GREY, speed=400000)
|
|
||||||
|
|
||||||
timeout = loop.sleep(3 * 1000000)
|
|
||||||
|
|
||||||
yield from loop.wait([timeout, animation])
|
|
||||||
|
|
||||||
try:
|
|
||||||
print(animation.throw(StopIteration()))
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
|
|
||||||
from apps import playground
|
|
||||||
return playground.layout_tap_to_confirm('1BitkeyP2nDd5oa64x7AjvBbbwST54W5Zmx2', 110.126967, 'BTC')
|
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
import sys
|
import sys
|
||||||
import utime
|
import utime
|
||||||
from . import utils
|
|
||||||
|
|
||||||
from . import log
|
from . import log
|
||||||
|
from . import utils
|
||||||
|
|
||||||
_new_layout = None
|
_new_layout = None
|
||||||
_current_layout = None
|
_current_layout = None
|
||||||
|
@ -11,10 +11,14 @@ EVT_TMOVE = const(-2)
|
|||||||
EVT_TEND = const(-3)
|
EVT_TEND = const(-3)
|
||||||
EVT_MSG = const(-4)
|
EVT_MSG = const(-4)
|
||||||
|
|
||||||
evt_handlers = { EVT_TSTART: None,
|
DO_NOTHING = const(-5)
|
||||||
EVT_TMOVE: None,
|
|
||||||
EVT_TEND: None,
|
evt_handlers = {
|
||||||
EVT_MSG: None, }
|
EVT_TSTART: None,
|
||||||
|
EVT_TMOVE: None,
|
||||||
|
EVT_TEND: None,
|
||||||
|
EVT_MSG: None,
|
||||||
|
}
|
||||||
time_queue = []
|
time_queue = []
|
||||||
|
|
||||||
if __debug__:
|
if __debug__:
|
||||||
@ -32,30 +36,47 @@ def __call_at(time, gen):
|
|||||||
time = utime.ticks_us()
|
time = utime.ticks_us()
|
||||||
heappush(time_queue, (time, gen))
|
heappush(time_queue, (time, gen))
|
||||||
|
|
||||||
def __wait_gen(gen, cb):
|
|
||||||
if isinstance(gen, int):
|
|
||||||
ret = yield gen
|
|
||||||
|
|
||||||
else:
|
def __wait_for_gen(gen, cb):
|
||||||
|
if isinstance(gen, type_gen):
|
||||||
ret = yield from gen
|
ret = yield from gen
|
||||||
|
else:
|
||||||
|
ret = yield gen
|
||||||
|
try:
|
||||||
|
cb.throw(StopIteration)
|
||||||
|
except Exception as e:
|
||||||
|
log.info(__name__, '__wait_gen throw raised %s', e)
|
||||||
|
|
||||||
cb.throw(StopIteration())
|
log.info(__name__, '__wait_gen returning %s', ret)
|
||||||
|
|
||||||
|
|
||||||
def __wait_cb():
|
class __Wait():
|
||||||
while True:
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def __wait_callback(call_after):
|
||||||
|
# TODO: rewrite as instance of __Wait instead of generator
|
||||||
|
delegate = yield
|
||||||
|
received = 0
|
||||||
|
while received < call_after:
|
||||||
try:
|
try:
|
||||||
yield sleep(1000000)
|
yield
|
||||||
except StopIteration:
|
except StopIteration:
|
||||||
break
|
received += 1
|
||||||
|
__call_at(None, delegate)
|
||||||
|
|
||||||
def wait(gens):
|
|
||||||
cb = __wait_cb()
|
|
||||||
cb.send(None)
|
|
||||||
|
|
||||||
|
def wait_for_first(gens):
|
||||||
|
cb = __wait_callback(1)
|
||||||
for g in gens:
|
for g in gens:
|
||||||
__call_at(None, __wait_gen(g, cb))
|
__call_at(None, __wait_for_gen(g, cb))
|
||||||
|
return cb
|
||||||
|
|
||||||
|
|
||||||
|
def wait_for_all(gens):
|
||||||
|
cb = __wait_callback(len(gens))
|
||||||
|
for g in gens:
|
||||||
|
__call_at(None, __wait_for_gen(g, cb))
|
||||||
return cb
|
return cb
|
||||||
|
|
||||||
|
|
||||||
@ -99,9 +120,12 @@ def run_forever(start_gens):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
ret = gen.send(None)
|
ret = gen.send(None)
|
||||||
|
|
||||||
except StopIteration as e:
|
except StopIteration as e:
|
||||||
|
log.info(__name__, '%s ended', gen)
|
||||||
# gen ended, forget it and go on
|
# gen ended, forget it and go on
|
||||||
continue
|
continue
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
log.exception(__name__, e)
|
log.exception(__name__, e)
|
||||||
continue
|
continue
|
||||||
@ -114,9 +138,14 @@ def run_forever(start_gens):
|
|||||||
# wait for event
|
# wait for event
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
|
elif isinstance(ret, type_gen):
|
||||||
|
log.info(__name__, 'Scheduling %s -> %s', gen, ret)
|
||||||
|
ret.send(None)
|
||||||
|
ret.send(gen)
|
||||||
|
|
||||||
elif ret is None:
|
elif ret is None:
|
||||||
# just call us asap
|
# just call us asap
|
||||||
__call_at(None, gen)
|
__call_at(None, gen)
|
||||||
else:
|
|
||||||
|
|
||||||
raise Exception("Unhandled result %s" % gen)
|
else:
|
||||||
|
raise Exception("Unhandled result %s by %s" % (ret, gen))
|
||||||
|
Loading…
Reference in New Issue
Block a user