src/trezor: rework PIN progress update

This commit is contained in:
Pavol Rusnak 2018-02-24 21:02:14 +01:00
parent 2bb9d80c18
commit db141fbc14
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D
2 changed files with 23 additions and 7 deletions

View File

@ -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--) {
if (mp_obj_is_callable(callback)) {
mp_call_function_2(callback, mp_obj_new_int(wait), mp_obj_new_int(~ctr));
for (int i = 0; i < 10; i++) {
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

View File

@ -5,8 +5,12 @@ def pin_to_int(pin: str) -> int:
return int('1' + pin)
def show_pin_timeout(wait: int, total: int):
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)
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(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()