refactor(core/ui): DebugLink swipe for rust layouts

[no changelog]
pull/2357/head
Martin Milata 2 years ago
parent c9ca7cd544
commit ccf364f1da

@ -71,18 +71,17 @@ if __debug__:
async def dispatch_debuglink_decision(msg: DebugLinkDecision) -> None:
from trezor.enums import DebugButton, DebugSwipeDirection
from trezor.ui import Result
from trezor.ui.components.common import (
SWIPE_UP,
SWIPE_DOWN,
SWIPE_LEFT,
SWIPE_RIGHT,
)
if UI2:
confirm = trezorui2
class swipe:
SWIPE_UP = 0x01
SWIPE_DOWN = 0x02
SWIPE_LEFT = 0x04
SWIPE_RIGHT = 0x08
else:
from trezor.ui.components.tt import confirm, swipe
from trezor.ui.components.tt import confirm
if msg.button is not None:
if msg.button == DebugButton.NO:
@ -93,13 +92,13 @@ if __debug__:
await confirm_chan.put(Result(confirm.INFO))
if msg.swipe is not None:
if msg.swipe == DebugSwipeDirection.UP:
await swipe_chan.put(swipe.SWIPE_UP)
await swipe_chan.put(SWIPE_UP)
elif msg.swipe == DebugSwipeDirection.DOWN:
await swipe_chan.put(swipe.SWIPE_DOWN)
await swipe_chan.put(SWIPE_DOWN)
elif msg.swipe == DebugSwipeDirection.LEFT:
await swipe_chan.put(swipe.SWIPE_LEFT)
await swipe_chan.put(SWIPE_LEFT)
elif msg.swipe == DebugSwipeDirection.RIGHT:
await swipe_chan.put(swipe.SWIPE_RIGHT)
await swipe_chan.put(SWIPE_RIGHT)
if msg.input is not None:
await input_chan.put(Result(msg.input))

@ -2,6 +2,12 @@
The components/common module contains code that is used by both components/tt
and components/t1.
"""
from micropython import const
SWIPE_UP = const(0x01)
SWIPE_DOWN = const(0x02)
SWIPE_LEFT = const(0x04)
SWIPE_RIGHT = const(0x08)
def break_path_to_lines(path_str: str, per_line: int) -> list[str]:

@ -2,14 +2,11 @@ from micropython import const
from typing import Generator
from trezor import io, loop, ui
from trezor.ui.components.common import SWIPE_DOWN, SWIPE_LEFT, SWIPE_RIGHT, SWIPE_UP
SWIPE_UP = const(0x01)
SWIPE_DOWN = const(0x02)
SWIPE_LEFT = const(0x04)
SWIPE_RIGHT = const(0x08)
SWIPE_VERTICAL = const(SWIPE_UP | SWIPE_DOWN)
SWIPE_HORIZONTAL = const(SWIPE_LEFT | SWIPE_RIGHT)
SWIPE_ALL = const(SWIPE_VERTICAL | SWIPE_HORIZONTAL)
SWIPE_VERTICAL = SWIPE_UP | SWIPE_DOWN
SWIPE_HORIZONTAL = SWIPE_LEFT | SWIPE_RIGHT
SWIPE_ALL = SWIPE_VERTICAL | SWIPE_HORIZONTAL
_SWIPE_DISTANCE = const(120)
_SWIPE_TRESHOLD = const(30)

@ -33,6 +33,7 @@ class _RustLayout(ui.Layout):
return (
self.handle_timers(),
self.handle_input_and_rendering(),
self.handle_swipe(),
confirm_signal(),
input_signal(),
)
@ -48,6 +49,37 @@ class _RustLayout(ui.Layout):
result = " ".join(result).split("\n")
return result
async def handle_swipe(self):
from apps.debug import notify_layout_change, swipe_signal
from trezor.ui.components.common import (
SWIPE_UP,
SWIPE_DOWN,
SWIPE_LEFT,
SWIPE_RIGHT,
)
while True:
direction = await swipe_signal()
orig_x = orig_y = 120
off_x, off_y = {
SWIPE_UP: (0, -30),
SWIPE_DOWN: (0, 30),
SWIPE_LEFT: (-30, 0),
SWIPE_RIGHT: (30, 0),
}[direction]
for event, x, y in (
(io.TOUCH_START, orig_x, orig_y),
(io.TOUCH_MOVE, orig_x + 1 * off_x, orig_y + 1 * off_y),
(io.TOUCH_END, orig_x + 2 * off_x, orig_y + 2 * off_y),
):
msg = self.layout.touch_event(event, x, y)
self.layout.paint()
if msg is not None:
raise ui.Result(msg)
notify_layout_change(self)
else:
def create_tasks(self) -> tuple[loop.AwaitableTask, ...]:

Loading…
Cancel
Save