From 620fde05ca8d914875d73e7c6d3b210bf677e8e5 Mon Sep 17 00:00:00 2001 From: iranl Date: Fri, 15 Mar 2024 19:50:44 +0100 Subject: [PATCH] Fixes bool to int --- NukiOpenerWrapper.cpp | 4 ++-- NukiWrapper.cpp | 2 +- WebCfgServer.cpp | 40 +++++++++++++++++----------------- main.cpp | 50 +++++++++++++++++++++++++------------------ 4 files changed, 52 insertions(+), 44 deletions(-) diff --git a/NukiOpenerWrapper.cpp b/NukiOpenerWrapper.cpp index 8648646..3d3b3b8 100644 --- a/NukiOpenerWrapper.cpp +++ b/NukiOpenerWrapper.cpp @@ -502,9 +502,9 @@ LockActionResult NukiOpenerWrapper::onLockActionReceivedCallback(const char *val nukiOpenerPreferences = new Preferences(); nukiOpenerPreferences->begin("nukihub", true); uint32_t aclPrefs[17]; - nukiLockPreferences->getBytes(preference_acl, &aclPrefs, sizeof(aclPrefs)); + nukiOpenerPreferences->getBytes(preference_acl, &aclPrefs, sizeof(aclPrefs)); - if((action == NukiOpener::LockAction::ActivateRTO && aclPrefs[9] == 1) || (action == NukiOpener::LockAction::DeactivateRTO && aclPrefs[10] == 1) || (action == NukiOpener::LockAction::ElectricStrikeActuation && aclPrefs[11] == 1) || (action == NukiOpener::LockAction::ActivateCM && aclPrefs[12] == 1) || (action == NukiOpener::LockAction::DeactivateCM && aclPrefs[13] == 1) || (action == NukiOpener::LockAction::FobAction1 && aclPrefs[14] == 1) || (action == NukiOpener::LockAction::FobAction2 && aclPrefs[15] == 1) || (action == NukiOpener::LockAction::FobAction3 && aclPrefs[16] == 1)) + if((action == NukiOpener::LockAction::ActivateRTO && (int)aclPrefs[9] == 1) || (action == NukiOpener::LockAction::DeactivateRTO && (int)aclPrefs[10] == 1) || (action == NukiOpener::LockAction::ElectricStrikeActuation && (int)aclPrefs[11] == 1) || (action == NukiOpener::LockAction::ActivateCM && (int)aclPrefs[12] == 1) || (action == NukiOpener::LockAction::DeactivateCM && (int)aclPrefs[13] == 1) || (action == NukiOpener::LockAction::FobAction1 && (int)aclPrefs[14] == 1) || (action == NukiOpener::LockAction::FobAction2 && (int)aclPrefs[15] == 1) || (action == NukiOpener::LockAction::FobAction3 && (int)aclPrefs[16] == 1)) { nukiOpenerPreferences->end(); nukiOpenerInst->_nextLockAction = action; diff --git a/NukiWrapper.cpp b/NukiWrapper.cpp index 44b0bad..d5e9766 100644 --- a/NukiWrapper.cpp +++ b/NukiWrapper.cpp @@ -471,7 +471,7 @@ LockActionResult NukiWrapper::onLockActionReceivedCallback(const char *value) uint32_t aclPrefs[17]; nukiLockPreferences->getBytes(preference_acl, &aclPrefs, sizeof(aclPrefs)); - if((action == NukiLock::LockAction::Lock && aclPrefs[0] == 1) || (action == NukiLock::LockAction::Unlock && aclPrefs[1] == 1) || (action == NukiLock::LockAction::Unlatch && aclPrefs[2] == 1) || (action == NukiLock::LockAction::LockNgo && aclPrefs[3] == 1) || (action == NukiLock::LockAction::LockNgoUnlatch && aclPrefs[4] == 1) || (action == NukiLock::LockAction::FullLock && aclPrefs[5] == 1) || (action == NukiLock::LockAction::FobAction1 && aclPrefs[6] == 1) || (action == NukiLock::LockAction::FobAction2 && aclPrefs[7] == 1) || (action == NukiLock::LockAction::FobAction3 && aclPrefs[8] == 1)) + if((action == NukiLock::LockAction::Lock && (int)aclPrefs[0] == 1) || (action == NukiLock::LockAction::Unlock && (int)aclPrefs[1] == 1) || (action == NukiLock::LockAction::Unlatch && (int)aclPrefs[2] == 1) || (action == NukiLock::LockAction::LockNgo && (int)aclPrefs[3] == 1) || (action == NukiLock::LockAction::LockNgoUnlatch && (int)aclPrefs[4] == 1) || (action == NukiLock::LockAction::FullLock && (int)aclPrefs[5] == 1) || (action == NukiLock::LockAction::FobAction1 && (int)aclPrefs[6] == 1) || (action == NukiLock::LockAction::FobAction2 && (int)aclPrefs[7] == 1) || (action == NukiLock::LockAction::FobAction3 && (int)aclPrefs[8] == 1)) { nukiLockPreferences->end(); nukiInst->_nextLockAction = action; diff --git a/WebCfgServer.cpp b/WebCfgServer.cpp index 752219e..ea43d99 100644 --- a/WebCfgServer.cpp +++ b/WebCfgServer.cpp @@ -461,7 +461,7 @@ bool WebCfgServer::processArgs(String& message) _preferences->putInt(preference_restart_ble_beacon_lost, value.toInt()); configChanged = true; } - else if(key == "aclLvlChanged") + else if(key == "ACLLVLCHANGED") { aclLvlChanged = true; } @@ -638,7 +638,7 @@ bool WebCfgServer::processArgs(String& message) if(aclLvlChanged) { - preferences->putBytes(preference_acl, (byte*)(&aclPrefs), sizeof(aclPrefs)); + _preferences->putBytes(preference_acl, (byte*)(&aclPrefs), sizeof(aclPrefs)); configChanged = true; } @@ -935,7 +935,7 @@ void WebCfgServer::buildAccLvlHtml(String &response) _preferences->getBytes(preference_acl, &aclPrefs, sizeof(aclPrefs)); response.concat("
"); - response.concat(""); + response.concat(""); response.concat("

Nuki General Access Control

"); response.concat(""); printCheckBox(response, "ACLCNF", "Change Nuki configuration", _preferences->getBool(preference_admin_enabled)); @@ -951,15 +951,15 @@ void WebCfgServer::buildAccLvlHtml(String &response) response.concat("

Nuki Lock Access Control

"); response.concat("
SettingEnabled
"); - printCheckBox(response, "ACLLCKLCK", "Lock", (aclPrefs[0] == "1")); - printCheckBox(response, "ACLLCKUNLCK", "Unlock", (aclPrefs[1] == "1")); - printCheckBox(response, "ACLLCKUNLTCH", "Unlatch", (aclPrefs[2] == "1")); - printCheckBox(response, "ACLLCKLNG", "Lock N Go", (aclPrefs[3] == "1")); - printCheckBox(response, "ACLLCKLNGU", "Lock N Go Unlatch", (aclPrefs[4] == "1")); - printCheckBox(response, "ACLLCKFLLCK", "Full Lock", (aclPrefs[5] == "1")); - printCheckBox(response, "ACLLCKFOB1", "Fob Action 1", (aclPrefs[6] == "1")); - printCheckBox(response, "ACLLCKFOB2", "Fob Action 2", (aclPrefs[7] == "1")); - printCheckBox(response, "ACLLCKFOB3", "Fob Action 3", (aclPrefs[8] == "1")); + printCheckBox(response, "ACLLCKLCK", "Lock", ((int)aclPrefs[0] == 1)); + printCheckBox(response, "ACLLCKUNLCK", "Unlock", ((int)aclPrefs[1] == 1)); + printCheckBox(response, "ACLLCKUNLTCH", "Unlatch", ((int)aclPrefs[2] == 1)); + printCheckBox(response, "ACLLCKLNG", "Lock N Go", ((int)aclPrefs[3] == 1)); + printCheckBox(response, "ACLLCKLNGU", "Lock N Go Unlatch", ((int)aclPrefs[4] == 1)); + printCheckBox(response, "ACLLCKFLLCK", "Full Lock", ((int)aclPrefs[5] == 1)); + printCheckBox(response, "ACLLCKFOB1", "Fob Action 1", ((int)aclPrefs[6] == 1)); + printCheckBox(response, "ACLLCKFOB2", "Fob Action 2", ((int)aclPrefs[7] == 1)); + printCheckBox(response, "ACLLCKFOB3", "Fob Action 3", ((int)aclPrefs[8] == 1)); response.concat("
ActionAllowed

"); } if(_nukiOpener != nullptr) @@ -967,14 +967,14 @@ void WebCfgServer::buildAccLvlHtml(String &response) response.concat("

Nuki Opener Access Control

"); response.concat(""); - printCheckBox(response, "ACLOPNUNLCK", "Activate Ring-to-Open", (aclPrefs[9] == "1")); - printCheckBox(response, "ACLOPNLCK", "Deactivate Ring-to-Open", (aclPrefs[10] == "1")); - printCheckBox(response, "ACLOPNUNLTCH", "Electric Strike Actuation", (aclPrefs[11] == "1")); - printCheckBox(response, "ACLOPNUNLCKCM", "Activate Continuous Mode", (aclPrefs[12] == "1")); - printCheckBox(response, "ACLOPNLCKCM", "Deactivate Continuous Mode", (aclPrefs[13] == "1")); - printCheckBox(response, "ACLOPNFOB1", "Fob Action 1", (aclPrefs[14] == "1")); - printCheckBox(response, "ACLOPNFOB2", "Fob Action 2", (aclPrefs[15] == "1")); - printCheckBox(response, "ACLOPNFOB3", "Fob Action 3", (aclPrefs[16] == "1")); + printCheckBox(response, "ACLOPNUNLCK", "Activate Ring-to-Open", ((int)aclPrefs[9] == 1)); + printCheckBox(response, "ACLOPNLCK", "Deactivate Ring-to-Open", ((int)aclPrefs[10] == 1)); + printCheckBox(response, "ACLOPNUNLTCH", "Electric Strike Actuation", ((int)aclPrefs[11] == 1)); + printCheckBox(response, "ACLOPNUNLCKCM", "Activate Continuous Mode", ((int)aclPrefs[12] == 1)); + printCheckBox(response, "ACLOPNLCKCM", "Deactivate Continuous Mode", ((int)aclPrefs[13] == 1)); + printCheckBox(response, "ACLOPNFOB1", "Fob Action 1", ((int)aclPrefs[14] == 1)); + printCheckBox(response, "ACLOPNFOB2", "Fob Action 2", ((int)aclPrefs[15] == 1)); + printCheckBox(response, "ACLOPNFOB3", "Fob Action 3", ((int)aclPrefs[16] == 1)); response.concat("
ActionAllowed

"); } response.concat("
"); diff --git a/main.cpp b/main.cpp index eaf0af0..b945f8a 100644 --- a/main.cpp +++ b/main.cpp @@ -164,37 +164,45 @@ bool initPreferences() preferences->putBool(preference_keypad_info_enabled, false); } - uint32_t aclPrefs[17]; - switch(preferences->getInt(preference_access_level)) { case 0: - preferences->putBool(preference_keypad_control_enabled, true); - preferences->putBool(preference_admin_enabled, true); + { + preferences->putBool(preference_keypad_control_enabled, true); + preferences->putBool(preference_admin_enabled, true); - aclPrefs = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}; - break; + uint32_t aclPrefs[17] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}; + preferences->putBytes(preference_acl, (byte*)(&aclPrefs), sizeof(aclPrefs)); + break; + } case 1: - preferences->putBool(preference_keypad_control_enabled, false); - preferences->putBool(preference_admin_enabled, false); + { + preferences->putBool(preference_keypad_control_enabled, false); + preferences->putBool(preference_admin_enabled, false); - aclPrefs = {1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0}; - break; + uint32_t aclPrefs[17] = {1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0}; + preferences->putBytes(preference_acl, (byte*)(&aclPrefs), sizeof(aclPrefs)); + break; + } case 2: - preferences->putBool(preference_keypad_control_enabled, false); - preferences->putBool(preference_admin_enabled, false); + { + preferences->putBool(preference_keypad_control_enabled, false); + preferences->putBool(preference_admin_enabled, false); - aclPrefs = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; - break; + uint32_t aclPrefs[17] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; + preferences->putBytes(preference_acl, (byte*)(&aclPrefs), sizeof(aclPrefs)); + break; + } case 3: - preferences->putBool(preference_keypad_control_enabled, false); - preferences->putBool(preference_admin_enabled, false); + { + preferences->putBool(preference_keypad_control_enabled, false); + preferences->putBool(preference_admin_enabled, false); - aclPrefs = {1, 1, 0, 1, 0, 1, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0}; - break; - } - - preferences->putBytes(preference_acl, (byte*)(&aclPrefs), sizeof(aclPrefs)); + uint32_t aclPrefs[17] = {1, 1, 0, 1, 0, 1, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0}; + preferences->putBytes(preference_acl, (byte*)(&aclPrefs), sizeof(aclPrefs)); + break; + } + } } preferences->putInt(preference_config_version, atof(NUKI_HUB_VERSION) * 100);