Fix OLED autosleep timing and battery sampling cadence
- Track last OLED activity to avoid double timeout; keep power gating on transitions - Copy TZ before setenv() in timegm_fallback to avoid invalid pointer reuse - Add BATTERY_SAMPLE_INTERVAL_MS and only refresh cache at batch start when due - Keep battery sampling to a single ADC read (Arduino core lacks explicit ADC power gating)
This commit is contained in:
@@ -36,10 +36,9 @@ static bool g_mqtt_ok = false;
|
||||
|
||||
static bool g_oled_on = true;
|
||||
static bool g_prev_ctrl_high = false;
|
||||
static uint32_t g_oled_off_start = 0;
|
||||
static uint32_t g_last_page_ms = 0;
|
||||
static uint8_t g_page = 0;
|
||||
static uint32_t g_boot_ms = 0;
|
||||
static uint32_t g_last_activity_ms = 0;
|
||||
static bool g_display_ready = false;
|
||||
static uint32_t g_last_init_attempt_ms = 0;
|
||||
static bool g_last_oled_on = true;
|
||||
@@ -83,7 +82,7 @@ void display_init() {
|
||||
display.display();
|
||||
}
|
||||
g_last_init_attempt_ms = millis();
|
||||
g_boot_ms = millis();
|
||||
g_last_activity_ms = millis();
|
||||
}
|
||||
|
||||
void display_set_role(DeviceRole role) {
|
||||
@@ -380,27 +379,16 @@ void display_tick() {
|
||||
ctrl_high = digitalRead(PIN_OLED_CTRL) == HIGH;
|
||||
}
|
||||
|
||||
bool in_boot_window = (millis() - g_boot_ms) < OLED_AUTO_OFF_MS;
|
||||
uint32_t now_ms = millis();
|
||||
bool ctrl_falling_edge = g_prev_ctrl_high && !ctrl_high;
|
||||
if (g_role == DeviceRole::Receiver) {
|
||||
g_oled_on = true;
|
||||
g_oled_off_start = 0;
|
||||
} else if (in_boot_window) {
|
||||
g_oled_on = true;
|
||||
g_last_activity_ms = now_ms;
|
||||
} else {
|
||||
if (ctrl_high) {
|
||||
g_oled_on = true;
|
||||
g_oled_off_start = 0;
|
||||
} else if (g_prev_ctrl_high && !ctrl_high) {
|
||||
g_oled_off_start = millis();
|
||||
} else if (!g_prev_ctrl_high && !ctrl_high && g_oled_off_start == 0) {
|
||||
g_oled_off_start = millis();
|
||||
if (ctrl_high || ctrl_falling_edge) {
|
||||
g_last_activity_ms = now_ms;
|
||||
}
|
||||
|
||||
if (!ctrl_high && g_oled_off_start > 0 && millis() - g_oled_off_start > OLED_AUTO_OFF_MS) {
|
||||
g_oled_on = false;
|
||||
}
|
||||
|
||||
// fall through to power gating below
|
||||
g_oled_on = (now_ms - g_last_activity_ms) < OLED_AUTO_OFF_MS;
|
||||
}
|
||||
|
||||
if (g_oled_on) {
|
||||
|
||||
Reference in New Issue
Block a user