mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-18 13:38:12 +00:00
src/trezor: rework PIN progress update
This commit is contained in:
parent
2bb9d80c18
commit
db141fbc14
@ -136,11 +136,23 @@ static secbool pin_check(uint32_t pin, mp_obj_t callback)
|
||||
pin_fails_check_max(ctr);
|
||||
|
||||
// Sleep for ~ctr seconds before checking the PIN.
|
||||
uint32_t progress;
|
||||
for (uint32_t wait = ~ctr; wait > 0; wait--) {
|
||||
for (int i = 0; i < 10; i++) {
|
||||
if (mp_obj_is_callable(callback)) {
|
||||
mp_call_function_2(callback, mp_obj_new_int(wait), mp_obj_new_int(~ctr));
|
||||
if ((~ctr) > 1000000) { // precise enough
|
||||
progress = (~ctr - wait) / ((~ctr) / 1000);
|
||||
} else {
|
||||
progress = ((~ctr - wait) * 10 + i) * 100 / (~ctr);
|
||||
}
|
||||
hal_delay(1000);
|
||||
mp_call_function_2(callback, mp_obj_new_int(wait), mp_obj_new_int(progress));
|
||||
}
|
||||
hal_delay(100);
|
||||
}
|
||||
}
|
||||
// Show last frame if we were waiting
|
||||
if ((~ctr > 0) && mp_obj_is_callable(callback)) {
|
||||
mp_call_function_2(callback, mp_obj_new_int(0), mp_obj_new_int(1000));
|
||||
}
|
||||
|
||||
// First, we increase PIN fail counter in storage, even before checking the
|
||||
|
@ -5,8 +5,12 @@ def pin_to_int(pin: str) -> int:
|
||||
return int('1' + pin)
|
||||
|
||||
|
||||
def show_pin_timeout(wait: int, total: int):
|
||||
def show_pin_timeout(seconds: int, progress: int):
|
||||
if progress == 0:
|
||||
ui.display.bar(0, 0, ui.WIDTH, ui.HEIGHT, ui.BG)
|
||||
ui.display.loader(1000 - (1000 * wait // total), -10, ui.FG, ui.BG)
|
||||
ui.display.text_center(ui.WIDTH // 2, ui.HEIGHT - 20, 'Waiting for %d s' % wait, ui.BOLD, ui.FG, ui.BG)
|
||||
ui.display.loader(progress, -10, ui.FG, ui.BG)
|
||||
if seconds == 0:
|
||||
ui.display.text_center(ui.WIDTH // 2, ui.HEIGHT - 20, 'Done', ui.BOLD, ui.FG, ui.BG, ui.WIDTH)
|
||||
else:
|
||||
ui.display.text_center(ui.WIDTH // 2, ui.HEIGHT - 20, 'Waiting for %d s' % seconds, ui.BOLD, ui.FG, ui.BG, ui.WIDTH)
|
||||
ui.display.refresh()
|
||||
|
Loading…
Reference in New Issue
Block a user