Browse Source

settings: handle old keys in the respective modules

fixes #2419
mcspr-patch-1
Maxim Prokhorov 3 years ago
parent
commit
0f723b0248
6 changed files with 67 additions and 47 deletions
  1. +10
    -2
      code/espurna/button.cpp
  2. +12
    -0
      code/espurna/led.cpp
  3. +18
    -1
      code/espurna/light.cpp
  4. +9
    -29
      code/espurna/migrate.cpp
  5. +14
    -15
      code/espurna/relay.cpp
  6. +4
    -0
      code/espurna/settings.h

+ 10
- 2
code/espurna/button.cpp View File

@ -874,9 +874,17 @@ bool _buttonSetupProvider(unsigned char index, ButtonProvider provider) {
return result; return result;
} }
void buttonSetup() {
// Backwards compatibility
void _buttonSettingsMigrate(int version) {
if (!version || (version >= 5)) {
return;
}
delSettingPrefix("btnGPIO");
moveSetting("btnDelay", "btnRepDel"); moveSetting("btnDelay", "btnRepDel");
}
void buttonSetup() {
_buttonSettingsMigrate(migrateVersion());
for (unsigned char index = 0; index < ButtonsMax; ++index) { for (unsigned char index = 0; index < ButtonsMax; ++index) {
auto provider = getSetting({"btnProv", index}, _buttonProvider(index)); auto provider = getSetting({"btnProv", index}, _buttonProvider(index));


+ 12
- 0
code/espurna/led.cpp View File

@ -427,7 +427,19 @@ void ledLoop() {
} }
void _ledSettingsMigrate(int version) {
if (!version || (version >= 5)) {
return;
}
delSettingPrefix({
"ledGPIO",
"ledLogic"
});
}
void ledSetup() { void ledSetup() {
_ledSettingsMigrate(migrateVersion());
size_t leds = 0; size_t leds = 0;


+ 18
- 1
code/espurna/light.cpp View File

@ -1928,8 +1928,25 @@ void _lightProviderDebug() {
"\n")); "\n"));
} }
void lightSetup() {
void _lightSettingsMigrate(int version) {
if (!version || (version >= 5)) {
return;
}
delSettingPrefix({
"chGPIO",
"chLogic",
"myChips",
"myDCKGPIO",
"myDIGPIO"
});
delSetting("lightProvider");
moveSetting("lightTime", "ltTime"); moveSetting("lightTime", "ltTime");
}
void lightSetup() {
_lightSettingsMigrate(migrateVersion());
const auto enable_pin = getSetting("ltEnableGPIO", _lightEnablePin()); const auto enable_pin = getSetting("ltEnableGPIO", _lightEnablePin());
if (enable_pin != GPIO_NONE) { if (enable_pin != GPIO_NONE) {


+ 9
- 29
code/espurna/migrate.cpp View File

@ -12,9 +12,7 @@ Copyright (C) 2016-2019 by Xose Pérez <xose dot perez at gmail dot com>
#include <vector> #include <vector>
#include <utility> #include <utility>
namespace {
void delPrefixes(const std::initializer_list<const char*>& prefixes) {
void delSettingPrefix(const std::initializer_list<const char*>& prefixes) {
std::vector<String> to_purge; std::vector<String> to_purge;
using namespace settings; using namespace settings;
@ -33,7 +31,13 @@ void delPrefixes(const std::initializer_list<const char*>& prefixes) {
} }
} }
} // namespace
void delSettingPrefix(const char* prefix) {
delSettingPrefix({prefix});
}
void delSettingPrefix(const String& prefix) {
delSettingPrefix(prefix.c_str());
}
// Configuration versions // Configuration versions
// //
@ -53,7 +57,6 @@ int migrateVersion() {
} }
void migrate() { void migrate() {
// We either get 0, when version did not change // We either get 0, when version did not change
// Or, the version we migrate from // Or, the version we migrate from
const auto version = migrateVersion(); const auto version = migrateVersion();
@ -67,34 +70,11 @@ void migrate() {
// and some very old keys that were forced via migrate.ino // and some very old keys that were forced via migrate.ino
switch (version) { switch (version) {
case 2: case 2:
delPrefixes({
"btnGPIO",
"ledGPIO",
"ledLogic",
"relayGPIO",
"relayType"
});
// fall through
case 3: case 3:
case 4: case 4:
delPrefixes({
"board",
"chGPIO",
"chLogic",
"ledGPIO",
"ledLogic",
"lightProvider",
"myChips",
"myDCKGPIO",
"myDIGPIO",
"relayGPIO",
"relayProvider",
"relayType",
"relays"
});
delSetting("board");
break; break;
} }
saveSettings(); saveSettings();
} }

+ 14
- 15
code/espurna/relay.cpp View File

@ -1092,16 +1092,17 @@ PayloadStatus relayParsePayload(const char * payload) {
#endif #endif
} }
// BACKWARDS COMPATIBILITY
void _relayBackwards() {
for (unsigned char id = 0; id < _relays.size(); ++id) {
SettingsKey key {"mqttGroupInv", id};
if (!hasSetting(key)) continue;
setSetting({"mqttGroupSync", id}, getSetting(key));
delSetting(key);
void _relaySettingsMigrate(int version) {
if (!version || (version >= 5)) {
return;
} }
delSettingPrefix({
"relayGPIO",
"relayProvider",
"relayType",
});
delSetting("relays");
} }
void _relayBoot(unsigned char index, const RelayMaskHelper& mask) { void _relayBoot(unsigned char index, const RelayMaskHelper& mask) {
@ -1793,7 +1794,7 @@ RelayProviderBasePtr _relaySetupProvider(unsigned char index) {
return result; return result;
} }
void _relaySetupAdhoc() {
void _relaySetup() {
_relays.reserve(_relayAdhocPins()); _relays.reserve(_relayAdhocPins());
for (unsigned char id = 0; id < RelaysMax; ++id) { for (unsigned char id = 0; id < RelaysMax; ++id) {
@ -1806,17 +1807,15 @@ void _relaySetupAdhoc() {
} }
_relays.emplace_back(std::move(impl)); _relays.emplace_back(std::move(impl));
} }
relaySetupDummy(getSetting("relayDummy", DUMMY_RELAY_COUNT));
} }
void relaySetup() { void relaySetup() {
_relaySettingsMigrate(migrateVersion());
// Ad-hoc relays
_relaySetupAdhoc();
// Dummy (virtual) relays
relaySetupDummy(getSetting("relayDummy", DUMMY_RELAY_COUNT));
_relaySetup();
_relayBackwards();
_relayConfigure(); _relayConfigure();
_relayBootAll(); _relayBootAll();
_relayLoop(); _relayLoop();


+ 4
- 0
code/espurna/settings.h View File

@ -238,6 +238,10 @@ bool delSetting(const String& key);
bool delSetting(const __FlashStringHelper* key); bool delSetting(const __FlashStringHelper* key);
bool delSetting(const SettingsKey& key); bool delSetting(const SettingsKey& key);
void delSettingPrefix(const std::initializer_list<const char*>&);
void delSettingPrefix(const char* prefix);
void delSettingPrefix(const String& prefix);
bool hasSetting(const char* key); bool hasSetting(const char* key);
bool hasSetting(const String& key); bool hasSetting(const String& key);
bool hasSetting(const __FlashStringHelper* key); bool hasSetting(const __FlashStringHelper* key);


Loading…
Cancel
Save