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.

67 lines
2.0 KiB

7 years ago
  1. /*
  2. MIGRATE MODULE
  3. Copyright (C) 2016-2019 by Xose Pérez <xose dot perez at gmail dot com>
  4. */
  5. #include "settings.h"
  6. void _cmpMoveIndexDown(const char * key, int offset = 0) {
  7. if (hasSetting({key, 0})) return;
  8. for (unsigned char index = 1; index < SETTINGS_MAX_LIST_COUNT; index++) {
  9. const unsigned char prev = index - 1;
  10. if (hasSetting({key, index})) {
  11. setSetting({key, prev}, getSetting({key, index}).toInt() + offset);
  12. } else {
  13. delSetting({key, prev});
  14. }
  15. }
  16. }
  17. // Configuration versions
  18. //
  19. // 1: based on Embedis, no board definitions
  20. // 2: based on Embedis, with board definitions 1-based
  21. // 3: based on Embedis, with board definitions 0-based
  22. // 4: based on Embedis, no board definitions
  23. void migrate() {
  24. // Update if not on the latest version
  25. const auto version = getSetting("cfg", CFG_VERSION);
  26. if (version == CFG_VERSION) return;
  27. setSetting("cfg", CFG_VERSION);
  28. switch (version) {
  29. // migrate old version with 1-based indices
  30. case 2:
  31. _cmpMoveIndexDown("ledGPIO");
  32. _cmpMoveIndexDown("ledLogic");
  33. _cmpMoveIndexDown("btnGPIO");
  34. _cmpMoveIndexDown("btnRelay", -1);
  35. _cmpMoveIndexDown("relayGPIO");
  36. _cmpMoveIndexDown("relayType");
  37. // fall through
  38. // get rid / move some existing keys from old migrate.ino
  39. case 3:
  40. moveSettings("chGPIO", "ltDimmerGPIO");
  41. moveSettings("myDIGPIO", "ltMy92DIGPIO");
  42. moveSettings("myDCKGPIO", "ltMy92DCKGPIO");
  43. moveSettings("myChips", "ltMy92Chips");
  44. moveSettings("myModel", "ltMy92Model");
  45. moveSettings("chLogic", "ltDimmerInv");
  46. moveSettings("ledLogic", "ledInv");
  47. delSetting("lightProvider");
  48. delSetting("relayProvider");
  49. delSetting("relays");
  50. delSetting("board");
  51. // fall through
  52. default:
  53. break;
  54. }
  55. saveSettings();
  56. }