feat: persist pressure history to LittleFS across reboots
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
#include <LittleFS.h>
|
||||
#include "config.h"
|
||||
#include "history.h"
|
||||
|
||||
@@ -36,3 +37,35 @@ bool historyTrendDelta(float& outDelta) {
|
||||
outDelta = latest.mslHpa - past.mslHpa;
|
||||
return true;
|
||||
}
|
||||
|
||||
static const char* HPATH = "/history.dat";
|
||||
|
||||
// Binary format: [int32 count][count * Sample], stored oldest-first.
|
||||
bool historySave() {
|
||||
File f = LittleFS.open(HPATH, "w");
|
||||
if (!f) return false;
|
||||
int32_t n = s_count;
|
||||
f.write((const uint8_t*)&n, sizeof(n));
|
||||
for (int i = 0; i < s_count; i++) {
|
||||
Sample s = historyGet(i);
|
||||
f.write((const uint8_t*)&s, sizeof(s));
|
||||
}
|
||||
f.close();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool historyLoad() {
|
||||
File f = LittleFS.open(HPATH, "r");
|
||||
if (!f) return false;
|
||||
int32_t n = 0;
|
||||
if (f.read((uint8_t*)&n, sizeof(n)) != sizeof(n)) { f.close(); return false; }
|
||||
if (n < 0 || n > HISTORY_SIZE) { f.close(); return false; }
|
||||
s_head = 0; s_count = 0;
|
||||
for (int i = 0; i < n; i++) {
|
||||
Sample s;
|
||||
if (f.read((uint8_t*)&s, sizeof(s)) != sizeof(s)) break;
|
||||
historyAdd(s.epoch, s.mslHpa, s.tempC);
|
||||
}
|
||||
f.close();
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user