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:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user