mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-05-25 10:18:45 +00:00
refactor(core): drain the BLE event queue whenever layout is running
[no changelog]
This commit is contained in:
parent
11b390c700
commit
fb36b8d19d
@ -381,6 +381,9 @@ class Layout(Generic[T]):
|
|||||||
yield self._handle_input_iface(io.BUTTON, self.layout.button_event)
|
yield self._handle_input_iface(io.BUTTON, self.layout.button_event)
|
||||||
if utils.USE_TOUCH:
|
if utils.USE_TOUCH:
|
||||||
yield self._handle_input_iface(io.TOUCH, self.layout.touch_event)
|
yield self._handle_input_iface(io.TOUCH, self.layout.touch_event)
|
||||||
|
if utils.USE_BLE:
|
||||||
|
# most layouts don't care but we don't want to keep stale events in the queue
|
||||||
|
yield self._handle_ble_events()
|
||||||
|
|
||||||
def _handle_input_iface(
|
def _handle_input_iface(
|
||||||
self, iface: int, event_call: Callable[..., LayoutState | None]
|
self, iface: int, event_call: Callable[..., LayoutState | None]
|
||||||
@ -430,6 +433,26 @@ class Layout(Generic[T]):
|
|||||||
except Exception:
|
except Exception:
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
if utils.USE_BLE:
|
||||||
|
|
||||||
|
async def _handle_ble_events(self) -> None:
|
||||||
|
blecheck = loop.wait(io.BLE_EVENT)
|
||||||
|
try:
|
||||||
|
while True:
|
||||||
|
event = await blecheck
|
||||||
|
if __debug__:
|
||||||
|
import trezorble as ble
|
||||||
|
|
||||||
|
log.debug(
|
||||||
|
__name__,
|
||||||
|
"BLE event: %s, state: %s",
|
||||||
|
event,
|
||||||
|
",".join(ble.connection_flags()),
|
||||||
|
)
|
||||||
|
self._event(self.layout.ble_event, *event)
|
||||||
|
except Shutdown:
|
||||||
|
return
|
||||||
|
|
||||||
def _task_finalizer(self, task: loop.Task, value: Any) -> None:
|
def _task_finalizer(self, task: loop.Task, value: Any) -> None:
|
||||||
if value is None:
|
if value is None:
|
||||||
# all is good
|
# all is good
|
||||||
|
@ -3,7 +3,7 @@ from typing import TYPE_CHECKING
|
|||||||
import storage.cache as storage_cache
|
import storage.cache as storage_cache
|
||||||
import trezorui_api
|
import trezorui_api
|
||||||
from storage.cache_common import APP_COMMON_BUSY_DEADLINE_MS
|
from storage.cache_common import APP_COMMON_BUSY_DEADLINE_MS
|
||||||
from trezor import TR, ui, utils
|
from trezor import TR, ui
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from typing import Any, Callable, Iterator, ParamSpec, TypeVar
|
from typing import Any, Callable, Iterator, ParamSpec, TypeVar
|
||||||
@ -101,21 +101,9 @@ class Homescreen(HomescreenBase):
|
|||||||
event = await usbcheck
|
event = await usbcheck
|
||||||
self._event(self.layout.usb_event, event)
|
self._event(self.layout.usb_event, event)
|
||||||
|
|
||||||
if utils.USE_BLE:
|
|
||||||
|
|
||||||
async def ble_checker_task(self) -> None:
|
|
||||||
from trezor import io, loop
|
|
||||||
|
|
||||||
blecheck = loop.wait(io.BLE_EVENT)
|
|
||||||
while True:
|
|
||||||
event = await blecheck
|
|
||||||
self._event(self.layout.ble_event, *event)
|
|
||||||
|
|
||||||
def create_tasks(self) -> Iterator[loop.Task]:
|
def create_tasks(self) -> Iterator[loop.Task]:
|
||||||
yield from super().create_tasks()
|
yield from super().create_tasks()
|
||||||
yield self.usb_checker_task()
|
yield self.usb_checker_task()
|
||||||
if utils.USE_BLE:
|
|
||||||
yield self.ble_checker_task()
|
|
||||||
|
|
||||||
|
|
||||||
class Lockscreen(HomescreenBase):
|
class Lockscreen(HomescreenBase):
|
||||||
|
Loading…
Reference in New Issue
Block a user