Display quick fixes: instant screen switches, deferred NVS saves, dark OTA writes, version label
Firmware / build (push) Successful in 4m30s
Firmware / build (push) Successful in 4m30s
- screen switches use LV_SCR_LOAD_ANIM_NONE: full-screen fades were re-rendered and blended in software every frame and stuttered at 1024x600 - Tunables: NVS write 3 s after the last change or on leaving the Tuning screen (Tunables::flush()), not per tap - each flash write flickers the RGB panel - OTA: backlight off while the image is written, with full-screen notices before and after; tunables flushed before any reboot - firmware version shown bottom-right on every screen (lv_layer_top) - docs: CLAUDE.md, wiki ota-updates, open-questions #13, log Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+95
-31
@@ -17,6 +17,10 @@
|
||||
#include "drivers/can_driver.h"
|
||||
#include "protocol/automotive_data.h"
|
||||
#include "config/ota_config.h"
|
||||
#include "modules/display_init.h"
|
||||
#include "modules/tunables.h"
|
||||
#include "display/lvgl_v8_port.h"
|
||||
#include <lvgl.h>
|
||||
|
||||
#include <WiFi.h>
|
||||
#include <WiFiClientSecure.h>
|
||||
@@ -277,45 +281,27 @@ static bool verifySignature(const manifest_t& m) {
|
||||
// Install
|
||||
// ============================================================================
|
||||
|
||||
static void install(bool force) {
|
||||
manifest_t m;
|
||||
if (!fetchManifest(m) || !verifySignature(m)) return;
|
||||
|
||||
if (!force && strcmp(m.version, FW_VERSION) == 0) {
|
||||
print("[ota] already running %s - nothing to do (`ota install force` to reinstall)", FW_VERSION);
|
||||
return;
|
||||
}
|
||||
|
||||
const esp_partition_t* part = esp_ota_get_next_update_partition(NULL);
|
||||
if (!part) { print("[ota] no idle OTA slot (partition table?)"); return; }
|
||||
if (m.size > part->size) {
|
||||
print("[ota] image %lu B does not fit slot %s (%lu B)",
|
||||
(unsigned long)m.size, part->label, (unsigned long)part->size);
|
||||
return;
|
||||
}
|
||||
|
||||
print("[ota] installing %s -> %s (%lu bytes). Screen may flicker while flash is written.",
|
||||
m.version, part->label, (unsigned long)m.size);
|
||||
|
||||
/** Download firmware.bin into the idle slot, hashing as it streams; true if it matches the signed manifest. */
|
||||
static bool writeImage(const manifest_t& m, const esp_partition_t* part) {
|
||||
String url = String(OTA_DOWNLOAD_BASE) + m.tag + "/firmware.bin";
|
||||
WiFiClientSecure client;
|
||||
client.setCACert(OTA_CA_PEM);
|
||||
HTTPClient http;
|
||||
http.setConnectTimeout(10000);
|
||||
http.setTimeout(15000);
|
||||
if (!http.begin(client, url)) { print("[ota] bad download URL"); return; }
|
||||
if (!http.begin(client, url)) { print("[ota] bad download URL"); return false; }
|
||||
http.setUserAgent("patrol-a-ota/" FW_VERSION);
|
||||
int code = http.GET();
|
||||
if (code != HTTP_CODE_OK) { print("[ota] download failed (HTTP %d)", code); http.end(); return; }
|
||||
if (code != HTTP_CODE_OK) { print("[ota] download failed (HTTP %d)", code); http.end(); return false; }
|
||||
if (http.getSize() != (int)m.size) {
|
||||
print("[ota] server size %d != manifest size %lu", http.getSize(), (unsigned long)m.size);
|
||||
http.end();
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
esp_ota_handle_t h = 0;
|
||||
esp_err_t err = esp_ota_begin(part, OTA_WITH_SEQUENTIAL_WRITES, &h);
|
||||
if (err != ESP_OK) { print("[ota] esp_ota_begin: %s", esp_err_to_name(err)); http.end(); return; }
|
||||
if (err != ESP_OK) { print("[ota] esp_ota_begin: %s", esp_err_to_name(err)); http.end(); return false; }
|
||||
|
||||
uint8_t* buf = (uint8_t*)malloc(CHUNK);
|
||||
mbedtls_sha256_context sc;
|
||||
@@ -361,19 +347,95 @@ static void install(bool force) {
|
||||
print("[ota] SHA-256 MISMATCH - image does not match the signed manifest");
|
||||
ok = false;
|
||||
}
|
||||
if (!ok) { esp_ota_abort(h); print("[ota] aborted; still running %s", FW_VERSION); return; }
|
||||
if (!ok) { esp_ota_abort(h); print("[ota] aborted; still running %s", FW_VERSION); return false; }
|
||||
|
||||
err = esp_ota_end(h); // validates the image structure + its embedded hash
|
||||
if (err != ESP_OK) { print("[ota] image check failed: %s", esp_err_to_name(err)); return; }
|
||||
if (err != ESP_OK) { print("[ota] image check failed: %s", esp_err_to_name(err)); return false; }
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
// ---- Full-screen notice on lv_layer_top() (above every screen) ----------------
|
||||
static lv_obj_t* g_notice = NULL;
|
||||
static lv_obj_t* g_notice_lbl = NULL;
|
||||
|
||||
static void showNotice(const char* text) {
|
||||
lvgl_port_lock(-1);
|
||||
if (g_notice == NULL) {
|
||||
g_notice = lv_obj_create(lv_layer_top());
|
||||
lv_obj_remove_style_all(g_notice);
|
||||
lv_obj_set_size(g_notice, LV_PCT(100), LV_PCT(100));
|
||||
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_label_set_text(g_notice_lbl, text);
|
||||
lv_obj_clear_flag(g_notice, LV_OBJ_FLAG_HIDDEN);
|
||||
lvgl_port_unlock();
|
||||
}
|
||||
|
||||
static void hideNotice() {
|
||||
lvgl_port_lock(-1);
|
||||
if (g_notice) lv_obj_add_flag(g_notice, LV_OBJ_FLAG_HIDDEN);
|
||||
lvgl_port_unlock();
|
||||
}
|
||||
|
||||
static void install(bool force) {
|
||||
manifest_t m;
|
||||
if (!fetchManifest(m) || !verifySignature(m)) return;
|
||||
|
||||
if (!force && strcmp(m.version, FW_VERSION) == 0) {
|
||||
print("[ota] already running %s - nothing to do (`ota install force` to reinstall)", FW_VERSION);
|
||||
return;
|
||||
}
|
||||
|
||||
const esp_partition_t* part = esp_ota_get_next_update_partition(NULL);
|
||||
if (!part) { print("[ota] no idle OTA slot (partition table?)"); return; }
|
||||
if (m.size > part->size) {
|
||||
print("[ota] image %lu B does not fit slot %s (%lu B)",
|
||||
(unsigned long)m.size, part->label, (unsigned long)part->size);
|
||||
return;
|
||||
}
|
||||
|
||||
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.
|
||||
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);
|
||||
bool ok = writeImage(m, part);
|
||||
DisplayInit::setBacklight(true);
|
||||
|
||||
// The download took a while - the driver may have started the engine since.
|
||||
if (!gate(false)) { print("[ota] new image left inactive in %s; retry when parked", part->label); return; }
|
||||
|
||||
err = esp_ota_set_boot_partition(part);
|
||||
if (err != ESP_OK) { print("[ota] set boot slot: %s", esp_err_to_name(err)); return; }
|
||||
if (ok && !gate(false)) {
|
||||
print("[ota] new image left inactive in %s; retry when parked", part->label);
|
||||
ok = false;
|
||||
}
|
||||
if (ok) {
|
||||
esp_err_t err = esp_ota_set_boot_partition(part);
|
||||
if (err != ESP_OK) { print("[ota] set boot slot: %s", esp_err_to_name(err)); ok = false; }
|
||||
}
|
||||
if (!ok) {
|
||||
snprintf(msg, sizeof(msg), "Update failed\n\nStill running %s", FW_VERSION);
|
||||
showNotice(msg);
|
||||
delay(5000);
|
||||
hideNotice();
|
||||
return;
|
||||
}
|
||||
|
||||
print("[ota] verified and installed %s. Rebooting in 3 s; it confirms itself after %lu s of uptime.",
|
||||
m.version, (unsigned long)(OTA_CONFIRM_MS / 1000));
|
||||
snprintf(msg, sizeof(msg), "Installed %s\n\nRestarting...", m.version);
|
||||
showNotice(msg);
|
||||
Tunables::flush();
|
||||
delay(3000);
|
||||
esp_restart();
|
||||
}
|
||||
@@ -451,6 +513,7 @@ static void rollback() {
|
||||
if (!gate(false)) return;
|
||||
if (g_pending_verify) {
|
||||
print("[ota] rejecting this unconfirmed image; rebooting into the previous one");
|
||||
Tunables::flush();
|
||||
delay(500);
|
||||
esp_ota_mark_app_invalid_rollback_and_reboot();
|
||||
return;
|
||||
@@ -469,7 +532,8 @@ static void rollback() {
|
||||
}
|
||||
esp_err_t err = esp_ota_set_boot_partition(other);
|
||||
if (err != ESP_OK) { print("[ota] set boot slot: %s", esp_err_to_name(err)); return; }
|
||||
print("[ota] booting %s (built %s %s) in 2 s", other->label, d.date, d.time);
|
||||
print("[ota] booting %s in 2 s", other->label);
|
||||
Tunables::flush();
|
||||
delay(2000);
|
||||
esp_restart();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user