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:
2026-02-02 23:01:55 +01:00
parent 90d830da6f
commit 2199627a35
6 changed files with 29 additions and 33 deletions

View File

@@ -34,11 +34,8 @@ void power_configure_unused_pins_sender() {
}
void read_battery(MeterData &data) {
uint32_t sum = 0;
sum += analogRead(PIN_BAT_ADC);
sum += analogRead(PIN_BAT_ADC);
float avg = static_cast<float>(sum) / 2.0f;
float v = (avg / 4095.0f) * ADC_REF_V * BATTERY_DIVIDER * BATTERY_CAL;
uint32_t raw = analogRead(PIN_BAT_ADC);
float v = (static_cast<float>(raw) / 4095.0f) * ADC_REF_V * BATTERY_DIVIDER * BATTERY_CAL;
data.battery_voltage_v = v;
data.battery_percent = battery_percent_from_voltage(v);