1
0
mirror of https://github.com/thooge/esp32-nmea2000-obp60.git synced 2025-12-16 07:23:07 +01:00

optimize memory usage for config data, allow 4s timeout for setConfig

This commit is contained in:
andreas
2022-03-11 14:50:48 +01:00
parent 6741222574
commit 4557e6c0bb
6 changed files with 40 additions and 17 deletions

View File

@@ -66,13 +66,10 @@ bool GwConfigHandler::loadConfig(){
bool GwConfigHandler::saveConfig(){
prefs.begin(PREF_NAME,false);
for (int i=0;i<getNumConfig();i++){
String val=configs[i]->asString();
auto it=changedValues.find(configs[i]->getName());
if (it != changedValues.end()){
val=it->second;
if (configs[i]->hasChangedValue){
LOG_DEBUG(GwLog::LOG,"saving %s=%s",configs[i]->getName().c_str(),configs[i]->changedValue.c_str());
prefs.putString(configs[i]->getName().c_str(),configs[i]->changedValue);
}
LOG_DEBUG(GwLog::LOG,"saving %s=%s",configs[i]->getName().c_str(),val.c_str());
prefs.putString(configs[i]->getName().c_str(),val);
}
prefs.end();
LOG_DEBUG(GwLog::LOG,"saved config");
@@ -87,14 +84,14 @@ bool GwConfigHandler::updateValue(String name, String value){
}
else{
LOG_DEBUG(GwLog::LOG,"update config %s=>%s",name.c_str(),i->isSecret()?"***":value.c_str());
changedValues[name]=value;
i->updateValue(value);
}
return true;
}
bool GwConfigHandler::reset(bool save){
LOG_DEBUG(GwLog::LOG,"reset config");
for (int i=0;i<getNumConfig();i++){
changedValues[configs[i]->getName()]=configs[i]->getDefault();
configs[i]->updateValue(configs[i]->getDefault(),true);
}
if (!save) return true;
return saveConfig();