Hand-coded Settings + tabbed Gauge Tuning; remembered Wi-Fi; on-screen updates
Firmware / build (push) Successful in 3m58s

Settings (replaces the SquareLine screen, now deleted): sidebar with
Wi-Fi (switch, status card with failure reasons, networks nearby,
full-screen password page), Updates (installed vs latest, Check, Install
behind a confirm dialog) and System (CAN / link / perf overlay switches,
live link, CAN, memory, uptime).

Gauge Tuning: tabs Tachometer / Coolant gauge / Alerts / Simulation,
56 px -/+ rows with hints and real units, accelerating hold-to-repeat,
per-tab Reset with confirm, save indicator, SIMULATION ON chip, swipe
left to go back.

WiFiManager rewritten without LVGL code: one remembered network (NVS
"wifi"), auto-join at boot, scans only on request, no endless reconnect
(keeps the ESP-NOW channel stable), failure reasons from the disconnect
event, password never logged. Ota gains getStatus()/requestCheck()/
requestInstall() for the screen. CAN/UART switches become setEnabled().
Shared ui_kit (header, buttons, switches, confirm dialog); Montserrat
20/24 enabled.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-09-27 07:38:17 +02:00
parent 766019a01e
commit e68fad73b6
30 changed files with 2082 additions and 2276 deletions
+86 -18
View File
@@ -70,19 +70,63 @@ static bool g_job_pending = false;
static job_t g_job = JOB_CHECK;
static bool g_pending_verify = false;
// What the Settings screen shows. Written by the loop task (jobs) and the LVGL
// task (requests), read by the loop task - a spinlock keeps copies consistent.
static portMUX_TYPE g_ui_mux = portMUX_INITIALIZER_UNLOCKED;
static ui_status_t g_ui = {PHASE_IDLE, "", ""};
static char g_last_msg[96] = ""; // last console line, reused as the failure reason
static void setPhase(phase_t p, const char* latest = NULL, const char* msg = NULL) {
portENTER_CRITICAL(&g_ui_mux);
g_ui.phase = p;
if (latest) { strncpy(g_ui.latest, latest, sizeof(g_ui.latest) - 1); g_ui.latest[sizeof(g_ui.latest) - 1] = 0; }
const char* m = msg ? msg : "";
strncpy(g_ui.message, m, sizeof(g_ui.message) - 1);
g_ui.message[sizeof(g_ui.message) - 1] = 0;
portEXIT_CRITICAL(&g_ui_mux);
}
// ============================================================================
// Helpers
// ============================================================================
static void print(const char* fmt, ...) {
static void vlog(bool remember, const char* fmt, va_list ap) {
char buf[220];
va_list ap;
va_start(ap, fmt);
vsnprintf(buf, sizeof(buf), fmt, ap);
va_end(ap);
SerialLock::lock();
Serial.println(buf);
SerialLock::unlock();
if (remember) {
const char* m = strncmp(buf, "[ota] ", 6) == 0 ? buf + 6 : buf;
portENTER_CRITICAL(&g_ui_mux);
strncpy(g_last_msg, m, sizeof(g_last_msg) - 1);
g_last_msg[sizeof(g_last_msg) - 1] = 0;
portEXIT_CRITICAL(&g_ui_mux);
}
}
/** Console line; also kept as the reason the screen shows if the job fails. */
static void print(const char* fmt, ...) {
va_list ap;
va_start(ap, fmt);
vlog(true, fmt, ap);
va_end(ap);
}
/** Console-only diagnostics (heap, stack) that must not replace a failure reason. */
static void debug(const char* fmt, ...) {
va_list ap;
va_start(ap, fmt);
vlog(false, fmt, ap);
va_end(ap);
}
static void failPhase() {
char m[96];
portENTER_CRITICAL(&g_ui_mux);
memcpy(m, g_last_msg, sizeof(m));
portEXIT_CRITICAL(&g_ui_mux);
setPhase(PHASE_FAILED, NULL, m);
}
static const char* stateName(esp_ota_img_states_t s) {
@@ -124,17 +168,20 @@ static bool parked(char* why, size_t n) {
return true;
}
static bool gate(bool need_wifi, bool need_parked = true) {
static bool gate(bool need_wifi, bool need_parked = true, char* why_out = NULL, size_t why_n = 0) {
char why[96];
bool ok = true;
if (need_parked && !parked(why, sizeof(why))) {
ok = false;
} else if (need_wifi && WiFi.status() != WL_CONNECTED) {
snprintf(why, sizeof(why), "Wi-Fi not connected - join a network first");
ok = false;
}
if (!ok) {
print("[ota] refused: %s", why);
return false;
if (why_out) snprintf(why_out, why_n, "%s", why);
}
if (need_wifi && WiFi.status() != WL_CONNECTED) {
print("[ota] refused: Wi-Fi not connected - join a network on the Settings screen first");
return false;
}
return true;
return ok;
}
static void toHex(const uint8_t* in, size_t n, char* out) {
@@ -391,18 +438,20 @@ static void hideNotice() {
static void install(bool force) {
manifest_t m;
if (!fetchManifest(m) || !verifySignature(m)) return;
if (!fetchManifest(m) || !verifySignature(m)) { failPhase(); return; }
if (!force && strcmp(m.version, FW_VERSION) == 0) {
print("[ota] already running %s - nothing to do (`ota install force` to reinstall)", FW_VERSION);
setPhase(PHASE_UP_TO_DATE, m.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 (!part) { print("[ota] no idle OTA slot (partition table?)"); failPhase(); 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);
failPhase();
return;
}
@@ -428,6 +477,7 @@ static void install(bool force) {
if (err != ESP_OK) { print("[ota] set boot slot: %s", esp_err_to_name(err)); ok = false; }
}
if (!ok) {
failPhase();
snprintf(msg, sizeof(msg), "Update failed\n\nStill running %s", FW_VERSION);
showNotice(msg);
delay(5000);
@@ -446,11 +496,12 @@ static void install(bool force) {
static void check() {
manifest_t m;
if (!fetchManifest(m) || !verifySignature(m)) return;
if (!fetchManifest(m) || !verifySignature(m)) { failPhase(); return; }
bool same = strcmp(m.version, FW_VERSION) == 0;
print("[ota] running %s | latest release %s (%lu bytes, signature OK)%s",
FW_VERSION, m.version, (unsigned long)m.size,
same ? " - up to date" : " - `ota install` to update");
setPhase(same ? PHASE_UP_TO_DATE : PHASE_AVAILABLE, m.version);
}
// This core's mbedtls is built with CONFIG_MBEDTLS_INTERNAL_MEM_ALLOC: every TLS
@@ -466,7 +517,7 @@ static void* tlsCallocInternal(size_t n, size_t size) {
}
static void printHeap(const char* when) {
print("[ota] heap %s: internal free %u (largest block %u), PSRAM free %u", when,
debug("[ota] heap %s: internal free %u (largest block %u), PSRAM free %u", when,
(unsigned)heap_caps_get_free_size(MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT),
(unsigned)heap_caps_get_largest_free_block(MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT),
(unsigned)heap_caps_get_free_size(MALLOC_CAP_SPIRAM));
@@ -477,14 +528,20 @@ static void runJob(job_t job) {
if (job == JOB_CHECK) check();
else install(job == JOB_INSTALL_FORCE);
mbedtls_platform_set_calloc_free(tlsCallocInternal, heap_caps_free);
print("[ota] loop stack headroom after job: %u B", (unsigned)uxTaskGetStackHighWaterMark(NULL));
debug("[ota] loop stack headroom after job: %u B", (unsigned)uxTaskGetStackHighWaterMark(NULL));
}
static void startJob(job_t job) {
if (!gate(true, job != JOB_CHECK)) return; // checking is harmless; installing needs parked
static bool startJob(job_t job, char* why = NULL, size_t why_n = 0) {
if (g_job_pending) {
if (why) snprintf(why, why_n, "busy");
return false;
}
if (!gate(true, job != JOB_CHECK, why, why_n)) return false; // checking is harmless; installing needs parked
setPhase(job == JOB_CHECK ? PHASE_CHECKING : PHASE_INSTALLING);
g_job = job;
g_job_pending = true; // runs on the next tick(), in the loop task
print("[ota] working - console and screen values pause until done");
return true;
}
// ============================================================================
@@ -556,6 +613,17 @@ static void help() {
const char* version() { return FW_VERSION; }
ui_status_t getStatus() {
ui_status_t s;
portENTER_CRITICAL(&g_ui_mux);
s = g_ui;
portEXIT_CRITICAL(&g_ui_mux);
return s;
}
bool requestCheck(char* why, size_t n) { return startJob(JOB_CHECK, why, n); }
bool requestInstall(char* why, size_t n) { return startJob(JOB_INSTALL, why, n); }
void init() {
const esp_partition_t* run = esp_ota_get_running_partition();
esp_ota_img_states_t st = ESP_OTA_IMG_UNDEFINED;