mirror of
https://github.com/xoseperez/espurna.git
synced 2026-03-10 18:27:14 +01:00
Convert .ino -> .cpp (#2228)
- general conversion from .ino modules into a separate .cpp files - clean-up internal headers, place libraries into .h. guard .cpp with _SUPPORT flags - fix some instances of shared variables instead of public methods - tweak build system to still build a single source file via os environment variable ESPURNA_BUILD_SINGLE_SOURCE
This commit is contained in:
67
code/espurna/migrate.cpp
Normal file
67
code/espurna/migrate.cpp
Normal file
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
|
||||
MIGRATE MODULE
|
||||
|
||||
Copyright (C) 2016-2019 by Xose Pérez <xose dot perez at gmail dot com>
|
||||
|
||||
*/
|
||||
|
||||
#include "settings.h"
|
||||
|
||||
void _cmpMoveIndexDown(const char * key, int offset = 0) {
|
||||
if (hasSetting({key, 0})) return;
|
||||
for (unsigned char index = 1; index < SETTINGS_MAX_LIST_COUNT; index++) {
|
||||
const unsigned char prev = index - 1;
|
||||
if (hasSetting({key, index})) {
|
||||
setSetting({key, prev}, getSetting({key, index}).toInt() + offset);
|
||||
} else {
|
||||
delSetting({key, prev});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Configuration versions
|
||||
//
|
||||
// 1: based on Embedis, no board definitions
|
||||
// 2: based on Embedis, with board definitions 1-based
|
||||
// 3: based on Embedis, with board definitions 0-based
|
||||
// 4: based on Embedis, no board definitions
|
||||
|
||||
void migrate() {
|
||||
|
||||
// Update if not on the latest version
|
||||
const auto version = getSetting("cfg", CFG_VERSION);
|
||||
if (version == CFG_VERSION) return;
|
||||
setSetting("cfg", CFG_VERSION);
|
||||
|
||||
switch (version) {
|
||||
// migrate old version with 1-based indices
|
||||
case 2:
|
||||
_cmpMoveIndexDown("ledGPIO");
|
||||
_cmpMoveIndexDown("ledLogic");
|
||||
_cmpMoveIndexDown("btnGPIO");
|
||||
_cmpMoveIndexDown("btnRelay", -1);
|
||||
_cmpMoveIndexDown("relayGPIO");
|
||||
_cmpMoveIndexDown("relayType");
|
||||
// fall through
|
||||
// get rid / move some existing keys from old migrate.ino
|
||||
case 3:
|
||||
moveSettings("chGPIO", "ltDimmerGPIO");
|
||||
moveSettings("myDIGPIO", "ltMy92DIGPIO");
|
||||
moveSettings("myDCKGPIO", "ltMy92DCKGPIO");
|
||||
moveSettings("myChips", "ltMy92Chips");
|
||||
moveSettings("myModel", "ltMy92Model");
|
||||
moveSettings("chLogic", "ltDimmerInv");
|
||||
moveSettings("ledLogic", "ledInv");
|
||||
delSetting("lightProvider");
|
||||
delSetting("relayProvider");
|
||||
delSetting("relays");
|
||||
delSetting("board");
|
||||
// fall through
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
saveSettings();
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user