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
+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);