feat: persist pressure history to LittleFS across reboots
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -13,6 +13,7 @@ AppState g_state;
|
||||
|
||||
static unsigned long tSample = 0;
|
||||
static unsigned long tHistory = 0;
|
||||
static unsigned long tFlush = 0;
|
||||
|
||||
static void sampleNow() {
|
||||
g_state.now = rtcNow();
|
||||
@@ -47,12 +48,14 @@ void setup() {
|
||||
}
|
||||
settingsBegin();
|
||||
historyBegin();
|
||||
historyLoad(); // restore prior samples (empty on first ever boot)
|
||||
Serial.printf("history restored: %d samples\n", historyCount());
|
||||
|
||||
// Seed first sample immediately.
|
||||
sampleNow();
|
||||
historyAdd(rtcEpoch(), g_state.mslHpa, g_state.tempC);
|
||||
displayRender(g_state);
|
||||
tSample = tHistory = millis();
|
||||
tSample = tHistory = tFlush = millis();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
@@ -68,4 +71,10 @@ void loop() {
|
||||
tHistory = now;
|
||||
historyAdd(rtcEpoch(), g_state.mslHpa, g_state.tempC);
|
||||
}
|
||||
|
||||
if (now - tFlush >= FLUSH_INTERVAL_MS) {
|
||||
tFlush = now;
|
||||
historySave();
|
||||
Serial.printf("history flushed: %d samples\n", historyCount());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user