OTA: screen stays on with a progress bar and 'do not switch off' (flash writes no longer blank the panel under XIP); wiki step 4

This commit is contained in:
2026-09-27 18:00:33 +02:00
parent 26e61190f9
commit 990ba68590
7 changed files with 174 additions and 16 deletions
+72 -10
View File
@@ -40,6 +40,8 @@ extern "C" bool verifyRollbackLater() { return true; }
namespace Ota {
static void setNoticeProgress(int pct); // defined with the full-screen notice below
#define OTA_CONFIRM_S 30 // healthy uptime before a new image is kept
#define TOSTR_(x) #x
#define TOSTR(x) TOSTR_(x)
@@ -382,7 +384,9 @@ static bool writeImage(const manifest_t& m, const esp_partition_t* part) {
err = esp_ota_write(h, buf, r);
if (err != ESP_OK) { print("[ota] flash write: %s", esp_err_to_name(err)); ok = false; break; }
got += r;
int decile = (int)((uint64_t)got * 10 / m.size);
int pct = (int)((uint64_t)got * 100 / m.size);
setNoticeProgress(pct);
int decile = pct / 10;
if (decile != last_decile) { print("[ota] %d%%", decile * 10); last_decile = decile; }
}
http.end();
@@ -407,10 +411,18 @@ static bool writeImage(const manifest_t& m, const esp_partition_t* part) {
}
// ---- Full-screen notice on lv_layer_top() (above every screen) ----------------
// Since the core runs with XIP from PSRAM and an IRAM-safe RGB refill ISR
// (2026-09-27), flash writes no longer blank the panel, so the screen stays ON
// during the download and shows a progress bar. The user must see that the
// update is alive; a dark screen invited switching the ignition off mid-write.
static lv_obj_t* g_notice = NULL;
static lv_obj_t* g_notice_lbl = NULL;
static lv_obj_t* g_notice_bar = NULL;
static lv_obj_t* g_notice_pct = NULL;
static lv_obj_t* g_notice_warn = NULL;
static int g_notice_last_pct = -1;
static void showNotice(const char* text) {
static void showNotice(const char* text, bool with_progress = false) {
lvgl_port_lock(-1);
if (g_notice == NULL) {
g_notice = lv_obj_create(lv_layer_top());
@@ -419,17 +431,69 @@ static void showNotice(const char* text) {
lv_obj_set_style_bg_color(g_notice, lv_color_black(), 0);
lv_obj_set_style_bg_opa(g_notice, LV_OPA_COVER, 0);
lv_obj_add_flag(g_notice, LV_OBJ_FLAG_CLICKABLE); // swallow touches while shown
g_notice_lbl = lv_label_create(g_notice);
lv_obj_set_style_text_font(g_notice_lbl, &lv_font_montserrat_30, 0);
lv_obj_set_style_text_color(g_notice_lbl, lv_color_white(), 0);
lv_obj_set_style_text_align(g_notice_lbl, LV_TEXT_ALIGN_CENTER, 0);
lv_obj_center(g_notice_lbl);
lv_obj_align(g_notice_lbl, LV_ALIGN_CENTER, 0, -90);
g_notice_bar = lv_bar_create(g_notice);
lv_obj_set_size(g_notice_bar, 640, 28);
lv_obj_align(g_notice_bar, LV_ALIGN_CENTER, 0, 10);
lv_bar_set_range(g_notice_bar, 0, 100);
lv_bar_set_value(g_notice_bar, 0, LV_ANIM_OFF);
lv_obj_set_style_bg_color(g_notice_bar, lv_color_hex(0x252D36), LV_PART_MAIN);
lv_obj_set_style_bg_opa(g_notice_bar, LV_OPA_COVER, LV_PART_MAIN);
lv_obj_set_style_radius(g_notice_bar, 14, LV_PART_MAIN);
lv_obj_set_style_bg_color(g_notice_bar, lv_color_hex(0x3DA9FC), LV_PART_INDICATOR);
lv_obj_set_style_bg_opa(g_notice_bar, LV_OPA_COVER, LV_PART_INDICATOR);
lv_obj_set_style_radius(g_notice_bar, 14, LV_PART_INDICATOR);
g_notice_pct = lv_label_create(g_notice);
lv_obj_set_style_text_font(g_notice_pct, &lv_font_montserrat_24, 0);
lv_obj_set_style_text_color(g_notice_pct, lv_color_white(), 0);
lv_label_set_text(g_notice_pct, "0%");
lv_obj_align_to(g_notice_pct, g_notice_bar, LV_ALIGN_OUT_BOTTOM_MID, 0, 12);
g_notice_warn = lv_label_create(g_notice);
lv_obj_set_style_text_font(g_notice_warn, &lv_font_montserrat_24, 0);
lv_obj_set_style_text_color(g_notice_warn, lv_color_hex(0xF5A524), 0);
lv_obj_set_style_text_align(g_notice_warn, LV_TEXT_ALIGN_CENTER, 0);
lv_label_set_text(g_notice_warn, LV_SYMBOL_WARNING " Do not switch off the ignition");
lv_obj_align(g_notice_warn, LV_ALIGN_CENTER, 0, 130);
}
lv_label_set_text(g_notice_lbl, text);
if (with_progress) {
lv_bar_set_value(g_notice_bar, 0, LV_ANIM_OFF);
lv_label_set_text(g_notice_pct, "0%");
lv_obj_clear_flag(g_notice_bar, LV_OBJ_FLAG_HIDDEN);
lv_obj_clear_flag(g_notice_pct, LV_OBJ_FLAG_HIDDEN);
lv_obj_clear_flag(g_notice_warn, LV_OBJ_FLAG_HIDDEN);
} else {
lv_obj_add_flag(g_notice_bar, LV_OBJ_FLAG_HIDDEN);
lv_obj_add_flag(g_notice_pct, LV_OBJ_FLAG_HIDDEN);
lv_obj_add_flag(g_notice_warn, LV_OBJ_FLAG_HIDDEN);
}
g_notice_last_pct = -1;
lv_obj_clear_flag(g_notice, LV_OBJ_FLAG_HIDDEN);
lvgl_port_unlock();
}
/** Progress bar update from the download loop (loop task). Cheap: one bar + label. */
static void setNoticeProgress(int pct) {
if (pct < 0) pct = 0;
if (pct > 100) pct = 100;
if (pct == g_notice_last_pct || g_notice_bar == NULL) return;
g_notice_last_pct = pct;
char t[8];
snprintf(t, sizeof(t), "%d%%", pct);
if (!lvgl_port_lock(50)) return; // never stall the download on the UI lock
lv_bar_set_value(g_notice_bar, pct, LV_ANIM_OFF);
lv_label_set_text(g_notice_pct, t);
lvgl_port_unlock();
}
static void hideNotice() {
lvgl_port_lock(-1);
if (g_notice) lv_obj_add_flag(g_notice, LV_OBJ_FLAG_HIDDEN);
@@ -457,15 +521,13 @@ static void install(bool force) {
print("[ota] installing %s -> %s (%lu bytes)", m.version, part->label, (unsigned long)m.size);
// Flash writes stall the PSRAM-fed RGB panel (flicker), so the screen is
// dark while the image is written, with a notice before and after.
// The screen stays on: with XIP from PSRAM + an IRAM-safe RGB refill ISR the
// flash writes no longer starve the panel (verified 2026-09-27: 24 frames/s
// for the whole download). The bar is driven from the download loop.
char msg[160];
snprintf(msg, sizeof(msg), "Updating to %s\n\nThe screen goes dark for about a minute.\nDo not switch off.", m.version);
showNotice(msg);
delay(3000); // time to read it; LVGL renders on its own task
DisplayInit::setBacklight(false);
snprintf(msg, sizeof(msg), "Updating to %s", m.version);
showNotice(msg, true);
bool ok = writeImage(m, part);
DisplayInit::setBacklight(true);
// The download took a while - the driver may have started the engine since.
if (ok && !gate(false)) {
+3 -3
View File
@@ -528,9 +528,9 @@ static void onInstall(lv_event_t* e) {
char title[64];
snprintf(title, sizeof(title), "Install %s?", o.latest);
confirm(title,
"The screen goes dark for about a minute while the new firmware is written, "
"A progress bar shows while the new firmware downloads (about a minute), "
"then Controller A restarts. Controller B's gauges drop out for a few seconds.\n\n"
"Only while parked with the engine off.",
"Do not switch off the ignition until it has restarted. Only while parked with the engine off.",
"Install", onInstallConfirmed, NULL);
}
@@ -623,7 +623,7 @@ static void buildUpdatesPage(lv_obj_t* page) {
lv_obj_t* note = label(page,
"Updates come from " OTA_SERVER " and are signed. Installing takes about a minute: "
"the screen goes dark while the new firmware is written, then the controller restarts. "
"a progress bar shows while the new firmware is written, then the controller restarts. "
"If it doesn't start properly, it goes back to the current version by itself.",
&lv_font_montserrat_20, UI_COL_MUTED);
lv_label_set_long_mode(note, LV_LABEL_LONG_WRAP);