mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-13 19:18:56 +00:00
core: add indeterminate flag to display_loader
This commit is contained in:
parent
c995d9fa59
commit
c761351afa
@ -236,7 +236,7 @@ void ui_screen_install_confirm_newvendor(const vendor_header *const vhdr,
|
||||
|
||||
void ui_screen_install(void) {
|
||||
display_bar(0, 0, DISPLAY_RESX, DISPLAY_RESY, COLOR_WHITE);
|
||||
display_loader(0, -20, COLOR_BL_PROCESS, COLOR_WHITE, toi_icon_install,
|
||||
display_loader(0, false, -20, COLOR_BL_PROCESS, COLOR_WHITE, toi_icon_install,
|
||||
sizeof(toi_icon_install), COLOR_BLACK);
|
||||
display_text_center(DISPLAY_RESX / 2, DISPLAY_RESY - 24,
|
||||
"Installing firmware", -1, FONT_NORMAL, COLOR_BLACK,
|
||||
@ -244,13 +244,13 @@ void ui_screen_install(void) {
|
||||
}
|
||||
|
||||
void ui_screen_install_progress_erase(int pos, int len) {
|
||||
display_loader(250 * pos / len, -20, COLOR_BL_PROCESS, COLOR_WHITE,
|
||||
display_loader(250 * pos / len, false, -20, COLOR_BL_PROCESS, COLOR_WHITE,
|
||||
toi_icon_install, sizeof(toi_icon_install), COLOR_BLACK);
|
||||
}
|
||||
|
||||
void ui_screen_install_progress_upload(int pos) {
|
||||
display_loader(pos, -20, COLOR_BL_PROCESS, COLOR_WHITE, toi_icon_install,
|
||||
sizeof(toi_icon_install), COLOR_BLACK);
|
||||
display_loader(pos, false, -20, COLOR_BL_PROCESS, COLOR_WHITE,
|
||||
toi_icon_install, sizeof(toi_icon_install), COLOR_BLACK);
|
||||
}
|
||||
|
||||
// wipe UI
|
||||
@ -274,14 +274,14 @@ void ui_screen_wipe_confirm(void) {
|
||||
|
||||
void ui_screen_wipe(void) {
|
||||
display_bar(0, 0, DISPLAY_RESX, DISPLAY_RESY, COLOR_WHITE);
|
||||
display_loader(0, -20, COLOR_BL_PROCESS, COLOR_WHITE, toi_icon_wipe,
|
||||
display_loader(0, false, -20, COLOR_BL_PROCESS, COLOR_WHITE, toi_icon_wipe,
|
||||
sizeof(toi_icon_wipe), COLOR_BLACK);
|
||||
display_text_center(DISPLAY_RESX / 2, DISPLAY_RESY - 24, "Wiping device", -1,
|
||||
FONT_NORMAL, COLOR_BLACK, COLOR_WHITE);
|
||||
}
|
||||
|
||||
void ui_screen_wipe_progress(int pos, int len) {
|
||||
display_loader(1000 * pos / len, -20, COLOR_BL_PROCESS, COLOR_WHITE,
|
||||
display_loader(1000 * pos / len, false, -20, COLOR_BL_PROCESS, COLOR_WHITE,
|
||||
toi_icon_wipe, sizeof(toi_icon_wipe), COLOR_BLACK);
|
||||
}
|
||||
|
||||
@ -300,7 +300,7 @@ void ui_screen_done(int restart_seconds, secbool full_redraw) {
|
||||
if (sectrue == full_redraw) {
|
||||
display_bar(0, 0, DISPLAY_RESX, DISPLAY_RESY, COLOR_WHITE);
|
||||
}
|
||||
display_loader(1000, -20, COLOR_BL_DONE, COLOR_WHITE, toi_icon_done,
|
||||
display_loader(1000, false, -20, COLOR_BL_DONE, COLOR_WHITE, toi_icon_done,
|
||||
sizeof(toi_icon_done), COLOR_BLACK);
|
||||
if (secfalse == full_redraw) {
|
||||
display_bar(0, DISPLAY_RESY - 24 - 18, 240, 23, COLOR_WHITE);
|
||||
@ -313,7 +313,7 @@ void ui_screen_done(int restart_seconds, secbool full_redraw) {
|
||||
|
||||
void ui_screen_fail(void) {
|
||||
display_bar(0, 0, DISPLAY_RESX, DISPLAY_RESY, COLOR_WHITE);
|
||||
display_loader(1000, -20, COLOR_BL_FAIL, COLOR_WHITE, toi_icon_fail,
|
||||
display_loader(1000, false, -20, COLOR_BL_FAIL, COLOR_WHITE, toi_icon_fail,
|
||||
sizeof(toi_icon_fail), COLOR_BLACK);
|
||||
display_text_center(DISPLAY_RESX / 2, DISPLAY_RESY - 24,
|
||||
"Failed! Please, reconnect.", -1, FONT_NORMAL,
|
||||
|
@ -316,9 +316,9 @@ static void inflate_callback_loader(uint8_t byte, uint32_t pos,
|
||||
|
||||
#endif
|
||||
|
||||
void display_loader(uint16_t progress, int yoffset, uint16_t fgcolor,
|
||||
uint16_t bgcolor, const uint8_t *icon, uint32_t iconlen,
|
||||
uint16_t iconfgcolor) {
|
||||
void display_loader(uint16_t progress, bool indeterminate, int yoffset,
|
||||
uint16_t fgcolor, uint16_t bgcolor, const uint8_t *icon,
|
||||
uint32_t iconlen, uint16_t iconfgcolor) {
|
||||
#if TREZOR_MODEL == T
|
||||
uint16_t colortable[16], iconcolortable[16];
|
||||
set_color_table(colortable, fgcolor, bgcolor);
|
||||
@ -362,6 +362,7 @@ void display_loader(uint16_t progress, int yoffset, uint16_t fgcolor,
|
||||
}
|
||||
// inside of circle - draw glyph
|
||||
#define LOADER_ICON_CORNER_CUT 2
|
||||
#define LOADER_INDETERMINATE_WIDTH 125
|
||||
if (icon &&
|
||||
mx + my > (((LOADER_ICON_SIZE / 2) + LOADER_ICON_CORNER_CUT) * 2) &&
|
||||
mx >= img_loader_size - (LOADER_ICON_SIZE / 2) &&
|
||||
@ -378,10 +379,19 @@ void display_loader(uint16_t progress, int yoffset, uint16_t fgcolor,
|
||||
PIXELDATA(iconcolortable[c]);
|
||||
} else {
|
||||
uint8_t c;
|
||||
if (progress > a) {
|
||||
c = (img_loader[my][mx] & 0x00F0) >> 4;
|
||||
if (indeterminate) {
|
||||
uint16_t diff = (progress > a) ? (progress - a) : (a - progress);
|
||||
if (diff < LOADER_INDETERMINATE_WIDTH) {
|
||||
c = (img_loader[my][mx] & 0x00F0) >> 4;
|
||||
} else {
|
||||
c = img_loader[my][mx] & 0x000F;
|
||||
}
|
||||
} else {
|
||||
c = img_loader[my][mx] & 0x000F;
|
||||
if (progress > a) {
|
||||
c = (img_loader[my][mx] & 0x00F0) >> 4;
|
||||
} else {
|
||||
c = img_loader[my][mx] & 0x000F;
|
||||
}
|
||||
}
|
||||
PIXELDATA(colortable[c]);
|
||||
}
|
||||
|
@ -21,6 +21,7 @@
|
||||
#define __DISPLAY_H__
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#if TREZOR_MODEL == T
|
||||
|
||||
@ -82,9 +83,9 @@ void display_avatar(int x, int y, const void *data, int datalen,
|
||||
uint16_t fgcolor, uint16_t bgcolor);
|
||||
void display_icon(int x, int y, int w, int h, const void *data, int datalen,
|
||||
uint16_t fgcolor, uint16_t bgcolor);
|
||||
void display_loader(uint16_t progress, int yoffset, uint16_t fgcolor,
|
||||
uint16_t bgcolor, const uint8_t *icon, uint32_t iconlen,
|
||||
uint16_t iconfgcolor);
|
||||
void display_loader(uint16_t progress, bool indeterminate, int yoffset,
|
||||
uint16_t fgcolor, uint16_t bgcolor, const uint8_t *icon,
|
||||
uint32_t iconlen, uint16_t iconfgcolor);
|
||||
|
||||
#ifndef TREZOR_PRINT_DISABLE
|
||||
void display_print_color(uint16_t fgcolor, uint16_t bgcolor);
|
||||
|
@ -197,8 +197,8 @@ STATIC mp_obj_t mod_trezorui_Display_icon(size_t n_args, const mp_obj_t *args) {
|
||||
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorui_Display_icon_obj, 6, 6,
|
||||
mod_trezorui_Display_icon);
|
||||
/// def loader(self, progress: int, yoffset: int, fgcolor: int, bgcolor: int,
|
||||
/// icon: bytes = None, iconfgcolor: int = None) -> None:
|
||||
/// def loader(self, progress: int, indeterminate: bool, yoffset: int, fgcolor:
|
||||
/// int, bgcolor: int, icon: bytes = None, iconfgcolor: int = None) -> None:
|
||||
/// '''
|
||||
/// Renders a rotating loader graphic.
|
||||
/// Progress determines its position (0-1000), fgcolor is used as foreground
|
||||
@ -210,12 +210,13 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorui_Display_icon_obj, 6, 6,
|
||||
STATIC mp_obj_t mod_trezorui_Display_loader(size_t n_args,
|
||||
const mp_obj_t *args) {
|
||||
mp_int_t progress = mp_obj_get_int(args[1]);
|
||||
mp_int_t yoffset = mp_obj_get_int(args[2]);
|
||||
mp_int_t fgcolor = mp_obj_get_int(args[3]);
|
||||
mp_int_t bgcolor = mp_obj_get_int(args[4]);
|
||||
if (n_args > 5) { // icon provided
|
||||
bool indeterminate = args[2] == mp_const_true;
|
||||
mp_int_t yoffset = mp_obj_get_int(args[3]);
|
||||
mp_int_t fgcolor = mp_obj_get_int(args[4]);
|
||||
mp_int_t bgcolor = mp_obj_get_int(args[5]);
|
||||
if (n_args > 6) { // icon provided
|
||||
mp_buffer_info_t icon;
|
||||
mp_get_buffer_raise(args[5], &icon, MP_BUFFER_READ);
|
||||
mp_get_buffer_raise(args[6], &icon, MP_BUFFER_READ);
|
||||
const uint8_t *data = icon.buf;
|
||||
if (icon.len < 8 || memcmp(data, "TOIg", 4) != 0) {
|
||||
mp_raise_ValueError("Invalid image format");
|
||||
@ -230,20 +231,21 @@ STATIC mp_obj_t mod_trezorui_Display_loader(size_t n_args,
|
||||
mp_raise_ValueError("Invalid size of data");
|
||||
}
|
||||
uint16_t iconfgcolor;
|
||||
if (n_args > 6) { // icon color provided
|
||||
iconfgcolor = mp_obj_get_int(args[6]);
|
||||
if (n_args > 7) { // icon color provided
|
||||
iconfgcolor = mp_obj_get_int(args[7]);
|
||||
} else {
|
||||
iconfgcolor = ~bgcolor; // invert
|
||||
}
|
||||
display_loader(progress, yoffset, fgcolor, bgcolor, icon.buf, icon.len,
|
||||
iconfgcolor);
|
||||
display_loader(progress, indeterminate, yoffset, fgcolor, bgcolor, icon.buf,
|
||||
icon.len, iconfgcolor);
|
||||
} else {
|
||||
display_loader(progress, yoffset, fgcolor, bgcolor, NULL, 0, 0);
|
||||
display_loader(progress, indeterminate, yoffset, fgcolor, bgcolor, NULL, 0,
|
||||
0);
|
||||
}
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorui_Display_loader_obj, 5,
|
||||
7, mod_trezorui_Display_loader);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorui_Display_loader_obj, 6,
|
||||
8, mod_trezorui_Display_loader);
|
||||
|
||||
/// def print(self, text: str) -> None:
|
||||
/// '''
|
||||
|
@ -24,5 +24,5 @@ def report_init(text):
|
||||
|
||||
|
||||
def report():
|
||||
p = int(1000 * _progress / _steps)
|
||||
ui.display.loader(p, 18, ui.WHITE, ui.BG)
|
||||
p = 1000 * _progress // _steps
|
||||
ui.display.loader(p, False, 18, ui.WHITE, ui.BG)
|
||||
|
@ -44,6 +44,6 @@ def _start_progress():
|
||||
|
||||
|
||||
def _render_progress(progress: int, total: int):
|
||||
p = int(1000 * progress / total)
|
||||
ui.display.loader(p, 18, ui.WHITE, ui.BG)
|
||||
p = 1000 * progress // total
|
||||
ui.display.loader(p, False, 18, ui.WHITE, ui.BG)
|
||||
ui.display.refresh()
|
||||
|
@ -144,8 +144,8 @@ async def transaction_step(state, step, sub_step=None):
|
||||
text = Text("Signing transaction", ui.ICON_SEND, icon_color=ui.BLUE)
|
||||
text.render()
|
||||
|
||||
p = int(1000.0 * state.progress_cur / state.progress_total)
|
||||
ui.display.loader(p, -4, ui.WHITE, ui.BG)
|
||||
p = 1000 * state.progress_cur // state.progress_total
|
||||
ui.display.loader(p, False, -4, ui.WHITE, ui.BG)
|
||||
ui.display.text_center(ui.WIDTH // 2, 210, info[0], ui.NORMAL, ui.FG, ui.BG)
|
||||
if len(info) > 1:
|
||||
ui.display.text_center(ui.WIDTH // 2, 235, info[1], ui.NORMAL, ui.FG, ui.BG)
|
||||
@ -160,8 +160,8 @@ async def keyimage_sync_step(ctx, current, total_num):
|
||||
text = Text("Syncing", ui.ICON_SEND, icon_color=ui.BLUE)
|
||||
text.render()
|
||||
|
||||
p = (int(1000.0 * (current + 1) / total_num)) if total_num > 0 else 0
|
||||
ui.display.loader(p, 18, ui.WHITE, ui.BG)
|
||||
p = (1000 * (current + 1) // total_num) if total_num > 0 else 0
|
||||
ui.display.loader(p, False, 18, ui.WHITE, ui.BG)
|
||||
ui.display.refresh()
|
||||
|
||||
|
||||
@ -173,11 +173,9 @@ async def live_refresh_step(ctx, current):
|
||||
text = Text("Refreshing", ui.ICON_SEND, icon_color=ui.BLUE)
|
||||
text.render()
|
||||
|
||||
step = 6
|
||||
p = int(1000.0 * (current / step)) % 1000
|
||||
if p == 0 and current > 0:
|
||||
p = 1000
|
||||
step = 8
|
||||
p = (1000 * current // step) % 1000
|
||||
|
||||
ui.display.loader(p, 18, ui.WHITE, ui.BG, None, 0, 1000 // step)
|
||||
ui.display.loader(p, True, 18, ui.WHITE, ui.BG, None, 0)
|
||||
ui.display.text_center(ui.WIDTH // 2, 145, "%d" % current, ui.NORMAL, ui.FG, ui.BG)
|
||||
ui.display.refresh()
|
||||
|
@ -24,5 +24,5 @@ def report_init():
|
||||
|
||||
|
||||
def report():
|
||||
p = int(1000 * _progress / _steps)
|
||||
ui.display.loader(p, 18, ui.WHITE, ui.BG)
|
||||
p = 1000 * _progress // _steps
|
||||
ui.display.loader(p, False, 18, ui.WHITE, ui.BG)
|
||||
|
@ -18,7 +18,7 @@ def show_pin_timeout(seconds: int, progress: int, message: str) -> bool:
|
||||
ui.display.text_center(
|
||||
ui.WIDTH // 2, 37, message, ui.BOLD, ui.FG, ui.BG, ui.WIDTH
|
||||
)
|
||||
ui.display.loader(progress, 0, ui.FG, ui.BG)
|
||||
ui.display.loader(progress, False, 0, ui.FG, ui.BG)
|
||||
if seconds == 0:
|
||||
ui.display.text_center(
|
||||
ui.WIDTH // 2, ui.HEIGHT - 22, "Done", ui.BOLD, ui.FG, ui.BG, ui.WIDTH
|
||||
|
@ -47,12 +47,15 @@ class Loader(ui.Widget):
|
||||
else:
|
||||
s = self.normal_style
|
||||
if s["icon"] is None:
|
||||
ui.display.loader(r, -24, s["fg-color"], s["bg-color"])
|
||||
ui.display.loader(r, False, -24, s["fg-color"], s["bg-color"])
|
||||
elif s["icon-fg-color"] is None:
|
||||
ui.display.loader(r, -24, s["fg-color"], s["bg-color"], res.load(s["icon"]))
|
||||
ui.display.loader(
|
||||
r, False, -24, s["fg-color"], s["bg-color"], res.load(s["icon"])
|
||||
)
|
||||
else:
|
||||
ui.display.loader(
|
||||
r,
|
||||
False,
|
||||
-24,
|
||||
s["fg-color"],
|
||||
s["bg-color"],
|
||||
|
Loading…
Reference in New Issue
Block a user