Rename Controller A/B -> Main CTRL / Inst. Cluster (user); Sleep when the car is off: Settings switch, deep sleep on quiet CAN + idle screen, CAN RX wake, switch mirrored to the cluster; docs
Firmware / build (push) Successful in 7m22s

This commit is contained in:
2026-09-28 16:38:13 +02:00
parent 7a74c02b20
commit 803af7568f
48 changed files with 400 additions and 156 deletions
+1 -1
View File
@@ -1,5 +1,5 @@
/*
* ESP-NOW Link Module Implementation (Controller A, transmit only)
* ESP-NOW Link Module Implementation (Main CTRL, transmit only)
*/
#include "espnow_link.h"
+1 -1
View File
@@ -1,5 +1,5 @@
/*
* ESP-NOW Link Module (Controller A side)
* ESP-NOW Link Module (Main CTRL side)
*
* Second transport for the A -> B link: every frame the UART manager builds
* is also broadcast over ESP-NOW, so B keeps receiving if the wire is lost.
+21 -21
View File
@@ -1,5 +1,5 @@
/*
* Link Peer Module Implementation (Controller A)
* Link Peer Module Implementation (Main CTRL)
*
* Threading: onFrame() runs in the Wi-Fi task and only copies the STATUS into
* g_peer under a mutex. Everything else (NVS, sending, console) is the loop task.
@@ -129,9 +129,9 @@ peer_status_t getStatus() {
// ---- outbound ---------------------------------------------------------------
static bool sendSecure(uint8_t inner_type, const void* inner, size_t inner_len, char* why, size_t n) {
peer_status_t p = getStatus();
if (!p.heard) { snprintf(why, n, "Controller B not heard"); return false; }
if (!p.heard) { snprintf(why, n, "Inst. Cluster not heard"); return false; }
if (!p.paired) { snprintf(why, n, "not paired - run `link pair` with the wire connected"); return false; }
if (!p.key_match) { snprintf(why, n, "Controller B holds a different key - run `link pair` again"); return false; }
if (!p.key_match) { snprintf(why, n, "Inst. Cluster holds a different key - run `link pair` again"); return false; }
uint8_t payload[PACKET_MAX_PAYLOAD], frame[PACKET_MAX_SIZE];
size_t plen = link_secure_seal(g_key, inner_type, inner, inner_len, payload);
@@ -175,8 +175,8 @@ static bool pushCredentials(char* why, size_t n, bool log) {
if (ok) {
g_pushed_hash = have ? hashStr(hashStr(2166136261u, c.ssid), c.pass) : 1;
g_last_push_ms = millis();
if (log) print(have ? "[link] Wi-Fi credentials for '%s' sent to Controller B (encrypted)"
: "[link] told Controller B to forget its Wi-Fi credentials", c.ssid);
if (log) print(have ? "[link] Wi-Fi credentials for '%s' sent to Inst. Cluster (encrypted)"
: "[link] told Inst. Cluster to forget its Wi-Fi credentials", c.ssid);
}
memset(&c, 0, sizeof(c));
return ok;
@@ -204,7 +204,7 @@ static void syncCredentials() {
// ---- pairing ----------------------------------------------------------------
static bool pair(char* why, size_t n) {
if (UARTManager::getState() == UARTManager::UART_STATE_OFF) {
snprintf(why, n, "link is off - enable 'Send to Controller B' in Settings first");
snprintf(why, n, "link is off - enable 'Send to Inst. Cluster' in Settings first");
return false;
}
link_pair_t pk = {};
@@ -229,31 +229,31 @@ static bool pair(char* why, size_t n) {
g_pushed_hash = 0; // re-send the credentials under the new key
g_last_push_ms = 0;
print("[link] PAIR sent over the wire %d time(s); new key fingerprint %04X. "
"Controller B confirms in its next STATUS (`link status`).", sent, g_key_fp);
"Inst. Cluster confirms in its next STATUS (`link status`).", sent, g_key_fp);
return true;
}
// ---- public: requests (UI) --------------------------------------------------
static bool bReady(char* why, size_t n, bool need_parked) {
peer_status_t p = getStatus();
if (!p.heard) { snprintf(why, n, "Controller B not heard - is it powered?"); return false; }
if (!p.heard) { snprintf(why, n, "Inst. Cluster not heard - is it powered?"); return false; }
if (!p.paired || !p.key_match) {
snprintf(why, n, "Controller B is not paired with this controller (console: link pair, wire connected)");
snprintf(why, n, "Inst. Cluster is not paired with this controller (console: link pair, wire connected)");
return false;
}
if (!(p.st.flags & LINK_STATUS_HAVE_WIFI)) {
snprintf(why, n, "Controller B has no Wi-Fi credentials yet - join a network on this screen first");
snprintf(why, n, "Inst. Cluster has no Wi-Fi credentials yet - join a network on this screen first");
return false;
}
if (p.st.ota_phase == LINK_OTA_CHECKING || p.st.ota_phase == LINK_OTA_INSTALLING) {
snprintf(why, n, "Controller B is busy (%s)", phaseName(p.st.ota_phase));
snprintf(why, n, "Inst. Cluster is busy (%s)", phaseName(p.st.ota_phase));
return false;
}
if (need_parked && !Ota::isParked(why, n)) return false;
// Same network as B => same radio channel, so B's STATUS frames (progress)
// keep reaching this screen while B is joined.
if (WiFiManager::getStatus().link != WiFiManager::LINK_CONNECTED) {
snprintf(why, n, "join Wi-Fi on this controller first, so Controller B's progress can be followed");
snprintf(why, n, "join Wi-Fi on this controller first, so Inst. Cluster's progress can be followed");
return false;
}
return true;
@@ -274,7 +274,7 @@ void init() {
if (g_mutex == NULL) g_mutex = xSemaphoreCreateMutex();
loadKey();
EspNowLink::setReceiveHandler(onFrame);
print("[link] Controller B: %s", g_paired ? "pairing key loaded" : "NOT paired - `link pair` with the wire connected");
print("[link] Inst. Cluster: %s", g_paired ? "pairing key loaded" : "NOT paired - `link pair` with the wire connected");
}
void tick() {
@@ -288,18 +288,18 @@ void tick() {
peer_status_t p = getStatus();
if (p.heard != was_heard) {
was_heard = p.heard;
if (p.heard) print("[link] Controller B heard: %s, %s, %lu s up", p.st.version,
if (p.heard) print("[link] Inst. Cluster heard: %s, %s, %lu s up", p.st.version,
p.key_match ? "paired" : (p.st.key_fp ? "paired with ANOTHER key" : "unpaired"),
(unsigned long)p.st.uptime_s);
else print("[link] Controller B silent for %lu s", (unsigned long)(p.age_ms / 1000));
else print("[link] Inst. Cluster silent for %lu s", (unsigned long)(p.age_ms / 1000));
}
if (p.heard && p.key_match && !was_match) {
print("[link] Controller B confirmed pairing (fingerprint %04X)", p.st.key_fp);
print("[link] Inst. Cluster confirmed pairing (fingerprint %04X)", p.st.key_fp);
}
was_match = p.heard && p.key_match;
if (p.heard && p.st.ota_phase != last_phase) {
if (last_phase != 0xFF || p.st.ota_phase != LINK_OTA_IDLE)
print("[link] Controller B update: %s%s%s%s%s", phaseName(p.st.ota_phase),
print("[link] Inst. Cluster update: %s%s%s%s%s", phaseName(p.st.ota_phase),
p.st.latest[0] ? ", latest " : "", p.st.latest,
p.st.ota_phase == LINK_OTA_FAILED ? " - " : "",
p.st.ota_phase == LINK_OTA_FAILED ? p.st.message : "");
@@ -310,7 +310,7 @@ void tick() {
// ---- console ----------------------------------------------------------------
static void help() {
print("link status Controller B: version, pairing, update phase");
print("link status Inst. Cluster: version, pairing, update phase");
print("link pair new shared key -> B over the UART wire (bench, wire connected)");
print("link unpair forget the key here (B keeps its own until re-paired)");
print("link creds send the remembered Wi-Fi network to B now");
@@ -329,8 +329,8 @@ bool handleCommand(const char* line) {
print("[link] this side: %s (fingerprint %04X) | STATUS frames %lu | SECURE sent %lu, failed %lu",
p.paired ? "paired" : "NOT paired", p.key_fp, (unsigned long)g_status_count,
(unsigned long)g_secure_sent, (unsigned long)g_secure_fail);
if (!g_ever_heard) { print("[link] Controller B never heard"); return true; }
print("[link] Controller B %02X:%02X:%02X:%02X:%02X:%02X, %s (%lu s ago)",
if (!g_ever_heard) { print("[link] Inst. Cluster never heard"); return true; }
print("[link] Inst. Cluster %02X:%02X:%02X:%02X:%02X:%02X, %s (%lu s ago)",
p.mac[0], p.mac[1], p.mac[2], p.mac[3], p.mac[4], p.mac[5],
p.heard ? "alive" : "SILENT", (unsigned long)(p.age_ms / 1000));
print("[link] firmware %s | key %04X (%s) | Wi-Fi creds %s%s%s",
@@ -360,7 +360,7 @@ bool handleCommand(const char* line) {
else if (!strcmp(b, "install force")) ok = bReady(why, sizeof(why), true) && sendOtaCmd(LINK_OTA_CMD_INSTALL, LINK_OTA_FORCE, why, sizeof(why));
else if (!strcmp(b, "rollback")) ok = bReady(why, sizeof(why), true) && sendOtaCmd(LINK_OTA_CMD_ROLLBACK, 0, why, sizeof(why));
else { help(); return true; }
print(ok ? "[link] command sent to Controller B - watch `link status`" : "[link] refused: %s", why);
print(ok ? "[link] command sent to Inst. Cluster - watch `link status`" : "[link] refused: %s", why);
return true;
}
help();
+2 -2
View File
@@ -1,10 +1,10 @@
/*
* Link Peer Module (Controller A) - what A knows about Controller B, and the
* Link Peer Module (Main CTRL) - what A knows about Inst. Cluster, and the
* maintenance traffic that keeps B updatable. See
* ESP32-S3-LCD-1.3/wiki/pages/controller-b-ota.md (B's wiki).
*
* STATUS B -> A ESP-NOW unicast every 5 s: B's version, OTA phase, uptime.
* Shown on Settings -> Updates as the "Controller B" card.
* Shown on Settings -> Updates as the "Inst. Cluster" card.
* PAIR A -> B `link pair` on the console, UART WIRE ONLY: a fresh random
* key, kept in NVS on both sides. Both repos are public, so
* this is the only secret and it never travels by radio.
+1 -1
View File
@@ -144,7 +144,7 @@ static const char* stateName(esp_ota_img_states_t s) {
/**
* The vehicle must be parked to update: installing ends in a reboot that blanks
* Controller B's gauges. A silent bus (ignition off, or the bench) counts as
* Inst. Cluster's gauges. A silent bus (ignition off, or the bench) counts as
* parked. Lever UNKNOWN is allowed so a missing gear frame can't block a bench
* update; engine and output shaft are the checks that matter.
*/
+2 -2
View File
@@ -20,7 +20,7 @@
* or crash before that makes the bootloader fall back to the old slot.
*
* Needs Wi-Fi joined to a network with internet (Settings screen). Joining an
* AP moves the radio channel; the ESP-NOW link to Controller B follows it.
* AP moves the radio channel; the ESP-NOW link to Inst. Cluster follows it.
* See wiki/pages/ota-updates.md.
*/
@@ -66,7 +66,7 @@ ui_status_t getStatus();
bool requestCheck(char* why, size_t n);
bool requestInstall(char* why, size_t n);
/** The parking gate on its own (Controller B's install is guarded by it too). */
/** The parking gate on its own (Inst. Cluster's install is guarded by it too). */
bool isParked(char* why, size_t n);
} // namespace Ota
+128
View File
@@ -0,0 +1,128 @@
/*
* Power Manager implementation (Main CTRL). See power_manager.h.
*/
#include "power_manager.h"
#include "settings_manager.h"
#include "tunables.h"
#include "ota_update.h"
#include "link_peer.h"
#include "display_init.h"
#include "serial_lock.h"
#include "drivers/can_driver.h"
#include "display/lvgl_v8_port.h"
#include "protocol/automotive_data.h"
#include <lvgl.h>
#include <esp_sleep.h>
#include <driver/rtc_io.h>
namespace PowerManager {
static const uint32_t SLEEP_AFTER_MS = 60000; // quiet bus + idle touch + uptime before sleeping
static bool g_enabled = false;
static uint32_t g_last_log = 0;
static void print(const char* fmt, ...) {
char buf[200];
va_list ap;
va_start(ap, fmt);
vsnprintf(buf, sizeof(buf), fmt, ap);
va_end(ap);
SerialLock::lock();
Serial.println(buf);
SerialLock::unlock();
}
static void mirrorToCluster() {
link_config_t cfg = Tunables::get();
uint8_t want = g_enabled ? (cfg.out_enable | CFG_SLEEP_WHEN_SILENT) : (cfg.out_enable & ~CFG_SLEEP_WHEN_SILENT);
if (want == cfg.out_enable) return;
cfg.out_enable = want;
Tunables::set(cfg); // bumps cfg_version -> CONFIG frame -> Inst. Cluster caches it in NVS
}
void init(bool enabled) {
g_enabled = enabled;
esp_sleep_wakeup_cause_t why = esp_sleep_get_wakeup_cause();
if (why == ESP_SLEEP_WAKEUP_EXT0) print("[sleep] woke up: CAN bus activity");
print("[sleep] sleep when the car is off: %s", g_enabled ? "ON (60 s of quiet bus + idle screen)" : "off");
mirrorToCluster();
}
void setEnabled(bool on) {
if (on == g_enabled) return;
g_enabled = on;
SettingsManager::saveSleepState(on);
mirrorToCluster();
print("[sleep] %s", on ? "enabled - both controllers sleep 60 s after the bus goes quiet" : "disabled");
}
bool isEnabled() { return g_enabled; }
/** Why we are NOT sleeping right now, or NULL if every condition holds. */
static const char* blocker() {
if (!g_enabled) return "disabled";
if (millis() < SLEEP_AFTER_MS) return "just booted";
if (!CANDriver::isActive()) return "CAN switched off (no wake source)";
can_stats_t s = CANDriver::getStats();
if (s.messages_received > 0 && millis() - s.last_receive_time < SLEEP_AFTER_MS) return "bus alive";
Ota::ui_status_t o = Ota::getStatus();
if (o.phase == Ota::PHASE_CHECKING || o.phase == Ota::PHASE_INSTALLING) return "update running";
LinkPeer::peer_status_t p = LinkPeer::getStatus();
if (p.heard && (p.st.ota_phase == LINK_OTA_CHECKING || p.st.ota_phase == LINK_OTA_INSTALLING)) return "Inst. Cluster updating";
uint32_t idle = 0;
if (lvgl_port_lock(50)) { idle = lv_disp_get_inactive_time(NULL); lvgl_port_unlock(); }
else return "screen busy";
if (idle < SLEEP_AFTER_MS) return "screen in use";
return NULL;
}
static void goToSleep(const char* reason) {
print("[sleep] %s - deep sleep now; the CAN bus wakes me", reason);
Tunables::flush();
DisplayInit::setBacklight(false);
CANDriver::stop(); // frees GPIO 16 from the TWAI peripheral
delay(400); // let the CAN task deinit TWAI
// CAN RX idles high (recessive); the first bit of any frame pulls it low.
rtc_gpio_pulldown_dis((gpio_num_t)CAN_RX_PIN);
rtc_gpio_pullup_en((gpio_num_t)CAN_RX_PIN);
esp_sleep_enable_ext0_wakeup((gpio_num_t)CAN_RX_PIN, 0);
SerialLock::lock();
Serial.flush();
SerialLock::unlock();
esp_deep_sleep_start();
}
void tick() {
static uint32_t last = 0;
if (millis() - last < 1000) return;
last = millis();
const char* b = blocker();
if (b == NULL) goToSleep("bus quiet and screen idle for 60 s");
}
static void help() {
print("sleep status why the board is awake / when it would sleep");
print("sleep on | off same as the Settings switch (both controllers)");
print("sleep now deep sleep immediately (wake = CAN activity or power cycle)");
}
bool handleCommand(const char* line) {
if (strncmp(line, "sleep", 5) != 0 || (line[5] != 0 && line[5] != ' ')) return false;
const char* a = line + 5;
while (*a == ' ') a++;
if (!*a || !strcmp(a, "help")) { help(); return true; }
if (!strcmp(a, "status")) {
const char* b = blocker();
print("[sleep] %s | %s", g_enabled ? "enabled" : "disabled", b ? b : "about to sleep");
return true;
}
if (!strcmp(a, "on")) { setEnabled(true); return true; }
if (!strcmp(a, "off")) { setEnabled(false); return true; }
if (!strcmp(a, "now")) { goToSleep("console"); return true; }
help();
return true;
}
} // namespace PowerManager
+34
View File
@@ -0,0 +1,34 @@
/*
* Power Manager (Main CTRL) - deep sleep when the car is off.
*
* Toggle: Settings -> System -> "Sleep when the car is off" (NVS `sleep_en`,
* default OFF). The same switch is mirrored to the Inst. Cluster through the
* CONFIG frame (CFG_SLEEP_WHEN_SILENT bit), so one switch rules both boards.
*
* When enabled, this board goes to DEEP SLEEP once ALL of these hold:
* - CAN is switched on but the bus has been quiet for SLEEP_AFTER_MS
* (ignition off; a live car never stops talking)
* - nobody touched the screen for SLEEP_AFTER_MS
* - no update job is running here or on the Inst. Cluster
* - the board has been up for at least SLEEP_AFTER_MS
*
* Wake: the CAN RX pin (GPIO 16, an RTC IO on the S3) goes low with the first
* frame after the ignition comes back -> full reboot (~3 s to the Driveline).
* Nothing else wakes it: with the CAN wire unplugged, cycle the power.
*
* Console: sleep status | on | off | now
*/
#pragma once
#include <Arduino.h>
namespace PowerManager {
void init(bool enabled);
void setEnabled(bool on); // persists + mirrors to the Inst. Cluster config
bool isEnabled();
void tick(); // from loop()
bool handleCommand(const char* line);
} // namespace PowerManager
+15
View File
@@ -18,6 +18,7 @@ static const char* NVS_NAMESPACE = "settings";
static const char* NVS_KEY_WIFI_ENABLED = "wifi_en";
static const char* NVS_KEY_UART_ENABLED = "uart_en";
static const char* NVS_KEY_DEBUG_ENABLED = "debug_en";
static const char* NVS_KEY_SLEEP_ENABLED = "sleep_en";
static const char* NVS_KEY_CAN_ENABLED = "can_en";
// ============================================================================
@@ -66,6 +67,20 @@ void saveDebugState(bool enabled) {
Serial.printf("[SettingsManager] Saved Debug state = %s\n", enabled ? "ON" : "OFF");
}
void saveSleepState(bool enabled) {
preferences.begin(NVS_NAMESPACE, false);
preferences.putBool(NVS_KEY_SLEEP_ENABLED, enabled);
preferences.end();
Serial.printf("[SettingsManager] Saved Sleep state = %s\n", enabled ? "ON" : "OFF");
}
bool loadSleepState() {
preferences.begin(NVS_NAMESPACE, true);
bool enabled = preferences.getBool(NVS_KEY_SLEEP_ENABLED, false);
preferences.end();
return enabled;
}
bool loadDebugState() {
preferences.begin(NVS_NAMESPACE, true); // read-only mode
bool enabled = preferences.getBool(NVS_KEY_DEBUG_ENABLED, false); // default: OFF
+4
View File
@@ -60,6 +60,10 @@ bool loadDebugState();
*/
void saveCANState(bool enabled);
/** "Sleep when the car is off" (deep sleep after 60 s of quiet CAN bus). Default OFF. */
void saveSleepState(bool enabled);
bool loadSleepState();
/**
* @brief Load CAN Bus enabled state from NVS
* @return bool true if CAN Bus was enabled, false otherwise (default: false)
+29 -21
View File
@@ -8,6 +8,7 @@
#include "wifi_manager.h"
#include "ota_update.h"
#include "link_peer.h"
#include "power_manager.h"
#include "uart_manager.h"
#include "espnow_link.h"
#include "settings_manager.h"
@@ -82,6 +83,7 @@ static Ota::phase_t g_upd_refusal_phase = Ota::PHASE_IDLE;
static lv_obj_t* g_sys_can = NULL;
static lv_obj_t* g_sys_link = NULL;
static lv_obj_t* g_sys_dbg = NULL;
static lv_obj_t* g_sys_sleep = NULL;
static lv_obj_t* g_sys_info = NULL; // values column; keys are static
static void refresh(bool force);
@@ -208,7 +210,7 @@ static void onForget(lv_event_t* e) {
(void)e;
WiFiManager::status_t s = WiFiManager::getStatus();
char text[128];
snprintf(text, sizeof(text), "Controller A will no longer join \"%s\" by itself.", s.saved_ssid);
snprintf(text, sizeof(text), "Main CTRL will no longer join \"%s\" by itself.", s.saved_ssid);
confirm("Forget this network?", text, "Forget", onForgetConfirmed, NULL);
}
@@ -403,7 +405,7 @@ static void buildWifiPage(lv_obj_t* page) {
g_wifi_off_note = label(page,
"Wi-Fi is off.\n\nTurn it on to join a network for firmware updates. "
"The link to Controller B works without it.",
"The link to Inst. Cluster works without it.",
&lv_font_montserrat_20, UI_COL_MUTED);
lv_label_set_long_mode(g_wifi_off_note, LV_LABEL_LONG_WRAP);
lv_obj_set_width(g_wifi_off_note, LV_PCT(100));
@@ -511,7 +513,7 @@ static void buildPasswordOverlay() {
}
// ============================================================================
// UPDATES PAGE - Controller A (this board) and Controller B (over the link)
// UPDATES PAGE - Main CTRL (this board) and Inst. Cluster (over the link)
// ============================================================================
static lv_obj_t* g_b_installed = NULL;
@@ -537,9 +539,8 @@ static void onInstall(lv_event_t* e) {
char title[64];
snprintf(title, sizeof(title), "Install %s?", o.latest);
confirm(title,
"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"
"Do not switch off the ignition until it has restarted. Only while parked with the engine off.",
"This Controller will restart after successful update.\n\nInstrument Cluster's gauges will drop out for a few seconds.\n\n"
"DO NOT SWITCH OFF THE IGNITION!\n\nOnly while parked with the engine off!",
"Install", onInstallConfirmed, NULL);
}
@@ -569,9 +570,9 @@ static void onBInstall(lv_event_t* e) {
(void)e;
LinkPeer::peer_status_t p = LinkPeer::getStatus();
char title[64];
snprintf(title, sizeof(title), "Install %s on Controller B?", p.st.latest);
snprintf(title, sizeof(title), "Install %s on Inst. Cluster?", p.st.latest);
confirm(title,
"Controller B joins the Wi-Fi network, downloads its new firmware and restarts; "
"Inst. Cluster joins the Wi-Fi network, downloads its new firmware and restarts; "
"its gauges hold still meanwhile and this card shows the progress.\n\n"
"Only while parked with the engine off.",
"Install", onBInstallConfirmed, NULL);
@@ -599,7 +600,7 @@ static void refreshUpdatesA() {
case Ota::PHASE_AVAILABLE: snprintf(msg, sizeof(msg), "Version %s is available.", o.latest); col = UI_COL_ACCENT; break;
case Ota::PHASE_FAILED: snprintf(msg, sizeof(msg), LV_SYMBOL_WARNING " %s", o.message); col = UI_COL_WARN; break;
default:
snprintf(msg, sizeof(msg), "%s", wifi_ok ? "");
snprintf(msg, sizeof(msg), "%s", wifi_ok ? "Tap Check to look for a new version." : "Connect to Wi-Fi to check for updates.");
break;
}
if (g_upd_refusal[0]) {
@@ -637,24 +638,24 @@ static void refreshUpdatesB() {
char msg[160];
lv_color_t col = UI_COL_MUTED;
if (!p.heard) {
snprintf(msg, sizeof(msg), "Controller B not heard.%s",
snprintf(msg, sizeof(msg), "Inst. Cluster not heard.%s",
p.paired ? "" : " Not paired yet: connect the wire and run 'link pair' on the console.");
} else if (!p.paired || !p.key_match) {
snprintf(msg, sizeof(msg), LV_SYMBOL_WARNING " Not paired with this controller. "
"Connect the wire and run 'link pair' on the console.");
col = UI_COL_AMBER;
} else if (!has_wifi) {
snprintf(msg, sizeof(msg), "Controller B has no Wi-Fi credentials yet. Join a network here; "
snprintf(msg, sizeof(msg), "Inst. Cluster has no Wi-Fi credentials yet. Join a network here; "
"they are passed on by themselves.");
} else {
switch (p.st.ota_phase) {
case LINK_OTA_CHECKING: snprintf(msg, sizeof(msg), "Controller B is checking..."); break;
case LINK_OTA_INSTALLING: snprintf(msg, sizeof(msg), "Installing %s on Controller B... %u %%",
case LINK_OTA_CHECKING: snprintf(msg, sizeof(msg), "Inst. Cluster is checking..."); break;
case LINK_OTA_INSTALLING: snprintf(msg, sizeof(msg), "Installing %s on Inst. Cluster... %u %%",
p.st.latest, p.st.ota_progress); col = UI_COL_ACCENT; break;
case LINK_OTA_UP_TO_DATE: snprintf(msg, sizeof(msg), LV_SYMBOL_OK " Controller B is up to date."); col = UI_COL_OK; break;
case LINK_OTA_AVAILABLE: snprintf(msg, sizeof(msg), "Version %s is available for Controller B.", p.st.latest); col = UI_COL_ACCENT; break;
case LINK_OTA_UP_TO_DATE: snprintf(msg, sizeof(msg), LV_SYMBOL_OK " Inst. Cluster is up to date."); col = UI_COL_OK; break;
case LINK_OTA_AVAILABLE: snprintf(msg, sizeof(msg), "Version %s is available for Inst. Cluster.", p.st.latest); col = UI_COL_ACCENT; break;
case LINK_OTA_FAILED: snprintf(msg, sizeof(msg), LV_SYMBOL_WARNING " %s", p.st.message); col = UI_COL_WARN; break;
default: snprintf(msg, sizeof(msg), ""); break;
default: snprintf(msg, sizeof(msg), "Tap Check to look for a new version"); break;
}
if (p.st.flags & LINK_STATUS_PENDING_VERIFY) {
size_t n = strlen(msg);
@@ -726,7 +727,7 @@ static void buildUpdatesPage(lv_obj_t* page) {
label(page, "Firmware updates", &lv_font_montserrat_24, UI_COL_TEXT);
lv_obj_t* installed_a = NULL;
lv_obj_t* a = controllerCard(page, "Controller A", FW_VERSION, &installed_a, &g_upd_latest, &g_upd_state);
lv_obj_t* a = controllerCard(page, "Main CTRL", FW_VERSION, &installed_a, &g_upd_latest, &g_upd_state);
lv_obj_t* btns = box(a, LV_FLEX_FLOW_ROW);
lv_obj_set_size(btns, LV_PCT(100), LV_SIZE_CONTENT);
lv_obj_set_style_pad_column(btns, 16, 0);
@@ -734,7 +735,7 @@ static void buildUpdatesPage(lv_obj_t* page) {
g_upd_install = button(btns, "Install", 280, 56, BTN_SUCCESS, onInstall, NULL);
g_upd_wifi = button(btns, LV_SYMBOL_WIFI " Wi-Fi settings", 260, 56, BTN_SECONDARY, onGoWifi, NULL);
lv_obj_t* b = controllerCard(page, "Controller B", "-", &g_b_installed, &g_b_latest, &g_b_state);
lv_obj_t* b = controllerCard(page, "Inst. Cluster", "-", &g_b_installed, &g_b_latest, &g_b_state);
btns = box(b, LV_FLEX_FLOW_ROW);
lv_obj_set_size(btns, LV_PCT(100), LV_SIZE_CONTENT);
lv_obj_set_style_pad_column(btns, 16, 0);
@@ -742,8 +743,7 @@ static void buildUpdatesPage(lv_obj_t* page) {
g_b_install = button(btns, "Install", 280, 56, BTN_SUCCESS, onBInstall, NULL);
lv_obj_t* note = label(page,
"Signed releases from " OTA_SERVER ". Each controller restarts after installing and keeps "
"the previous version as a fallback.",
"Each controller restarts after updating. DO NOT TURN OFF THE IGNITION DURING THE UPDATE",
&lv_font_montserrat_20, UI_COL_MUTED);
lv_label_set_long_mode(note, LV_LABEL_LONG_WRAP);
lv_obj_set_width(note, LV_PCT(100));
@@ -770,7 +770,13 @@ static void onDebugSwitch(lv_event_t* e) {
UIStateManager::setDebugEnabled(on);
}
static void onSleepSwitch(lv_event_t* e) {
if (g_refreshing) return;
PowerManager::setEnabled(lv_obj_has_state(lv_event_get_target(e), LV_STATE_CHECKED));
}
static void refreshSystem(bool force) {
setChecked(g_sys_sleep, PowerManager::isEnabled());
setChecked(g_sys_can, CANDriver::isActive());
setChecked(g_sys_link, UARTManager::getState() != UARTManager::UART_STATE_OFF);
setChecked(g_sys_dbg, UIStateManager::isDebugEnabled());
@@ -808,10 +814,12 @@ static void buildSystemPage(lv_obj_t* page) {
lv_obj_t* right;
makeSettingRow(c, "CAN bus", "Read the car's data bus", &right);
g_sys_can = toggle(right, onCanSwitch, NULL);
makeSettingRow(c, "Send to Controller B", "Gauge data over the wire and ESP-NOW", &right);
makeSettingRow(c, "Send to Inst. Cluster", "Gauge data over the wire and ESP-NOW", &right);
g_sys_link = toggle(right, onLinkSwitch, NULL);
makeSettingRow(c, "Performance overlay", "Frame rate and CPU load in the corner", &right);
g_sys_dbg = toggle(right, onDebugSwitch, NULL);
makeSettingRow(c, "Sleep when the car is off", "Both controllers sleep 60 s after the CAN bus goes quiet", &right);
g_sys_sleep = toggle(right, onSleepSwitch, NULL);
// two labels side by side, same line spacing, so keys and values line up
lv_obj_t* info = card(page);
+1 -1
View File
@@ -6,7 +6,7 @@
* entry; the joined network is remembered (WiFiManager)
* Updates - installed vs latest release, Check, Install behind a confirm
* dialog (Ota)
* System - CAN bus / link to Controller B / performance overlay switches,
* System - CAN bus / link to Inst. Cluster / performance overlay switches,
* live link and memory figures
*
* Reached by swiping LEFT on the Driveline screen; swipe right or the
+1 -1
View File
@@ -102,7 +102,7 @@ static void help() {
print("cfg override off | rpm <n> | duty <n> | both <rpm> <duty>");
print("cfg reset back to defaults");
print("diag help OBD-II diagnostic probe (transmits on the bus)");
print("link help Controller B: pairing, credentials, its updates");
print("link help Inst. Cluster: pairing, credentials, its updates");
}
static bool setField(const char* name, long v) {
+1 -1
View File
@@ -1,7 +1,7 @@
/*
* Tunables Module
*
* Owns the link_config_t that Controller A pushes to Controller B: Patrol gauge
* Owns the link_config_t that Main CTRL pushes to Inst. Cluster: Patrol gauge
* calibration (tach pulses/rev, coolant PWM law) and the alert thresholds A
* evaluates. Persisted in NVS. Editable at runtime over the USB serial console
* ("cfg help") until a settings-screen UI exists.
+5 -5
View File
@@ -61,9 +61,9 @@ namespace TuningScreen
{F_TEMP_OFFSET, TAB_COOLANT, "Offset", "Duty at 0 \xC2\xB0" "C (duty = slope x temp + offset)", 1, -1000, 1000, NULL},
{F_TEMP_MIN, TAB_COOLANT, "Minimum temperature", "Needle stays at rest below this", 1, -50, 200, NULL},
{F_TEMP_DUTY_MAX, TAB_COOLANT, "Duty limit", "Highest duty sent (255 = full scale)", 5, 0, 255, NULL},
{F_COOLANT_HOT, TAB_ALERTS, "Coolant too hot", "Alarm on Controller B at or above this temperature", 1, 0, 200, NULL},
{F_GEARBOX_HOT, TAB_ALERTS, "Gearbox oil too hot", "Alarm on Controller B at or above this temperature", 1, 0, 200, NULL},
{F_BATT_LOW, TAB_ALERTS, "Battery low", "Alarm on Controller B below this voltage", 10, 0, 3000, NULL},
{F_COOLANT_HOT, TAB_ALERTS, "Coolant too hot", "Alarm on Inst. Cluster at or above this temperature", 1, 0, 200, NULL},
{F_GEARBOX_HOT, TAB_ALERTS, "Gearbox oil too hot", "Alarm on Inst. Cluster at or above this temperature", 1, 0, 200, NULL},
{F_BATT_LOW, TAB_ALERTS, "Battery low", "Alarm on Inst. Cluster below this voltage", 10, 0, 3000, NULL},
};
static const char *TAB_NAMES[TAB_COUNT] = {"Tachometer", "Coolant gauge", "Alerts", "Simulation"};
@@ -522,7 +522,7 @@ namespace TuningScreen
makeRow(g_tab_page[TAB_TACH], F_TACH_PPR);
makeRow(g_tab_page[TAB_TACH], F_TACH_TRIM);
makeRow(g_tab_page[TAB_TACH], F_TACH_MAX_HZ);
g_tach_en_sw = makeSwitchRow(g_tab_page[TAB_TACH], "Tachometer output", "IO7 on Controller B. Off = no signal",
g_tach_en_sw = makeSwitchRow(g_tab_page[TAB_TACH], "Tachometer output", "IO7 on Inst. Cluster. Off = no signal",
onEnableSwitch, (void *)(uintptr_t)OUT_ENABLE_TACH);
// ---- Coolant gauge ----
@@ -531,7 +531,7 @@ namespace TuningScreen
makeRow(g_tab_page[TAB_COOLANT], F_TEMP_OFFSET);
makeRow(g_tab_page[TAB_COOLANT], F_TEMP_MIN);
makeRow(g_tab_page[TAB_COOLANT], F_TEMP_DUTY_MAX);
g_temp_en_sw = makeSwitchRow(g_tab_page[TAB_COOLANT], "Coolant gauge output", "IO8 on Controller B. Off = no signal",
g_temp_en_sw = makeSwitchRow(g_tab_page[TAB_COOLANT], "Coolant gauge output", "IO8 on Inst. Cluster. Off = no signal",
onEnableSwitch, (void *)(uintptr_t)OUT_ENABLE_TEMP);
// ---- Alerts ----
+1 -1
View File
@@ -11,7 +11,7 @@
* button (top right) goes back. The Simulation sliders don't bubble gestures,
* so dragging them never changes screens.
* Every change goes through Tunables, so it is saved to NVS (overrides
* excepted) and pushed to Controller B in the next CONFIG frame.
* excepted) and pushed to Inst. Cluster in the next CONFIG frame.
*/
#pragma once
+2 -2
View File
@@ -3,7 +3,7 @@
*
* Builds the v2 frames (DATA at 5 Hz, CONFIG on change + every CONFIG_RESEND_MS)
* and sends each one on BOTH transports: UART1 (GPIO 44 -> SP3485 -> 485_A/B)
* and ESP-NOW broadcast. Controller B dedupes on packet_id.
* and ESP-NOW broadcast. Inst. Cluster dedupes on packet_id.
*/
#include "uart_manager.h"
@@ -291,7 +291,7 @@ void setDebugEnabled(bool enabled) {
if (xSemaphoreTake(g_data_mutex, pdMS_TO_TICKS(100)) == pdTRUE) {
g_automotive_data.debug_enabled = enabled ? 1 : 0;
xSemaphoreGive(g_data_mutex);
ESP_LOGI("UARTMgr", "Debug flag set to %s (will be transmitted to Controller B)",
ESP_LOGI("UARTMgr", "Debug flag set to %s (will be transmitted to Inst. Cluster)",
enabled ? "ENABLED" : "DISABLED");
}
}
+1 -1
View File
@@ -117,7 +117,7 @@ void setDebugEnabled(bool enabled);
void linkToCANState(bool can_active);
/**
* @brief Settings-screen switch: start/stop sending to Controller B (UART1 +
* @brief Settings-screen switch: start/stop sending to Inst. Cluster (UART1 +
* ESP-NOW) and remember the choice in NVS.
*/
void setEnabled(bool enabled);
+1 -1
View File
@@ -1,7 +1,7 @@
/*
* UI State Manager Module
*
* Holds the debug flag (sent to Controller B, shows LVGL's performance overlay).
* Holds the debug flag (sent to Inst. Cluster, shows LVGL's performance overlay).
*/
#pragma once
+2 -2
View File
@@ -6,7 +6,7 @@
* the request functions, so screen lifetimes can never leave dangling pointers
* here.
*
* Radio rules (the ESP-NOW link to Controller B shares the radio):
* Radio rules (the ESP-NOW link to Inst. Cluster shares the radio):
* - the radio stays in STA mode forever; "off" only stops association/scans.
* Never WiFi.disconnect(true) / WiFi.mode(WIFI_OFF) - that kills ESP-NOW.
* - scans only when asked (each one hops every channel);
@@ -84,7 +84,7 @@ bool handleCommand(const char* line);
/**
* The remembered network, password included - for LinkPeer, which hands it to
* Controller B inside an encrypted frame. Never print the password.
* Inst. Cluster inside an encrypted frame. Never print the password.
* @return false if no network is saved
*/
bool getSavedCredentials(char* ssid, size_t ssid_n, char* pass, size_t pass_n);