mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-08-02 20:08:31 +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,
|
self,
|
||||||
word: Optional[str] = None,
|
word: Optional[str] = None,
|
||||||
button: Optional[messages.DebugButton] = None,
|
button: Optional[messages.DebugButton] = None,
|
||||||
|
physical_button: Optional[messages.DebugPhysicalButton] = None,
|
||||||
swipe: Optional[messages.DebugSwipeDirection] = None,
|
swipe: Optional[messages.DebugSwipeDirection] = None,
|
||||||
x: Optional[int] = None,
|
x: Optional[int] = None,
|
||||||
y: Optional[int] = None,
|
y: Optional[int] = None,
|
||||||
@ -517,14 +518,21 @@ class DebugLink:
|
|||||||
if not self.allow_interactions:
|
if not self.allow_interactions:
|
||||||
return None
|
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:
|
if args != 1:
|
||||||
raise ValueError(
|
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(
|
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)
|
ret = self._call(decision, nowait=not wait)
|
||||||
@ -564,8 +572,8 @@ class DebugLink:
|
|||||||
f.write(screen_content)
|
f.write(screen_content)
|
||||||
f.write("\n" + 80 * "/" + "\n")
|
f.write("\n" + 80 * "/" + "\n")
|
||||||
|
|
||||||
# Type overloads make sure that when we supply `wait=True` into `click()`,
|
# Type overloads below make sure that when we supply `wait=True` into functions,
|
||||||
# it will always return `LayoutContent` and we do not need to assert `is not None`.
|
# they will always return `LayoutContent` and we do not need to assert `is not None`.
|
||||||
|
|
||||||
@overload
|
@overload
|
||||||
def click(self, click: Tuple[int, int]) -> None:
|
def click(self, click: Tuple[int, int]) -> None:
|
||||||
@ -618,6 +626,57 @@ class DebugLink:
|
|||||||
def swipe_left(self, wait: bool = False) -> Union[LayoutContent, None]:
|
def swipe_left(self, wait: bool = False) -> Union[LayoutContent, None]:
|
||||||
return self.input(swipe=messages.DebugSwipeDirection.LEFT, wait=wait)
|
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:
|
def stop(self) -> None:
|
||||||
self._call(messages.DebugLinkStop(), nowait=True)
|
self._call(messages.DebugLinkStop(), nowait=True)
|
||||||
|
|
||||||
@ -626,7 +685,7 @@ class DebugLink:
|
|||||||
|
|
||||||
def start_recording(self, directory: str) -> None:
|
def start_recording(self, directory: str) -> None:
|
||||||
# Different recording logic between TT and T1
|
# Different recording logic between TT and T1
|
||||||
if self.model == "T":
|
if self.model in ("T", "R"):
|
||||||
self._call(messages.DebugLinkRecordScreen(target_directory=directory))
|
self._call(messages.DebugLinkRecordScreen(target_directory=directory))
|
||||||
else:
|
else:
|
||||||
self.t1_screenshot_directory = Path(directory)
|
self.t1_screenshot_directory = Path(directory)
|
||||||
@ -635,7 +694,7 @@ class DebugLink:
|
|||||||
|
|
||||||
def stop_recording(self) -> None:
|
def stop_recording(self) -> None:
|
||||||
# Different recording logic between TT and T1
|
# Different recording logic between TT and T1
|
||||||
if self.model == "T":
|
if self.model in ("T", "R"):
|
||||||
self._call(messages.DebugLinkRecordScreen(target_directory=None))
|
self._call(messages.DebugLinkRecordScreen(target_directory=None))
|
||||||
else:
|
else:
|
||||||
self.t1_take_screenshots = False
|
self.t1_take_screenshots = False
|
||||||
|
@ -3725,6 +3725,7 @@ class DebugLinkDecision(protobuf.MessageType):
|
|||||||
5: protobuf.Field("y", "uint32", repeated=False, required=False, default=None),
|
5: protobuf.Field("y", "uint32", repeated=False, required=False, default=None),
|
||||||
6: protobuf.Field("wait", "bool", 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),
|
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__(
|
def __init__(
|
||||||
@ -3737,6 +3738,7 @@ class DebugLinkDecision(protobuf.MessageType):
|
|||||||
y: Optional["int"] = None,
|
y: Optional["int"] = None,
|
||||||
wait: Optional["bool"] = None,
|
wait: Optional["bool"] = None,
|
||||||
hold_ms: Optional["int"] = None,
|
hold_ms: Optional["int"] = None,
|
||||||
|
physical_button: Optional["DebugPhysicalButton"] = None,
|
||||||
) -> None:
|
) -> None:
|
||||||
self.button = button
|
self.button = button
|
||||||
self.swipe = swipe
|
self.swipe = swipe
|
||||||
@ -3745,6 +3747,7 @@ class DebugLinkDecision(protobuf.MessageType):
|
|||||||
self.y = y
|
self.y = y
|
||||||
self.wait = wait
|
self.wait = wait
|
||||||
self.hold_ms = hold_ms
|
self.hold_ms = hold_ms
|
||||||
|
self.physical_button = physical_button
|
||||||
|
|
||||||
|
|
||||||
class DebugLinkLayout(protobuf.MessageType):
|
class DebugLinkLayout(protobuf.MessageType):
|
||||||
|
Loading…
Reference in New Issue
Block a user