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:
@@ -6,9 +6,32 @@
|
||||
#include "display/lvgl_v8_port.h"
|
||||
#include "ui/ui.h"
|
||||
#include "driveline_screen.h"
|
||||
#include "config/ota_config.h" // FW_VERSION
|
||||
|
||||
namespace DisplayInit {
|
||||
|
||||
static Backlight* g_backlight = nullptr;
|
||||
|
||||
/**
|
||||
* Firmware version, bottom-right on every screen. Lives on lv_layer_top(), which
|
||||
* sits above all screens and survives screen switches. Labels aren't
|
||||
* clickable, so it never steals touches or swipes from the screen below.
|
||||
* Call with the LVGL lock held.
|
||||
*/
|
||||
static void createVersionLabel() {
|
||||
lv_obj_t* lbl = lv_label_create(lv_layer_top());
|
||||
lv_label_set_text(lbl, "A " FW_VERSION);
|
||||
lv_obj_set_style_text_font(lbl, &lv_font_montserrat_14, 0);
|
||||
lv_obj_set_style_text_color(lbl, lv_color_hex(0x808080), 0);
|
||||
lv_obj_align(lbl, LV_ALIGN_BOTTOM_RIGHT, -8, -4);
|
||||
}
|
||||
|
||||
void setBacklight(bool on) {
|
||||
if (g_backlight == nullptr) return;
|
||||
if (on) g_backlight->on();
|
||||
else g_backlight->off();
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// PUBLIC API IMPLEMENTATION
|
||||
// ============================================================================
|
||||
@@ -76,6 +99,7 @@ DisplayObjects init() {
|
||||
// empty placeholder now (the SquareLine Home screen was removed 2026-09-21);
|
||||
// swap while the backlight is still off so there's no flash.
|
||||
DrivelineScreen::show();
|
||||
createVersionLabel();
|
||||
lvgl_port_unlock();
|
||||
Serial.println("[DisplayInit] Step 13: SquareLine UI loaded successfully!");
|
||||
|
||||
@@ -91,6 +115,7 @@ DisplayObjects init() {
|
||||
Serial.println("[DisplayInit] Display initialization complete!");
|
||||
|
||||
// Return board and backlight objects for later use
|
||||
g_backlight = backlight;
|
||||
return {board, backlight};
|
||||
}
|
||||
|
||||
|
||||
@@ -43,4 +43,7 @@ struct DisplayObjects {
|
||||
*/
|
||||
DisplayObjects init();
|
||||
|
||||
/** Backlight on/off after init() (e.g. dark during OTA flash writes, which flicker the panel). */
|
||||
void setBacklight(bool on);
|
||||
|
||||
} // namespace DisplayInit
|
||||
|
||||
@@ -145,7 +145,9 @@ static void onScreenGesture(lv_event_t* e) {
|
||||
lv_dir_t dir = lv_indev_get_gesture_dir(lv_indev_get_act());
|
||||
if (dir == LV_DIR_LEFT) {
|
||||
lv_indev_wait_release(lv_indev_get_act());
|
||||
_ui_screen_change(&ui_Settings_Screen, LV_SCR_LOAD_ANIM_FADE_ON, 100, 0,
|
||||
// No transition animation: a full-screen fade is re-rendered and blended
|
||||
// in software every frame and stutters on this 1024x600 panel.
|
||||
_ui_screen_change(&ui_Settings_Screen, LV_SCR_LOAD_ANIM_NONE, 0, 0,
|
||||
&ui_Settings_Screen_screen_init);
|
||||
} else if (dir == LV_DIR_RIGHT) {
|
||||
lv_indev_wait_release(lv_indev_get_act());
|
||||
@@ -257,7 +259,7 @@ static void build() {
|
||||
|
||||
void show() {
|
||||
build();
|
||||
lv_scr_load_anim(g_screen, LV_SCR_LOAD_ANIM_FADE_ON, 100, 0, false);
|
||||
lv_scr_load_anim(g_screen, LV_SCR_LOAD_ANIM_NONE, 0, 0, false); // instant: fades stutter at 1024x600
|
||||
}
|
||||
|
||||
void tick() {
|
||||
|
||||
+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();
|
||||
}
|
||||
|
||||
@@ -43,6 +43,18 @@ static void save() {
|
||||
prefs.end();
|
||||
}
|
||||
|
||||
// Every flash write briefly stalls the PSRAM-fed RGB panel (flicker), so edits
|
||||
// are applied + pushed to B at once but written to NVS only after the user
|
||||
// stops tapping (SAVE_IDLE_MS), on leaving the Tuning screen, or before reboot.
|
||||
static const uint32_t SAVE_IDLE_MS = 3000;
|
||||
static bool g_dirty = false;
|
||||
static uint32_t g_dirty_ms = 0;
|
||||
|
||||
static void markDirty() { // call with the mutex held
|
||||
g_dirty = true;
|
||||
g_dirty_ms = millis();
|
||||
}
|
||||
|
||||
static bool load() {
|
||||
Preferences prefs;
|
||||
prefs.begin(NVS_NAMESPACE, true);
|
||||
@@ -113,7 +125,7 @@ static bool setField(const char* name, long v) {
|
||||
if (ok) {
|
||||
g_cfg.cfg_version++;
|
||||
if (g_cfg.cfg_version == 0) g_cfg.cfg_version = 1;
|
||||
save();
|
||||
markDirty();
|
||||
}
|
||||
unlock();
|
||||
return ok;
|
||||
@@ -159,7 +171,7 @@ void set(const link_config_t& cfg) {
|
||||
uint8_t v = g_cfg.cfg_version + 1;
|
||||
g_cfg = cfg;
|
||||
g_cfg.cfg_version = v ? v : 1;
|
||||
save();
|
||||
markDirty();
|
||||
unlock();
|
||||
}
|
||||
|
||||
@@ -168,7 +180,7 @@ void resetDefaults() {
|
||||
uint8_t v = g_cfg.cfg_version + 1;
|
||||
link_config_defaults(&g_cfg);
|
||||
g_cfg.cfg_version = v ? v : 1;
|
||||
save();
|
||||
markDirty();
|
||||
unlock();
|
||||
}
|
||||
|
||||
@@ -203,7 +215,7 @@ bool handleCommand(const char* line) {
|
||||
if (!strcmp(argv[1], "set") && argc == 4) {
|
||||
long v = strtol(argv[3], NULL, 0);
|
||||
if (setField(argv[2], v)) {
|
||||
print("[cfg] %s = %ld (version %u, saved)", argv[2], v, version());
|
||||
print("[cfg] %s = %ld (version %u, saved to NVS in 3 s)", argv[2], v, version());
|
||||
} else {
|
||||
print("[cfg] unknown field '%s'", argv[2]);
|
||||
help();
|
||||
@@ -247,7 +259,18 @@ void setExtraCommandHandler(bool (*handler)(const char* line)) {
|
||||
g_extra_handler = handler;
|
||||
}
|
||||
|
||||
void flush() {
|
||||
lock();
|
||||
if (g_dirty) {
|
||||
save();
|
||||
g_dirty = false;
|
||||
}
|
||||
unlock();
|
||||
}
|
||||
|
||||
void pollSerial() {
|
||||
if (g_dirty && millis() - g_dirty_ms > SAVE_IDLE_MS) flush();
|
||||
|
||||
while (Serial.available()) {
|
||||
char c = (char)Serial.read();
|
||||
if (c == '\r' || c == '\n') {
|
||||
|
||||
@@ -58,6 +58,13 @@ bool handleCommand(const char* line);
|
||||
*/
|
||||
void pollSerial();
|
||||
|
||||
/**
|
||||
* Write pending edits to NVS now. Edits are otherwise saved SAVE_IDLE_MS after
|
||||
* the last change (each flash write flickers the RGB panel). Call before a
|
||||
* reboot or when leaving the Tuning screen.
|
||||
*/
|
||||
void flush();
|
||||
|
||||
/**
|
||||
* Register a second console command handler (e.g. DiagProbe::handleCommand)
|
||||
* that gets lines `cfg` does not recognise. Returns true if it consumed the line.
|
||||
|
||||
@@ -334,6 +334,7 @@ namespace TuningScreen
|
||||
{
|
||||
if (lv_event_get_code(e) != LV_EVENT_CLICKED)
|
||||
return;
|
||||
Tunables::flush(); // write pending edits now rather than after the idle delay
|
||||
DrivelineScreen::show();
|
||||
}
|
||||
|
||||
@@ -584,7 +585,7 @@ namespace TuningScreen
|
||||
{
|
||||
build();
|
||||
refreshFromTunables();
|
||||
lv_scr_load_anim(g_screen, LV_SCR_LOAD_ANIM_FADE_ON, 100, 0, false);
|
||||
lv_scr_load_anim(g_screen, LV_SCR_LOAD_ANIM_NONE, 0, 0, false); // instant: fades stutter at 1024x600
|
||||
}
|
||||
|
||||
void tick()
|
||||
|
||||
Reference in New Issue
Block a user