mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-01-23 13:51:00 +00:00
core: dispatch DebugLinkDecisions from a common queue
This commit is contained in:
parent
741bfd5c53
commit
c285bbba7a
@ -26,39 +26,36 @@ if __debug__:
|
||||
swipe_signal = swipe_chan.take
|
||||
input_signal = input_chan.take
|
||||
|
||||
async def dispatch_DebugLinkDecision(
|
||||
ctx: wire.Context, msg: DebugLinkDecision
|
||||
) -> None:
|
||||
debuglink_decision_chan = loop.chan()
|
||||
|
||||
async def debuglink_decision_dispatcher():
|
||||
from trezor.ui import confirm, swipe
|
||||
|
||||
waiting_signals = [
|
||||
bool(s.putters) for s in (confirm_chan, swipe_chan, input_chan)
|
||||
]
|
||||
if sum(waiting_signals) > 0:
|
||||
log.warning(
|
||||
__name__,
|
||||
"Received new DebugLinkDecision before the previous one was handled.",
|
||||
)
|
||||
log.warning(
|
||||
__name__,
|
||||
"received: button {}, swipe {}, input {}".format(
|
||||
msg.yes_no, msg.up_down, msg.input
|
||||
),
|
||||
)
|
||||
log.warning(
|
||||
__name__,
|
||||
"waiting: button {}, swipe {}, input {}".format(*waiting_signals),
|
||||
)
|
||||
while True:
|
||||
msg = await debuglink_decision_chan.take()
|
||||
|
||||
if msg.yes_no is not None:
|
||||
await confirm_chan.put(
|
||||
confirm.CONFIRMED if msg.yes_no else confirm.CANCELLED
|
||||
)
|
||||
if msg.up_down is not None:
|
||||
await swipe_chan.put(swipe.SWIPE_DOWN if msg.up_down else swipe.SWIPE_UP)
|
||||
await swipe_chan.put(
|
||||
swipe.SWIPE_DOWN if msg.up_down else swipe.SWIPE_UP
|
||||
)
|
||||
if msg.input is not None:
|
||||
await input_chan.put(msg.input)
|
||||
|
||||
loop.schedule(debuglink_decision_dispatcher())
|
||||
|
||||
async def dispatch_DebugLinkDecision(
|
||||
ctx: wire.Context, msg: DebugLinkDecision
|
||||
) -> None:
|
||||
|
||||
if debuglink_decision_chan.putters:
|
||||
log.warning(__name__, "DebugLinkDecision queue is not empty")
|
||||
|
||||
debuglink_decision_chan.publish(msg)
|
||||
|
||||
async def dispatch_DebugLinkGetState(
|
||||
ctx: wire.Context, msg: DebugLinkGetState
|
||||
) -> DebugLinkState:
|
||||
|
Loading…
Reference in New Issue
Block a user