Remove the deep-sleep feature entirely (user decision): power manager, Settings switch, NVS key, sleep bit in the shared header, wiki page and cheat-sheet entries
Firmware / build (push) Successful in 6m59s

This commit is contained in:
2026-09-28 17:20:54 +02:00
parent 59fae2c219
commit f07590bbc5
12 changed files with 5 additions and 268 deletions
+1 -5
View File
@@ -19,7 +19,6 @@
#include "modules/ota_update.h" // Manual firmware updates from Gitea releases (`ota` console)
#include "modules/link_peer.h" // Inst. Cluster status, pairing, credential handoff, B updates (`link` console)
#include "modules/status_overlay.h" // Every screen: Wi-Fi chip top-right, blinking alert banner top-centre
#include "modules/power_manager.h" // Deep sleep when the car is off (Settings switch, `sleep` console)
// ============================================================================
// MINIMAL LVGL + UI SETTINGS + WIFI + UART
@@ -62,8 +61,7 @@ static bool memCommand(const char* line) {
static bool consoleExtraCommand(const char* line) {
return DiagProbe::handleCommand(line) || Ota::handleCommand(line) ||
WiFiManager::handleCommand(line) || memCommand(line) ||
PerfMon::handleCommand(line) || LinkPeer::handleCommand(line) ||
PowerManager::handleCommand(line);
PerfMon::handleCommand(line) || LinkPeer::handleCommand(line);
}
// ============================================================================
@@ -101,7 +99,6 @@ void setup()
Tunables::init();
DiagProbe::init();
Tunables::setExtraCommandHandler(consoleExtraCommand);
PowerManager::init(SettingsManager::loadSleepState()); // after Tunables: mirrors the switch into the config
PerfMon::init();
// Load saved switch states from NVS
@@ -173,7 +170,6 @@ void loop()
TuningScreen::tick();
SettingsScreen::tick();
StatusOverlay::tick();
PowerManager::tick(); // deep sleep once the bus and the screen have been quiet for a minute
delay(100); // Check frequently to catch screen changes quickly
}
-149
View File
@@ -1,149 +0,0 @@
/*
* 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>
#include <driver/gpio.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;
}
// The RGB panel's 20 signal lines (Waveshare 5B board header). In deep sleep the
// LCD peripheral stops and these pins would float: a panel with no clock and
// floating data shows white/flickering edges if any light reaches it. Drive
// them low and HOLD them through the sleep, so the panel sees a black frame.
static const int RGB_PINS[] = {46, 3, 5, 7, 14, 38, 18, 17, 10, 39, 0, 45, 48, 47, 21, 1, 2, 42, 41, 40};
static void parkPanel() {
lvgl_port_lock(-1); // stop the render task from touching the panel while we take the pins
for (int pin : RGB_PINS) {
gpio_reset_pin((gpio_num_t)pin);
gpio_set_direction((gpio_num_t)pin, GPIO_MODE_OUTPUT);
gpio_set_level((gpio_num_t)pin, 0);
gpio_hold_en((gpio_num_t)pin);
}
gpio_deep_sleep_hold_en();
// the lock is deliberately not released: nothing must draw again before sleep
}
static void goToSleep(const char* reason) {
print("[sleep] %s - deep sleep now; the CAN bus wakes me", reason);
Tunables::flush();
DisplayInit::setBacklight(false); // CH422G EXIO2 low; the expander keeps it while we sleep
delay(50);
CANDriver::stop(); // frees GPIO 16 from the TWAI peripheral
delay(400); // let the CAN task deinit TWAI
parkPanel();
// 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
@@ -1,34 +0,0 @@
/*
* 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,7 +18,6 @@ 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";
// ============================================================================
@@ -67,20 +66,6 @@ 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,10 +60,6 @@ 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)
-10
View File
@@ -8,7 +8,6 @@
#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"
@@ -83,7 +82,6 @@ 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);
@@ -770,13 +768,7 @@ 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());
@@ -818,8 +810,6 @@ static void buildSystemPage(lv_obj_t* page) {
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);