1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-17 03:48:09 +00:00

Merge pull request #734 from trezor/andrewkozlik/733

Fix continuous display blinking with Android
This commit is contained in:
Andrew Kozlik 2019-12-04 13:11:03 +01:00 committed by GitHub
commit 9ce8d0a9da
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 3 deletions

View File

@ -215,6 +215,9 @@ _ALLOW_RESIDENT_CREDENTIALS = True
# The attestation type to use in MakeCredential responses. If false, then self attestation will be used.
_USE_BASIC_ATTESTATION = False
# The CID of the last WINK command. Used to ensure that we do only one WINK at a time on any given CID.
_last_wink_cid = 0
class CborError(Exception):
def __init__(self, code: int):
@ -1027,8 +1030,7 @@ def dispatch_cmd(req: Cmd, dialog_mgr: DialogManager) -> Optional[Cmd]:
elif req.cmd == _CMD_WINK:
if __debug__:
log.debug(__name__, "_CMD_WINK")
loop.schedule(ui.alert())
return req
return cmd_wink(req)
elif req.cmd == _CMD_CBOR and _ALLOW_FIDO2:
if not req.data:
return cmd_error(req.cid, _ERR_INVALID_LEN)
@ -1092,6 +1094,14 @@ def cmd_init(req: Cmd) -> Cmd:
return Cmd(req.cid, req.cmd, buf)
def cmd_wink(req: Cmd) -> Cmd:
global _last_wink_cid
if _last_wink_cid != req.cid:
_last_wink_cid = req.cid
ui.alert()
return req
def msg_register(req: Msg, dialog_mgr: DialogManager) -> Cmd:
if not storage.is_initialized():
if __debug__:

View File

@ -34,6 +34,9 @@ VIEWY = const(9)
# channel used to cancel layouts, see `Cancelled` exception
layout_chan = loop.chan()
# allow only one alert at a time to avoid alerts overlapping
_alert_in_progress = False
# in debug mode, display an indicator in top right corner
if __debug__:
@ -78,7 +81,7 @@ def pulse(period: int, offset: int = 0) -> float:
return 0.5 + 0.5 * math.sin(2 * math.pi * (utime.ticks_us() + offset) / period)
async def alert(count: int = 3) -> None:
async def _alert(count: int) -> None:
short_sleep = loop.sleep(20000)
long_sleep = loop.sleep(80000)
for i in range(count * 2):
@ -89,6 +92,17 @@ async def alert(count: int = 3) -> None:
display.backlight(style.BACKLIGHT_DIM)
await long_sleep
display.backlight(style.BACKLIGHT_NORMAL)
global _alert_in_progress
_alert_in_progress = False
def alert(count: int = 3) -> None:
global _alert_in_progress
if _alert_in_progress:
return
_alert_in_progress = True
loop.schedule(_alert(count))
async def click() -> Pos: