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:
@@ -1,6 +1,7 @@
|
||||
#include "rtc_ds3231.h"
|
||||
#include "config.h"
|
||||
#include <Wire.h>
|
||||
#include <string>
|
||||
#include <time.h>
|
||||
|
||||
static constexpr uint8_t DS3231_ADDR = 0x68;
|
||||
@@ -17,12 +18,14 @@ static time_t timegm_fallback(struct tm *tm_utc) {
|
||||
if (!tm_utc) {
|
||||
return static_cast<time_t>(-1);
|
||||
}
|
||||
char *old_tz = getenv("TZ");
|
||||
const char *old_tz = getenv("TZ");
|
||||
// getenv() may return a pointer into mutable storage that becomes invalid after setenv().
|
||||
std::string old_tz_copy = old_tz ? old_tz : "";
|
||||
setenv("TZ", "UTC0", 1);
|
||||
tzset();
|
||||
time_t t = mktime(tm_utc);
|
||||
if (old_tz) {
|
||||
setenv("TZ", old_tz, 1);
|
||||
if (!old_tz_copy.empty()) {
|
||||
setenv("TZ", old_tz_copy.c_str(), 1);
|
||||
} else {
|
||||
unsetenv("TZ");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user