1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-26 17:38:39 +00:00

TT ble handling

This commit is contained in:
tychovrahe 2024-10-03 12:25:22 +02:00
parent 90765e6fae
commit 70465eb084
4 changed files with 20 additions and 0 deletions

View File

@ -1682,6 +1682,9 @@ pub static mp_module_trezorui2: Module = obj_module! {
/// def usb_event(self, connected: bool) -> T | None:
/// """Receive a USB connect/disconnect event."""
///
/// def ble_event(self, event: int, data: bytes) -> T | None:
/// """Receive a BLE events."""
///
/// def timer(self, token: int) -> T | None:
/// """Callback for the timer set by `attach_timer_fn`.
///

View File

@ -1148,6 +1148,8 @@ class LayoutObj(Generic[T]):
"""Receive a progress event."""
def usb_event(self, connected: bool) -> T | None:
"""Receive a USB connect/disconnect event."""
def ble_event(self, event: int, data: bytes) -> T | None:
"""Receive a BLE events."""
def timer(self, token: int) -> T | None:
"""Callback for the timer set by `attach_timer_fn`.
This function should be called by the executor after the corresponding

View File

@ -77,6 +77,7 @@ class RustLayout(LayoutParentType[T]):
self.handle_click_signal(),
self.handle_result_signal(),
self.handle_usb(context.get_context()),
self.handle_ble_events(),
)
else:
return (
@ -85,6 +86,7 @@ class RustLayout(LayoutParentType[T]):
self.handle_swipe(),
self.handle_click_signal(),
self.handle_result_signal(),
self.handle_ble_events(),
)
async def handle_result_signal(self) -> None:
@ -189,11 +191,13 @@ class RustLayout(LayoutParentType[T]):
self.handle_input_and_rendering(),
self.handle_timers(),
self.handle_usb(context.get_context()),
self.handle_ble_events(),
)
else:
return (
self.handle_input_and_rendering(),
self.handle_timers(),
self.handle_ble_events(),
)
def _first_paint(self) -> None:
@ -244,6 +248,16 @@ class RustLayout(LayoutParentType[T]):
raise ui.Result(msg)
self._paint()
def handle_ble_events(self) -> loop.Task:
input = loop.wait(io.BLE_CHECK)
while True:
# Using `yield` instead of `await` to avoid allocations.
(event, data) = yield input
msg = self.layout.ble_event(event, data)
if msg is not None:
raise ui.Result(msg)
self._paint()
def handle_timers(self) -> loop.Task:
while True:
# Using `yield` instead of `await` to avoid allocations.

View File

@ -36,6 +36,7 @@ class HomescreenBase(RustLayout):
self.handle_input_and_rendering(),
self.handle_timers(),
self.handle_click_signal(), # so we can receive debug events
self.handle_ble_events(),
)