Remove the deep-sleep feature entirely (user decision): power manager, Settings switch, NVS key, sleep bit in the shared header, docs
This commit is contained in:
@@ -50,8 +50,7 @@ src/
|
|||||||
debug_monitor.cpp # shows/hides LVGL perf+mem monitors from A's debug_enabled flag (recorded by the receiver, applied in loop)
|
debug_monitor.cpp # shows/hides LVGL perf+mem monitors from A's debug_enabled flag (recorded by the receiver, applied in loop)
|
||||||
link_peer.cpp # maintenance side of the link: STATUS to A, PAIR from the wire, SECURE (AES-GCM) frames from A -> Wi-Fi creds / OTA commands
|
link_peer.cpp # maintenance side of the link: STATUS to A, PAIR from the wire, SECURE (AES-GCM) frames from A -> Wi-Fi creds / OTA commands
|
||||||
ota_update.cpp # pulls this repo's signed Gitea release over Wi-Fi (port of A's module), 'ota' console
|
ota_update.cpp # pulls this repo's signed Gitea release over Wi-Fi (port of A's module), 'ota' console
|
||||||
console.cpp # serial line reader + handler chain ('help', 'link', 'wifi', 'ota', 'sleep')
|
console.cpp # serial line reader + handler chain ('help', 'link', 'wifi', 'ota')
|
||||||
power_manager.cpp # deep sleep 60 s after the link goes silent (CFG_SLEEP_WHEN_SILENT from A); wake on IO1 or a 60 s probe boot
|
|
||||||
assets/
|
assets/
|
||||||
assets.h # LV_FONT_DECLARE / LV_IMG_DECLARE for the files below
|
assets.h # LV_FONT_DECLARE / LV_IMG_DECLARE for the files below
|
||||||
fonts/ # Ubuntu Light 35 (values) and Ubuntu Bold 110 (gear) - plain LVGL font arrays
|
fonts/ # Ubuntu Light 35 (values) and Ubuntu Bold 110 (gear) - plain LVGL font arrays
|
||||||
|
|||||||
@@ -45,9 +45,6 @@ bool handleCommand(const char* line);
|
|||||||
|
|
||||||
const char* version();
|
const char* version();
|
||||||
|
|
||||||
/** A check or install is queued or running (the power manager must not sleep). */
|
|
||||||
bool isBusy();
|
|
||||||
|
|
||||||
} // namespace Ota
|
} // namespace Ota
|
||||||
|
|
||||||
#endif // OTA_UPDATE_H
|
#endif // OTA_UPDATE_H
|
||||||
|
|||||||
@@ -1,41 +0,0 @@
|
|||||||
/**
|
|
||||||
* Power Manager (Inst. Cluster) - deep sleep when the Main CTRL goes quiet.
|
|
||||||
*
|
|
||||||
* Controlled from the Main CTRL's Settings switch "Sleep when the car is off":
|
|
||||||
* it arrives as the CFG_SLEEP_WHEN_SILENT bit of the CONFIG frame and is
|
|
||||||
* cached in NVS with the rest of the gauge config, so it is known even while
|
|
||||||
* the Main CTRL is already asleep.
|
|
||||||
*
|
|
||||||
* Sleep when: the bit is set, no DATA frame on any transport for
|
|
||||||
* SLEEP_AFTER_MS, no update job running, up for at least SLEEP_AFTER_MS.
|
|
||||||
* Gauges are driven low and the backlight off first.
|
|
||||||
*
|
|
||||||
* Wake:
|
|
||||||
* - UART RX (IO1, RTC IO) goes low: the Main CTRL's first frame on the wire
|
|
||||||
* - a timer every PROBE_PERIOD_S: a short "probe boot" with the backlight
|
|
||||||
* off that listens for ESP-NOW frames for a few seconds and goes straight
|
|
||||||
* back to sleep if nothing arrives. This is what wakes the board when the
|
|
||||||
* link is radio-only (no wire in the car).
|
|
||||||
*
|
|
||||||
* Console: sleep status | now
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef POWER_MANAGER_H
|
|
||||||
#define POWER_MANAGER_H
|
|
||||||
|
|
||||||
#include <Arduino.h>
|
|
||||||
|
|
||||||
namespace PowerManager {
|
|
||||||
|
|
||||||
/** Right after DisplayInit::init(): detects a probe boot and keeps the panel dark. */
|
|
||||||
void init();
|
|
||||||
|
|
||||||
/** True during a timer-wake probe boot (setup() skips its waits). */
|
|
||||||
bool isProbeBoot();
|
|
||||||
|
|
||||||
void tick();
|
|
||||||
bool handleCommand(const char* line);
|
|
||||||
|
|
||||||
} // namespace PowerManager
|
|
||||||
|
|
||||||
#endif // POWER_MANAGER_H
|
|
||||||
@@ -187,10 +187,6 @@ typedef struct __attribute__((packed)) {
|
|||||||
|
|
||||||
#define OUT_ENABLE_TACH (1 << 0)
|
#define OUT_ENABLE_TACH (1 << 0)
|
||||||
#define OUT_ENABLE_TEMP (1 << 1)
|
#define OUT_ENABLE_TEMP (1 << 1)
|
||||||
// Not an output: the Main CTRL's "Sleep when the car is off" switch, carried in
|
|
||||||
// the same byte so the CONFIG layout (and PACKET_VERSION) stay unchanged. The
|
|
||||||
// Inst. Cluster caches CONFIG in NVS, so it knows the setting while A sleeps.
|
|
||||||
#define CFG_SLEEP_WHEN_SILENT (1 << 7)
|
|
||||||
#define OVERRIDE_TACH (1 << 0)
|
#define OVERRIDE_TACH (1 << 0)
|
||||||
#define OVERRIDE_TEMP (1 << 1)
|
#define OVERRIDE_TEMP (1 << 1)
|
||||||
|
|
||||||
|
|||||||
+2
-9
@@ -8,7 +8,6 @@
|
|||||||
|
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include <lvgl.h>
|
#include <lvgl.h>
|
||||||
#include <esp_sleep.h>
|
|
||||||
#include "modules/display_init.h"
|
#include "modules/display_init.h"
|
||||||
#include "modules/uart_receiver.h"
|
#include "modules/uart_receiver.h"
|
||||||
#include "modules/espnow_receiver.h"
|
#include "modules/espnow_receiver.h"
|
||||||
@@ -18,7 +17,6 @@
|
|||||||
#include "modules/link_peer.h"
|
#include "modules/link_peer.h"
|
||||||
#include "modules/console.h"
|
#include "modules/console.h"
|
||||||
#include "modules/ota_update.h"
|
#include "modules/ota_update.h"
|
||||||
#include "modules/power_manager.h"
|
|
||||||
#include "config/ota_config.h"
|
#include "config/ota_config.h"
|
||||||
|
|
||||||
// FreeRTOS task handles
|
// FreeRTOS task handles
|
||||||
@@ -44,13 +42,11 @@ void setup() {
|
|||||||
|
|
||||||
Serial.println("\n[BOOT] ESP32-S3-LCD-1.3 starting...");
|
Serial.println("\n[BOOT] ESP32-S3-LCD-1.3 starting...");
|
||||||
|
|
||||||
// A timer-wake probe boot (see PowerManager) must be quick: no serial waits.
|
|
||||||
bool probe = esp_sleep_get_wakeup_cause() == ESP_SLEEP_WAKEUP_TIMER;
|
|
||||||
unsigned long start_wait = millis();
|
unsigned long start_wait = millis();
|
||||||
while (!probe && !Serial && (millis() - start_wait < 3000)) {
|
while (!Serial && (millis() - start_wait < 3000)) {
|
||||||
delay(100);
|
delay(100);
|
||||||
}
|
}
|
||||||
if (!probe) delay(500);
|
delay(500);
|
||||||
|
|
||||||
Serial.println("[BOOT] Serial communication ready!");
|
Serial.println("[BOOT] Serial communication ready!");
|
||||||
Serial.println("\n\n=================================");
|
Serial.println("\n\n=================================");
|
||||||
@@ -71,7 +67,6 @@ void setup() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
GaugeScreen::init(); // hand-coded screen, built once, loaded
|
GaugeScreen::init(); // hand-coded screen, built once, loaded
|
||||||
PowerManager::init(); // probe boot? keep the panel dark until the Main CTRL is heard
|
|
||||||
|
|
||||||
xTaskCreatePinnedToCore(lvglTask, "LVGL_Task", 8192, NULL, 2, &lvglTaskHandle, 1);
|
xTaskCreatePinnedToCore(lvglTask, "LVGL_Task", 8192, NULL, 2, &lvglTaskHandle, 1);
|
||||||
|
|
||||||
@@ -88,7 +83,6 @@ void setup() {
|
|||||||
Ota::init(); // version + slot; hooks A's OTA commands
|
Ota::init(); // version + slot; hooks A's OTA commands
|
||||||
Console::addHandler(LinkPeer::handleCommand);
|
Console::addHandler(LinkPeer::handleCommand);
|
||||||
Console::addHandler(Ota::handleCommand);
|
Console::addHandler(Ota::handleCommand);
|
||||||
Console::addHandler(PowerManager::handleCommand);
|
|
||||||
|
|
||||||
Serial.println("\n[UART] Initializing link receiver...");
|
Serial.println("\n[UART] Initializing link receiver...");
|
||||||
if (!UARTReceiver::init()) {
|
if (!UARTReceiver::init()) {
|
||||||
@@ -119,7 +113,6 @@ void loop() {
|
|||||||
// STATUS to A, PAIR/SECURE frames from A, serial console
|
// STATUS to A, PAIR/SECURE frames from A, serial console
|
||||||
LinkPeer::tick();
|
LinkPeer::tick();
|
||||||
Ota::tick(); // runs a queued check/install (blocks the loop while it does)
|
Ota::tick(); // runs a queued check/install (blocks the loop while it does)
|
||||||
PowerManager::tick(); // deep sleep when the Main CTRL has been silent for a minute
|
|
||||||
Console::tick();
|
Console::tick();
|
||||||
|
|
||||||
// Apply a new CONFIG from A. Overrides are a bench tool: applied but not
|
// Apply a new CONFIG from A. Overrides are a bench tool: applied but not
|
||||||
|
|||||||
@@ -545,10 +545,6 @@ static void help() {
|
|||||||
// ---- public ----------------------------------------------------------------
|
// ---- public ----------------------------------------------------------------
|
||||||
const char* version() { return FW_VERSION; }
|
const char* version() { return FW_VERSION; }
|
||||||
|
|
||||||
bool isBusy() {
|
|
||||||
return g_job != JOB_NONE || g_phase == LINK_OTA_CHECKING || g_phase == LINK_OTA_INSTALLING;
|
|
||||||
}
|
|
||||||
|
|
||||||
void onLinkCommand(uint8_t cmd, uint8_t flags) {
|
void onLinkCommand(uint8_t cmd, uint8_t flags) {
|
||||||
char why[96];
|
char why[96];
|
||||||
bool ok = false;
|
bool ok = false;
|
||||||
|
|||||||
@@ -1,105 +0,0 @@
|
|||||||
/**
|
|
||||||
* Power Manager implementation (Inst. Cluster). See power_manager.h.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "modules/power_manager.h"
|
|
||||||
#include "modules/display_init.h"
|
|
||||||
#include "modules/gauge_outputs.h"
|
|
||||||
#include "modules/uart_receiver.h"
|
|
||||||
#include "modules/ota_update.h"
|
|
||||||
#include "protocol/automotive_data.h"
|
|
||||||
#include <esp_sleep.h>
|
|
||||||
#include <driver/rtc_io.h>
|
|
||||||
|
|
||||||
namespace PowerManager {
|
|
||||||
|
|
||||||
static const uint32_t SLEEP_AFTER_MS = 60000; // link silent this long -> sleep
|
|
||||||
static const uint32_t PROBE_LISTEN_MS = 4000; // probe boot: wait this long for a frame
|
|
||||||
static const uint32_t PROBE_PERIOD_S = 60; // timer wake interval while asleep
|
|
||||||
#define WAKE_PIN ((gpio_num_t)UART_RX_PIN) // IO1, the wire from the Main CTRL
|
|
||||||
|
|
||||||
static bool g_probe = false;
|
|
||||||
static bool g_probe_restored = false;
|
|
||||||
static uint8_t g_saved_brightness = 128;
|
|
||||||
|
|
||||||
static bool sleepAllowed() {
|
|
||||||
return (GaugeOutputs::getConfig().out_enable & CFG_SLEEP_WHEN_SILENT) != 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void init() {
|
|
||||||
esp_sleep_wakeup_cause_t why = esp_sleep_get_wakeup_cause();
|
|
||||||
if (why == ESP_SLEEP_WAKEUP_TIMER) {
|
|
||||||
g_probe = true;
|
|
||||||
g_saved_brightness = DisplayInit::getBrightness();
|
|
||||||
DisplayInit::setBrightness(0); // stay dark unless the link is really back
|
|
||||||
Serial.println("[sleep] probe boot (timer) - listening for the Main CTRL");
|
|
||||||
} else if (why == ESP_SLEEP_WAKEUP_EXT0) {
|
|
||||||
Serial.println("[sleep] woke up: activity on the UART wire");
|
|
||||||
}
|
|
||||||
// The sleep flag lives in the cached CONFIG, which GaugeOutputs::init() loads
|
|
||||||
// later in setup(); it is read live in tick() and printed by `sleep status`.
|
|
||||||
}
|
|
||||||
|
|
||||||
bool isProbeBoot() { return g_probe; }
|
|
||||||
|
|
||||||
static void goToSleep(const char* reason) {
|
|
||||||
Serial.printf("[sleep] t=%lu ms: %s - deep sleep; wake on the wire or in %lu s\n",
|
|
||||||
(unsigned long)millis(), reason, (unsigned long)PROBE_PERIOD_S);
|
|
||||||
automotive_data_t none = {};
|
|
||||||
GaugeOutputs::update(none, false); // tach off, temp output off
|
|
||||||
DisplayInit::setBrightness(0);
|
|
||||||
rtc_gpio_pulldown_dis(WAKE_PIN);
|
|
||||||
rtc_gpio_pullup_en(WAKE_PIN); // UART idles high; a start bit pulls it low
|
|
||||||
esp_sleep_enable_ext0_wakeup(WAKE_PIN, 0);
|
|
||||||
esp_sleep_enable_timer_wakeup((uint64_t)PROBE_PERIOD_S * 1000000ULL);
|
|
||||||
Serial.flush();
|
|
||||||
esp_deep_sleep_start();
|
|
||||||
}
|
|
||||||
|
|
||||||
void tick() {
|
|
||||||
static uint32_t last = 0;
|
|
||||||
if (millis() - last < 500) return;
|
|
||||||
last = millis();
|
|
||||||
|
|
||||||
bool linked = UARTReceiver::isConnected(1000);
|
|
||||||
|
|
||||||
if (g_probe) {
|
|
||||||
if (linked && !g_probe_restored) {
|
|
||||||
g_probe_restored = true;
|
|
||||||
g_probe = false;
|
|
||||||
DisplayInit::setBrightness(g_saved_brightness);
|
|
||||||
Serial.println("[sleep] Main CTRL is back - normal operation");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!linked && millis() > PROBE_LISTEN_MS) {
|
|
||||||
if (sleepAllowed()) goToSleep("probe: nothing heard");
|
|
||||||
else { g_probe = false; DisplayInit::setBrightness(g_saved_brightness); } // sleep got disabled meanwhile
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!sleepAllowed()) return;
|
|
||||||
if (millis() < SLEEP_AFTER_MS) return;
|
|
||||||
if (UARTReceiver::isConnected(SLEEP_AFTER_MS)) return;
|
|
||||||
if (Ota::isBusy()) return;
|
|
||||||
goToSleep("link silent for 60 s");
|
|
||||||
}
|
|
||||||
|
|
||||||
bool handleCommand(const char* line) {
|
|
||||||
if (strcmp(line, "help") == 0) {
|
|
||||||
Serial.println("sleep status sleep flag from the Main CTRL, link state");
|
|
||||||
Serial.println("sleep now deep sleep immediately (wake: wire or 60 s probe)");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (strcmp(line, "sleep status") == 0) {
|
|
||||||
Serial.printf("[sleep] %s | link %s | up %lu s%s\n", sleepAllowed() ? "enabled" : "disabled",
|
|
||||||
UARTReceiver::isConnected(1000) ? "alive" : "silent", millis() / 1000,
|
|
||||||
g_probe ? " | probe boot" : "");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (strcmp(line, "sleep now") == 0) { goToSleep("console"); return true; }
|
|
||||||
if (strncmp(line, "sleep", 5) == 0) { handleCommand("help"); return true; }
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace PowerManager
|
|
||||||
@@ -82,3 +82,7 @@ User saw the 2026-09-27 layout ("not bad") and redesigned it: no temperature dig
|
|||||||
## [2026-09-28] verify | Renamed Inst. Cluster; deep sleep on link silence with wire + timer wake, verified on the bench
|
## [2026-09-28] verify | Renamed Inst. Cluster; deep sleep on link silence with wire + timer wake, verified on the bench
|
||||||
|
|
||||||
User renamed the boards (Controller A → Main CTRL, Controller B → Inst. Cluster) across the repo. New `power_manager.cpp`: when the Main CTRL's "Sleep when the car is off" switch arrives as `CFG_SLEEP_WHEN_SILENT` (bit 7 of `out_enable`, cached in NVS with the gauge config), the board deep-sleeps after 60 s without a DATA frame (gauges low, backlight off), waking on UART RX IO1 (ext0, pull-up) or a 60 s timer. A timer wake is a *probe boot*: setup skips the serial waits, the panel stays dark, 4 s of listening, then sleep again unless the Main CTRL is heard. `Ota::isBusy()` blocks sleep during a job. Console `sleep status | now`. Bench, timestamps from the console: `t=60442 ms: link silent for 60 s - deep sleep` → `rst:0x5 (DSLEEP)` **60.1 s later** → `probe boot (timer)` → `t=4043 ms: probe: nothing heard - deep sleep`. Bug found and fixed on the way: the flag was printed at init before `GaugeOutputs::init()` had loaded the cached config ("off" while it was on). Not verified: wake through the wire (needs the Main CTRL awake and the wire), and how the probe boot looks on the panel (should stay dark).
|
User renamed the boards (Controller A → Main CTRL, Controller B → Inst. Cluster) across the repo. New `power_manager.cpp`: when the Main CTRL's "Sleep when the car is off" switch arrives as `CFG_SLEEP_WHEN_SILENT` (bit 7 of `out_enable`, cached in NVS with the gauge config), the board deep-sleeps after 60 s without a DATA frame (gauges low, backlight off), waking on UART RX IO1 (ext0, pull-up) or a 60 s timer. A timer wake is a *probe boot*: setup skips the serial waits, the panel stays dark, 4 s of listening, then sleep again unless the Main CTRL is heard. `Ota::isBusy()` blocks sleep during a job. Console `sleep status | now`. Bench, timestamps from the console: `t=60442 ms: link silent for 60 s - deep sleep` → `rst:0x5 (DSLEEP)` **60.1 s later** → `probe boot (timer)` → `t=4043 ms: probe: nothing heard - deep sleep`. Bug found and fixed on the way: the flag was printed at init before `GaugeOutputs::init()` had loaded the cached config ("off" while it was on). Not verified: wake through the wire (needs the Main CTRL awake and the wire), and how the probe boot looks on the panel (should stay dark).
|
||||||
|
|
||||||
|
## [2026-09-28] update | Deep-sleep feature REMOVED (user decision) - and the lesson it left
|
||||||
|
|
||||||
|
The "Sleep when the car is off" switch and both power managers are gone: code, Settings row, NVS key, the `CFG_SLEEP_WHEN_SILENT` bit in the shared header, the wiki page and the cheat-sheet entries. Reason: on the bench the Main CTRL's panel showed flickering white edges after a sleep, and it stayed that way through resets and even a USB flash of release v0.1.8. Cause, understood too late: `gpio_hold_en()` on the 20 RGB panel lines (added to blank the panel in sleep) lives in the RTC domain and **survives every reset except a power cycle** - no firmware without a matching `gpio_hold_dis()` at boot can drive the panel again. Only pulling the power clears it. **Rule for the future: never use GPIO hold / deep-sleep hold on this board's panel lines, and never send a board to deep sleep from the console without the user's go-ahead** (the USB port vanishes and only reset or power brings it back). The boards stay awake whenever powered; if power saving is ever wanted again, do it in hardware (ignition-switched supply).
|
||||||
|
|||||||
Reference in New Issue
Block a user