Save configuration to preferences in NVS
This commit is contained in:
@@ -35,17 +35,20 @@ struct ConfigDef {
|
||||
static const ConfigDef configdefs[] = {
|
||||
{"systemName", ConfigType::STRING, String("OBPkp61")},
|
||||
{"systemMode", ConfigType::CHAR, 'K'},
|
||||
{"logLevel", ConfigType::BYTE, uint8_t(1)},
|
||||
{"logLevel", ConfigType::BYTE, uint8_t(4)},
|
||||
{"adminPassword", ConfigType::STRING, String("obpkp61")},
|
||||
{"useAdminPass", ConfigType::BOOL, true},
|
||||
{"instDesc1", ConfigType::STRING, String("")},
|
||||
{"instDesc2", ConfigType::STRING, String("")},
|
||||
{"apEnable", ConfigType::BOOL, true},
|
||||
{"apPassword", ConfigType::STRING, String("obpkp61")},
|
||||
{"apIp", ConfigType::STRING, String("192.168.15.1")},
|
||||
{"apMask", ConfigType::STRING, String("255.255.255.0")},
|
||||
{"stopApTime", ConfigType::SHORT, int16_t(0)},
|
||||
{"apHidden", ConfigType::BOOL, false},
|
||||
{"cpuSpeed", ConfigType::SHORT, int16_t(160)},
|
||||
{"ledBrightness", ConfigType::SHORT, int16_t(96)},
|
||||
{"ledRgbBrightness", ConfigType::SHORT, int16_t(96)},
|
||||
{"rgbBrightness", ConfigType::SHORT, int16_t(96)},
|
||||
{"tempFormat", ConfigType::CHAR, 'C'},
|
||||
{"switchBank", ConfigType::BYTE, uint8_t(0)},
|
||||
{"key1", ConfigType::BYTE, uint8_t(1)},
|
||||
@@ -75,15 +78,19 @@ private:
|
||||
Preferences& prefs;
|
||||
std::map<String, ConfigValue> values;
|
||||
std::map<String, const ConfigDef*> defs;
|
||||
void updateValue(const char* key, ConfigType type, ConfigValue newvalue);
|
||||
[[noreturn]] void error_abort() const;
|
||||
public:
|
||||
explicit Config(Preferences& prefs);
|
||||
void load();
|
||||
bool save(JsonObject json);
|
||||
void save();
|
||||
void dump();
|
||||
|
||||
bool hasKey(const char* key);
|
||||
|
||||
template<typename T>
|
||||
T get(const char* key) const;
|
||||
ConfigValue get(const char* key) const;
|
||||
|
||||
uint8_t getByte(const char* key) const;
|
||||
int16_t getShort(const char* key) const;
|
||||
@@ -94,6 +101,8 @@ public:
|
||||
const String& getString(const char* key) const;
|
||||
const char* getCString(const char* key) const;
|
||||
|
||||
bool setValue(const char* key, const char* value);
|
||||
|
||||
};
|
||||
|
||||
extern Config config;
|
||||
|
||||
Reference in New Issue
Block a user