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:
Max Prokhorov
2020-04-30 13:55:07 +03:00
committed by GitHub
parent 732e84c45e
commit edb23dbfc4
125 changed files with 2977 additions and 2352 deletions

67
code/espurna/migrate.cpp Normal file
View 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();
}