фиксы до работы с перемычкой вместо оптики
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
#include "SettingsStore.h"
|
||||
#include "Config.h"
|
||||
#include "Log.h"
|
||||
#include <Preferences.h>
|
||||
|
||||
namespace { constexpr uint16_t SETTINGS_VERSION = 1; constexpr char NAMESPACE[] = "opt-test"; }
|
||||
@@ -20,20 +21,21 @@ bool SettingsStore::valid(const Settings &s) const {
|
||||
|
||||
bool SettingsStore::load(Settings &s) {
|
||||
Preferences prefs;
|
||||
if (!prefs.begin(NAMESPACE, true)) { defaults(s); return false; }
|
||||
if (!prefs.begin(NAMESPACE, true)) { defaults(s); Log::event("NVS", "open for read FAILED; defaults selected"); return false; }
|
||||
const size_t got = prefs.getBytes("settings", &s, sizeof(s));
|
||||
prefs.end();
|
||||
if (got != sizeof(s) || !valid(s)) { defaults(s); return false; }
|
||||
if (got != sizeof(s) || !valid(s)) { defaults(s); Log::event("NVS", "missing/corrupt settings; defaults selected"); return false; }
|
||||
Log::event("NVS", "settings loaded and validated");
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SettingsStore::save(Settings &s) {
|
||||
s.version = SETTINGS_VERSION; s.checksum = settingsChecksum(s);
|
||||
if (!valid(s)) return false;
|
||||
if (!valid(s)) { Log::event("NVS", "save rejected: invalid settings"); return false; }
|
||||
Preferences prefs;
|
||||
if (!prefs.begin(NAMESPACE, false)) return false;
|
||||
if (!prefs.begin(NAMESPACE, false)) { Log::event("NVS", "open for write FAILED"); return false; }
|
||||
const bool ok = prefs.putBytes("settings", &s, sizeof(s)) == sizeof(s);
|
||||
prefs.end(); return ok;
|
||||
prefs.end(); Log::printf("NVS", "settings save %s", ok ? "OK" : "FAILED"); return ok;
|
||||
}
|
||||
|
||||
TestParams SettingsStore::params(const Settings &s) const {
|
||||
@@ -42,4 +44,3 @@ TestParams SettingsStore::params(const Settings &s) const {
|
||||
TEST_TIME_OPTIONS_MS[s.timeIndex], REPEAT_OPTIONS[s.repeatIndex],
|
||||
DUTY_OPTIONS_PCT[s.dutyIndex]};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user