tds3p-rsvp-reader/firmware/src/Settings.cpp

50 lines
1.6 KiB
C++

#include "Settings.h"
#include <Preferences.h>
namespace {
constexpr char kNamespace[] = "rsvp";
}
void Settings::begin() {}
SavedState Settings::load() const {
Preferences preferences;
preferences.begin(kNamespace, true);
SavedState state;
state.bookPath = preferences.getString("book", "");
state.wordIndex = preferences.getUInt("word", 0);
state.wpm = preferences.getUShort("wpm", 300);
state.brightness = preferences.getUChar("brightness", 5);
state.fontStyle = preferences.getUChar("font_style", 0);
state.fontSize = preferences.getUChar("font_size", 20);
preferences.end();
return state;
}
void Settings::save(const SavedState& state) const {
Preferences preferences;
preferences.begin(kNamespace, false);
if (!preferences.isKey("book") || preferences.getString("book") != state.bookPath) {
preferences.putString("book", state.bookPath);
}
if (!preferences.isKey("word") || preferences.getUInt("word") != state.wordIndex) {
preferences.putUInt("word", state.wordIndex);
}
if (!preferences.isKey("wpm") || preferences.getUShort("wpm") != state.wpm) {
preferences.putUShort("wpm", state.wpm);
}
if (!preferences.isKey("brightness") ||
preferences.getUChar("brightness") != state.brightness) {
preferences.putUChar("brightness", state.brightness);
}
if (!preferences.isKey("font_style") ||
preferences.getUChar("font_style") != state.fontStyle) {
preferences.putUChar("font_style", state.fontStyle);
}
if (!preferences.isKey("font_size") || preferences.getUChar("font_size") != state.fontSize) {
preferences.putUChar("font_size", state.fontSize);
}
preferences.end();
}