mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-07-30 18:38:27 +00:00
TR-python: add debuglink methods for buttons
This commit is contained in:
parent
e3570f7d6d
commit
f7524f7497
@ -508,6 +508,7 @@ class DebugLink:
|
||||
self,
|
||||
word: Optional[str] = None,
|
||||
button: Optional[messages.DebugButton] = None,
|
||||
physical_button: Optional[messages.DebugPhysicalButton] = None,
|
||||
swipe: Optional[messages.DebugSwipeDirection] = None,
|
||||
x: Optional[int] = None,
|
||||
y: Optional[int] = None,
|
||||
@ -517,14 +518,21 @@ class DebugLink:
|
||||
if not self.allow_interactions:
|
||||
return None
|
||||
|
||||
args = sum(a is not None for a in (word, button, swipe, x))
|
||||
args = sum(a is not None for a in (word, button, physical_button, swipe, x))
|
||||
if args != 1:
|
||||
raise ValueError(
|
||||
"Invalid input - must use one of word, button, swipe, click(x,y)"
|
||||
"Invalid input - must use one of word, button, physical_button, swipe, click(x,y)"
|
||||
)
|
||||
|
||||
decision = messages.DebugLinkDecision(
|
||||
button=button, swipe=swipe, input=word, x=x, y=y, wait=wait, hold_ms=hold_ms
|
||||
button=button,
|
||||
physical_button=physical_button,
|
||||
swipe=swipe,
|
||||
input=word,
|
||||
x=x,
|
||||
y=y,
|
||||
wait=wait,
|
||||
hold_ms=hold_ms,
|
||||
)
|
||||
|
||||
ret = self._call(decision, nowait=not wait)
|
||||
@ -564,8 +572,8 @@ class DebugLink:
|
||||
f.write(screen_content)
|
||||
f.write("\n" + 80 * "/" + "\n")
|
||||
|
||||
# Type overloads make sure that when we supply `wait=True` into `click()`,
|
||||
# it will always return `LayoutContent` and we do not need to assert `is not None`.
|
||||
# Type overloads below make sure that when we supply `wait=True` into functions,
|
||||
# they will always return `LayoutContent` and we do not need to assert `is not None`.
|
||||
|
||||
@overload
|
||||
def click(self, click: Tuple[int, int]) -> None:
|
||||
@ -618,6 +626,57 @@ class DebugLink:
|
||||
def swipe_left(self, wait: bool = False) -> Union[LayoutContent, None]:
|
||||
return self.input(swipe=messages.DebugSwipeDirection.LEFT, wait=wait)
|
||||
|
||||
@overload
|
||||
def press_left(self) -> None:
|
||||
...
|
||||
|
||||
@overload
|
||||
def press_left(self, wait: Literal[True]) -> LayoutContent:
|
||||
...
|
||||
|
||||
def press_left(self, wait: bool = False) -> Optional[LayoutContent]:
|
||||
return self.input(
|
||||
physical_button=messages.DebugPhysicalButton.LEFT_BTN, wait=wait
|
||||
)
|
||||
|
||||
@overload
|
||||
def press_middle(self) -> None:
|
||||
...
|
||||
|
||||
@overload
|
||||
def press_middle(self, wait: Literal[True]) -> LayoutContent:
|
||||
...
|
||||
|
||||
def press_middle(self, wait: bool = False) -> Optional[LayoutContent]:
|
||||
return self.input(
|
||||
physical_button=messages.DebugPhysicalButton.MIDDLE_BTN, wait=wait
|
||||
)
|
||||
|
||||
@overload
|
||||
def press_right(self) -> None:
|
||||
...
|
||||
|
||||
@overload
|
||||
def press_right(self, wait: Literal[True]) -> LayoutContent:
|
||||
...
|
||||
|
||||
def press_right(self, wait: bool = False) -> Optional[LayoutContent]:
|
||||
return self.input(
|
||||
physical_button=messages.DebugPhysicalButton.RIGHT_BTN, wait=wait
|
||||
)
|
||||
|
||||
def press_right_htc(
|
||||
self, hold_ms: int, extra_ms: int = 200
|
||||
) -> Optional[LayoutContent]:
|
||||
hold_ms = hold_ms + extra_ms # safety margin
|
||||
result = self.input(
|
||||
physical_button=messages.DebugPhysicalButton.RIGHT_BTN,
|
||||
hold_ms=hold_ms,
|
||||
)
|
||||
# sleeping little longer for UI to update
|
||||
time.sleep(hold_ms / 1000 + 0.1)
|
||||
return result
|
||||
|
||||
def stop(self) -> None:
|
||||
self._call(messages.DebugLinkStop(), nowait=True)
|
||||
|
||||
@ -626,7 +685,7 @@ class DebugLink:
|
||||
|
||||
def start_recording(self, directory: str) -> None:
|
||||
# Different recording logic between TT and T1
|
||||
if self.model == "T":
|
||||
if self.model in ("T", "R"):
|
||||
self._call(messages.DebugLinkRecordScreen(target_directory=directory))
|
||||
else:
|
||||
self.t1_screenshot_directory = Path(directory)
|
||||
@ -635,7 +694,7 @@ class DebugLink:
|
||||
|
||||
def stop_recording(self) -> None:
|
||||
# Different recording logic between TT and T1
|
||||
if self.model == "T":
|
||||
if self.model in ("T", "R"):
|
||||
self._call(messages.DebugLinkRecordScreen(target_directory=None))
|
||||
else:
|
||||
self.t1_take_screenshots = False
|
||||
|
@ -3725,6 +3725,7 @@ class DebugLinkDecision(protobuf.MessageType):
|
||||
5: protobuf.Field("y", "uint32", repeated=False, required=False, default=None),
|
||||
6: protobuf.Field("wait", "bool", repeated=False, required=False, default=None),
|
||||
7: protobuf.Field("hold_ms", "uint32", repeated=False, required=False, default=None),
|
||||
8: protobuf.Field("physical_button", "DebugPhysicalButton", repeated=False, required=False, default=None),
|
||||
}
|
||||
|
||||
def __init__(
|
||||
@ -3737,6 +3738,7 @@ class DebugLinkDecision(protobuf.MessageType):
|
||||
y: Optional["int"] = None,
|
||||
wait: Optional["bool"] = None,
|
||||
hold_ms: Optional["int"] = None,
|
||||
physical_button: Optional["DebugPhysicalButton"] = None,
|
||||
) -> None:
|
||||
self.button = button
|
||||
self.swipe = swipe
|
||||
@ -3745,6 +3747,7 @@ class DebugLinkDecision(protobuf.MessageType):
|
||||
self.y = y
|
||||
self.wait = wait
|
||||
self.hold_ms = hold_ms
|
||||
self.physical_button = physical_button
|
||||
|
||||
|
||||
class DebugLinkLayout(protobuf.MessageType):
|
||||
|
Loading…
Reference in New Issue
Block a user