add migration for obsolete gpio setting
This commit is contained in:
47
Gpio.cpp
47
Gpio.cpp
@@ -4,6 +4,7 @@
|
|||||||
#include "Pins.h"
|
#include "Pins.h"
|
||||||
#include "Logger.h"
|
#include "Logger.h"
|
||||||
#include "PreferencesKeys.h"
|
#include "PreferencesKeys.h"
|
||||||
|
#include "RestartReason.h"
|
||||||
|
|
||||||
Gpio* Gpio::_inst = nullptr;
|
Gpio* Gpio::_inst = nullptr;
|
||||||
unsigned long Gpio::_debounceTs = 0;
|
unsigned long Gpio::_debounceTs = 0;
|
||||||
@@ -15,6 +16,11 @@ Gpio::Gpio(Preferences* preferences)
|
|||||||
_inst = this;
|
_inst = this;
|
||||||
loadPinConfiguration();
|
loadPinConfiguration();
|
||||||
|
|
||||||
|
if(_preferences->getBool(preference_gpio_locking_enabled))
|
||||||
|
{
|
||||||
|
migrateObsoleteSetting();
|
||||||
|
}
|
||||||
|
|
||||||
_inst->init();
|
_inst->init();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -108,7 +114,7 @@ void Gpio::loadPinConfiguration()
|
|||||||
|
|
||||||
void Gpio::savePinConfiguration(const std::vector<PinEntry> &pinConfiguration)
|
void Gpio::savePinConfiguration(const std::vector<PinEntry> &pinConfiguration)
|
||||||
{
|
{
|
||||||
int8_t serialized[pinConfiguration.size() * 2];
|
int8_t serialized[std::max(pinConfiguration.size() * 2, _preferences->getBytesLength(preference_gpio_configuration))];
|
||||||
memset(serialized, 0, sizeof(serialized));
|
memset(serialized, 0, sizeof(serialized));
|
||||||
|
|
||||||
int len = pinConfiguration.size();
|
int len = pinConfiguration.size();
|
||||||
@@ -123,6 +129,13 @@ void Gpio::savePinConfiguration(const std::vector<PinEntry> &pinConfiguration)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for(int8_t v : serialized)
|
||||||
|
{
|
||||||
|
Serial.print((int)v);
|
||||||
|
Serial.print(" ");
|
||||||
|
}
|
||||||
|
Serial.println();
|
||||||
|
|
||||||
_preferences->putBytes(preference_gpio_configuration, serialized, sizeof(serialized));
|
_preferences->putBytes(preference_gpio_configuration, serialized, sizeof(serialized));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -260,3 +273,35 @@ void Gpio::setPinOutput(const uint8_t& pin, const uint8_t& state)
|
|||||||
{
|
{
|
||||||
digitalWrite(pin, state);
|
digitalWrite(pin, state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define TRIGGER_LOCK_PIN 32
|
||||||
|
#define TRIGGER_UNLOCK_PIN 33
|
||||||
|
#define TRIGGER_UNLATCH_PIN 27
|
||||||
|
|
||||||
|
void Gpio::migrateObsoleteSetting()
|
||||||
|
{
|
||||||
|
_pinConfiguration.clear();
|
||||||
|
|
||||||
|
PinEntry entry1;
|
||||||
|
entry1.pin = 27;
|
||||||
|
entry1.role = PinRole::InputUnlatch;
|
||||||
|
|
||||||
|
PinEntry entry2;
|
||||||
|
entry2.pin = 32;
|
||||||
|
entry2.role = PinRole::InputLock;
|
||||||
|
|
||||||
|
PinEntry entry3;
|
||||||
|
entry3.pin = 33;
|
||||||
|
entry3.role = PinRole::InputUnlock;
|
||||||
|
|
||||||
|
_pinConfiguration.push_back(entry1);
|
||||||
|
_pinConfiguration.push_back(entry2);
|
||||||
|
_pinConfiguration.push_back(entry3);
|
||||||
|
|
||||||
|
savePinConfiguration(_pinConfiguration);
|
||||||
|
|
||||||
|
_preferences->remove(preference_gpio_locking_enabled);
|
||||||
|
Log->println("Migrated gpio control setting");
|
||||||
|
delay(200);
|
||||||
|
restartEsp(RestartReason::GpioConfigurationUpdated);
|
||||||
|
}
|
||||||
|
|||||||
2
Gpio.h
2
Gpio.h
@@ -45,6 +45,8 @@ public:
|
|||||||
Gpio(Preferences* preferences);
|
Gpio(Preferences* preferences);
|
||||||
static void init();
|
static void init();
|
||||||
|
|
||||||
|
void migrateObsoleteSetting();
|
||||||
|
|
||||||
void addCallback(std::function<void(const GpioAction&)> callback);
|
void addCallback(std::function<void(const GpioAction&)> callback);
|
||||||
|
|
||||||
void loadPinConfiguration();
|
void loadPinConfiguration();
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ private:
|
|||||||
preference_query_interval_configuration, preference_query_interval_battery, preference_query_interval_keypad,
|
preference_query_interval_configuration, preference_query_interval_battery, preference_query_interval_keypad,
|
||||||
preference_keypad_control_enabled, preference_register_as_app, preference_command_nr_of_retries,
|
preference_keypad_control_enabled, preference_register_as_app, preference_command_nr_of_retries,
|
||||||
preference_command_retry_delay, preference_cred_user, preference_cred_password, preference_publish_authdata,
|
preference_command_retry_delay, preference_cred_user, preference_cred_password, preference_publish_authdata,
|
||||||
preference_gpio_locking_enabled, preference_publish_debug_info, preference_presence_detection_timeout,
|
preference_publish_debug_info, preference_presence_detection_timeout,
|
||||||
preference_has_mac_saved, preference_has_mac_byte_0, preference_has_mac_byte_1, preference_has_mac_byte_2,
|
preference_has_mac_saved, preference_has_mac_byte_0, preference_has_mac_byte_1, preference_has_mac_byte_2,
|
||||||
};
|
};
|
||||||
std::vector<char*> _redact =
|
std::vector<char*> _redact =
|
||||||
@@ -82,7 +82,7 @@ private:
|
|||||||
{
|
{
|
||||||
preference_started_before, preference_mqtt_log_enabled, preference_lock_enabled, preference_opener_enabled,
|
preference_started_before, preference_mqtt_log_enabled, preference_lock_enabled, preference_opener_enabled,
|
||||||
preference_restart_on_disconnect, preference_keypad_control_enabled, preference_register_as_app, preference_ip_dhcp_enabled,
|
preference_restart_on_disconnect, preference_keypad_control_enabled, preference_register_as_app, preference_ip_dhcp_enabled,
|
||||||
preference_publish_authdata, preference_gpio_locking_enabled, preference_has_mac_saved, preference_publish_debug_info
|
preference_publish_authdata, preference_has_mac_saved, preference_publish_debug_info
|
||||||
};
|
};
|
||||||
|
|
||||||
const bool isRedacted(const char* key) const
|
const bool isRedacted(const char* key) const
|
||||||
|
|||||||
@@ -451,11 +451,6 @@ bool WebCfgServer::processArgs(String& message)
|
|||||||
_preferences->putBool(preference_publish_authdata, (value == "1"));
|
_preferences->putBool(preference_publish_authdata, (value == "1"));
|
||||||
configChanged = true;
|
configChanged = true;
|
||||||
}
|
}
|
||||||
else if(key == "GPLCK")
|
|
||||||
{
|
|
||||||
_preferences->putBool(preference_gpio_locking_enabled, (value == "1"));
|
|
||||||
configChanged = true;
|
|
||||||
}
|
|
||||||
else if(key == "REGAPP")
|
else if(key == "REGAPP")
|
||||||
{
|
{
|
||||||
_preferences->putBool(preference_register_as_app, (value == "1"));
|
_preferences->putBool(preference_register_as_app, (value == "1"));
|
||||||
@@ -826,7 +821,6 @@ void WebCfgServer::buildNukiConfigHtml(String &response)
|
|||||||
printInputField(response, "NRTRY", "Number of retries if command failed", _preferences->getInt(preference_command_nr_of_retries), 10);
|
printInputField(response, "NRTRY", "Number of retries if command failed", _preferences->getInt(preference_command_nr_of_retries), 10);
|
||||||
printInputField(response, "TRYDLY", "Delay between retries (milliseconds)", _preferences->getInt(preference_command_retry_delay), 10);
|
printInputField(response, "TRYDLY", "Delay between retries (milliseconds)", _preferences->getInt(preference_command_retry_delay), 10);
|
||||||
printCheckBox(response, "PUBAUTH", "Publish auth data (May reduce battery life)", _preferences->getBool(preference_publish_authdata));
|
printCheckBox(response, "PUBAUTH", "Publish auth data (May reduce battery life)", _preferences->getBool(preference_publish_authdata));
|
||||||
printCheckBox(response, "GPLCK", "Enable control via GPIO", _preferences->getBool(preference_gpio_locking_enabled));
|
|
||||||
printInputField(response, "PRDTMO", "Presence detection timeout (seconds; -1 to disable)", _preferences->getInt(preference_presence_detection_timeout), 10);
|
printInputField(response, "PRDTMO", "Presence detection timeout (seconds; -1 to disable)", _preferences->getInt(preference_presence_detection_timeout), 10);
|
||||||
printInputField(response, "RSBC", "Restart if bluetooth beacons not received (seconds; -1 to disable)", _preferences->getInt(preference_restart_ble_beacon_lost), 10);
|
printInputField(response, "RSBC", "Restart if bluetooth beacons not received (seconds; -1 to disable)", _preferences->getInt(preference_restart_ble_beacon_lost), 10);
|
||||||
response.concat("</table>");
|
response.concat("</table>");
|
||||||
|
|||||||
1
main.cpp
1
main.cpp
@@ -170,6 +170,7 @@ void setup()
|
|||||||
Log->print(F("NUKI Hub version ")); Log->println(NUKI_HUB_VERSION);
|
Log->print(F("NUKI Hub version ")); Log->println(NUKI_HUB_VERSION);
|
||||||
|
|
||||||
bool firstStart = initPreferences();
|
bool firstStart = initPreferences();
|
||||||
|
|
||||||
initializeRestartReason();
|
initializeRestartReason();
|
||||||
|
|
||||||
CharBuffer::initialize();
|
CharBuffer::initialize();
|
||||||
|
|||||||
Reference in New Issue
Block a user