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

View file

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