Fork of the espurna firmware for `mhsw` switches
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
1.9 KiB

7 years ago
  1. /*
  2. MIGRATE MODULE
  3. Copyright (C) 2016-2018 by Xose Pérez <xose dot perez at gmail dot com>
  4. */
  5. void _migrateMoveIndexDown(const char * key, int offset = 0) {
  6. if (hasSetting(key, 0)) return;
  7. for (unsigned char index = 1; index < SETTINGS_MAX_LIST_COUNT; index++) {
  8. if (hasSetting(key, index)) {
  9. setSetting(key, index - 1, getSetting(key, index).toInt() + offset);
  10. } else {
  11. delSetting(key, index - 1);
  12. }
  13. }
  14. }
  15. // Configuration versions
  16. //
  17. // 1: based on Embedis, no board definitions
  18. // 2: based on Embedis, with board definitions 1-based
  19. // 3: based on Embedis, with board definitions 0-based
  20. // 4: based on Embedis, added sensors and force resetting
  21. void migrate() {
  22. moveSetting("boardName", "device");
  23. moveSettings("relayGPIO", "rlyGPIO");
  24. moveSettings("relayResetGPIO", "rlyResetGPIO");
  25. moveSettings("relayType", "rlyType");
  26. moveSetting("selGPIO", "hlwSELGPIO");
  27. moveSetting("cfGPIO", "hlwCFGPIO");
  28. moveSetting("cf1GPIO", "hlwCF1GPIO");
  29. moveSetting("relayProvider", "rlyProvider");
  30. moveSetting("lightProvider", "litProvider");
  31. moveSetting("relays", "rlyCount");
  32. moveSettings("chGPIO", "litChGPIO");
  33. moveSettings("chLogic", "litChLogic");
  34. moveSetting("enGPIO", "litEnableGPIO");
  35. moveSetting("hlwSelC", "hlwCurLevel");
  36. moveSetting("hlwIntM", "hlwInt");
  37. delSetting("ledWifi");
  38. // Get config version
  39. unsigned int board = getSetting("board", 0).toInt();
  40. unsigned int config_version = getSetting("cfg", board > 0 ? 2 : 1).toInt();
  41. setSetting("cfg", CFG_VERSION);
  42. if (config_version == 2) {
  43. _migrateMoveIndexDown("ledGPIO");
  44. _migrateMoveIndexDown("ledLogic");
  45. _migrateMoveIndexDown("btnGPIO");
  46. _migrateMoveIndexDown("btnRelay", -1);
  47. _migrateMoveIndexDown("rlyGPIO");
  48. _migrateMoveIndexDown("rlyType");
  49. }
  50. }