Gitea URL
All checks were successful
ESP32 Build & Release / build (push) Successful in 6m37s

This commit is contained in:
2026-09-12 14:35:09 +02:00
parent 3708674bbb
commit c272776d47
4 changed files with 162 additions and 127 deletions

View File

@@ -114,6 +114,11 @@ static int s_storage_option_idx = 0;
static uint32_t s_btn_held_ms = 0;
static bool s_btn_long_fired = false;
/* OTA progress widgets */
static lv_obj_t *s_ota_bar = NULL;
static lv_obj_t *s_ota_pct_lbl = NULL;
static lv_obj_t *s_ota_bytes_lbl = NULL;
/* Forward declarations */
static void view_menu(void);
static void view_scanner(void);
@@ -175,6 +180,8 @@ static bool load_art_crop(const char *uid)
esp_jpeg_image_cfg_t cfg = {
.indata = jpg_buf,
.indata_size = (uint32_t)fsize,
.outbuf = NULL,
.outbuf_size = 0,
.out_format = JPEG_IMAGE_FORMAT_RGB565,
.out_scale = JPEG_IMAGE_SCALE_0,
.flags = {
@@ -241,6 +248,9 @@ static const char *get_json_str(cJSON *root, const char *key, const char *fallba
static void ui_clean_screen(void)
{
free_art_buffer();
s_ota_bar = NULL;
s_ota_pct_lbl = NULL;
s_ota_bytes_lbl = NULL;
lv_obj_clean(lv_scr_act());
lv_obj_set_style_bg_color(lv_scr_act(), lv_color_black(), 0);
lv_obj_set_style_bg_opa(lv_scr_act(), LV_OPA_COVER, 0);
@@ -1075,6 +1085,17 @@ static void view_device_info(void)
static ota_status_t s_last_ota_rendered_st = OTA_STATUS_IDLE;
static int s_last_ota_percent = -1;
static void update_ota_progress(int percent, size_t rb, size_t tb)
{
lvgl_port_lock(0);
if (s_ota_bar && s_ota_pct_lbl && s_ota_bytes_lbl) {
lv_bar_set_value(s_ota_bar, percent, LV_ANIM_OFF);
lv_label_set_text_fmt(s_ota_pct_lbl, "%d%%", percent);
lv_label_set_text_fmt(s_ota_bytes_lbl, "%d / %d KB", (int)(rb / 1024), (int)(tb / 1024));
}
lvgl_port_unlock();
}
static void view_ota(void)
{
lvgl_port_lock(0);
@@ -1086,6 +1107,7 @@ static void view_ota(void)
ui_draw_header("FIRMWARE UPDATE", "GITEA OTA");
switch (st) {
case OTA_STATUS_IDLE:
case OTA_STATUS_CHECKING: {
lv_obj_t *box = lv_obj_create(lv_scr_act());
lv_obj_set_size(box, DISP_W - 24, 180);
@@ -1236,25 +1258,25 @@ static void view_ota(void)
lv_obj_set_style_text_color(t, lv_color_hex(0x00E5FF), 0);
lv_obj_align(t, LV_ALIGN_TOP_MID, 0, 10);
lv_obj_t *p_lbl = lv_label_create(box);
lv_label_set_text_fmt(p_lbl, "%d%%", percent);
lv_obj_set_style_text_font(p_lbl, &lv_font_montserrat_48, 0);
lv_obj_set_style_text_color(p_lbl, lv_color_hex(0xFFCC00), 0);
lv_obj_align(p_lbl, LV_ALIGN_CENTER, 0, -15);
s_ota_pct_lbl = lv_label_create(box);
lv_label_set_text_fmt(s_ota_pct_lbl, "%d%%", percent);
lv_obj_set_style_text_font(s_ota_pct_lbl, &lv_font_montserrat_48, 0);
lv_obj_set_style_text_color(s_ota_pct_lbl, lv_color_hex(0xFFCC00), 0);
lv_obj_align(s_ota_pct_lbl, LV_ALIGN_CENTER, 0, -15);
lv_obj_t *bar = lv_bar_create(box);
lv_obj_set_size(bar, DISP_W - 60, 14);
lv_obj_align(bar, LV_ALIGN_CENTER, 0, 35);
lv_bar_set_range(bar, 0, 100);
lv_bar_set_value(bar, percent, LV_ANIM_OFF);
lv_obj_set_style_bg_color(bar, lv_color_hex(0x333333), 0);
lv_obj_set_style_bg_color(bar, lv_color_hex(0x00E676), LV_PART_INDICATOR);
s_ota_bar = lv_bar_create(box);
lv_obj_set_size(s_ota_bar, DISP_W - 60, 14);
lv_obj_align(s_ota_bar, LV_ALIGN_CENTER, 0, 35);
lv_bar_set_range(s_ota_bar, 0, 100);
lv_bar_set_value(s_ota_bar, percent, LV_ANIM_OFF);
lv_obj_set_style_bg_color(s_ota_bar, lv_color_hex(0x333333), 0);
lv_obj_set_style_bg_color(s_ota_bar, lv_color_hex(0x00E676), LV_PART_INDICATOR);
lv_obj_t *b_lbl = lv_label_create(box);
lv_label_set_text_fmt(b_lbl, "%d / %d KB", (int)(rb / 1024), (int)(tb / 1024));
lv_obj_set_style_text_font(b_lbl, &lv_font_montserrat_14, 0);
lv_obj_set_style_text_color(b_lbl, lv_color_hex(0xAAAAAA), 0);
lv_obj_align(b_lbl, LV_ALIGN_BOTTOM_MID, 0, -8);
s_ota_bytes_lbl = lv_label_create(box);
lv_label_set_text_fmt(s_ota_bytes_lbl, "%d / %d KB", (int)(rb / 1024), (int)(tb / 1024));
lv_obj_set_style_text_font(s_ota_bytes_lbl, &lv_font_montserrat_14, 0);
lv_obj_set_style_text_color(s_ota_bytes_lbl, lv_color_hex(0xAAAAAA), 0);
lv_obj_align(s_ota_bytes_lbl, LV_ALIGN_BOTTOM_MID, 0, -8);
lv_obj_t *warn = lv_label_create(lv_scr_act());
lv_label_set_text(warn, "DO NOT TURN OFF POWER");
@@ -2015,9 +2037,13 @@ static void ui_task(void *arg)
if (app_get_view() == APP_STATE_OTA_UPDATE) {
ota_status_t cur_ota_st = ota_manager_get_status();
int cur_percent = ota_manager_get_progress();
if (cur_ota_st != s_last_ota_rendered_st ||
(cur_ota_st == OTA_STATUS_DOWNLOADING && cur_percent != s_last_ota_percent)) {
if (cur_ota_st != s_last_ota_rendered_st) {
view_ota();
} else if (cur_ota_st == OTA_STATUS_DOWNLOADING && cur_percent != s_last_ota_percent) {
s_last_ota_percent = cur_percent;
size_t rb = 0, tb = 0;
ota_manager_get_bytes(&rb, &tb);
update_ota_progress(cur_percent, rb, tb);
}
}