fixed bool operators

This commit is contained in:
Matthew Frost 2024-04-17 17:40:15 +02:00
parent cfdd6ddca7
commit 9577d02c57
2 changed files with 17 additions and 18 deletions

View file

@ -227,7 +227,7 @@
<td>Gets or sets the webhook unlock hook</td>
</tr>
<tr>
<td style="text-align: left;">/users</td>
<t00d style="text-align: left;">/users</td>
<td>GET, POST</td>
<td>N/A</td>
<td>lists all local / backup user</td>

View file

@ -7,8 +7,8 @@ Settings::Settings() : disableDoor(false), doorMode("LATCH") {
void Settings::loadFromEEPROM() {
settings_preferences.begin("settings", false);
disableDoor = settings_preferences.getBool("disableDoor", false);
doorMode = settings_preferences.getString("doorMode", "LATCH");
disableDoor = settings_preferences.getBool("dd", false);
doorMode = settings_preferences.getString("dm", "LATCH");
settings_preferences.end();
settings_preferences.begin("t2", false);
@ -30,38 +30,37 @@ void Settings::loadFromEEPROM() {
}
void Settings::saveSetting(const String& namespaceStr, const String& key, const String& value, const String& typeStr) {
settings_preferences.begin(namespaceStr.c_str(), false);
if (typeStr == "bool") {
bool currentValue = settings_preferences.getBool(key.c_str());
bool newValue = value;
bool newValue = (value == "1") ? true : false;
if (currentValue != newValue) {
settings_preferences.begin(namespaceStr.c_str(), false);
settings_preferences.putBool(key.c_str(), newValue);
settings_preferences.end();
}
} else if (typeStr == "int") {
int currentValue = settings_preferences.getInt(key.c_str());
int newValue = atoi(value.c_str());
if (currentValue != newValue) {
settings_preferences.begin(namespaceStr.c_str(), false);
settings_preferences.putInt(key.c_str(), newValue);
settings_preferences.end();
}
} else if (typeStr == "float") {
float currentValue = settings_preferences.getFloat(key.c_str());
float newValue = atof(value.c_str());
if (currentValue != newValue) {
settings_preferences.begin(namespaceStr.c_str(), false);
settings_preferences.putFloat(key.c_str(), newValue);
settings_preferences.end();
}
} else if (typeStr == "string") {
String currentValue = settings_preferences.getString(key.c_str());
if (currentValue != value) {
settings_preferences.begin(namespaceStr.c_str(), false);
settings_preferences.putString(key.c_str(), value);
settings_preferences.end();
}
settings_preferences.end();
} else {
// Handle other types here if needed
}
@ -71,18 +70,18 @@ void Settings::saveSetting(const String& namespaceStr, const String& key, const
void Settings::setDisableDoor(bool value) {
if (disableDoor != value) {
disableDoor = value;
#ifdef WIFI
#ifdef TINANCE2_BACKEND
tinance2logrequest("Settings::setDisableDoor: " + String(value));
tinance2logrequest("Settings::setDisableDoor: " + String(disableDoor));
#endif
#endif
#ifdef SERIAL_DEBUG
Serial.print("Settings::setDisableDoor: " + String(value));
Serial.println(disableDoor);
Serial.print("Settings::setDisableDoor: " + String(disableDoor));
#endif
saveSetting("settings", "disableDoor", String(disableDoor), "bool");
saveSetting("settings", "dd", String(disableDoor), "bool");
}
}
@ -104,7 +103,7 @@ void Settings::setDoorMode(const String mode) {
#ifdef SERIAL_DEBUG
Serial.print("Settings::setDoorMode: " + mode);
#endif
saveSetting("settings", "doorMode", doorMode, "string");
saveSetting("settings", "dm", doorMode, "string");
}
}
}