mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-18 21:48:13 +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);
|
pin_fails_check_max(ctr);
|
||||||
|
|
||||||
// Sleep for ~ctr seconds before checking the PIN.
|
// Sleep for ~ctr seconds before checking the PIN.
|
||||||
|
uint32_t progress;
|
||||||
for (uint32_t wait = ~ctr; wait > 0; wait--) {
|
for (uint32_t wait = ~ctr; wait > 0; wait--) {
|
||||||
if (mp_obj_is_callable(callback)) {
|
for (int i = 0; i < 10; i++) {
|
||||||
mp_call_function_2(callback, mp_obj_new_int(wait), mp_obj_new_int(~ctr));
|
if (mp_obj_is_callable(callback)) {
|
||||||
|
if ((~ctr) > 1000000) { // precise enough
|
||||||
|
progress = (~ctr - wait) / ((~ctr) / 1000);
|
||||||
|
} else {
|
||||||
|
progress = ((~ctr - wait) * 10 + i) * 100 / (~ctr);
|
||||||
|
}
|
||||||
|
mp_call_function_2(callback, mp_obj_new_int(wait), mp_obj_new_int(progress));
|
||||||
|
}
|
||||||
|
hal_delay(100);
|
||||||
}
|
}
|
||||||
hal_delay(1000);
|
}
|
||||||
|
// 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
|
// 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)
|
return int('1' + pin)
|
||||||
|
|
||||||
|
|
||||||
def show_pin_timeout(wait: int, total: int):
|
def show_pin_timeout(seconds: int, progress: int):
|
||||||
ui.display.bar(0, 0, ui.WIDTH, ui.HEIGHT, ui.BG)
|
if progress == 0:
|
||||||
ui.display.loader(1000 - (1000 * wait // total), -10, ui.FG, ui.BG)
|
ui.display.bar(0, 0, ui.WIDTH, ui.HEIGHT, 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()
|
ui.display.refresh()
|
||||||
|
Loading…
Reference in New Issue
Block a user