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.

79 lines
2.2 KiB

6 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. // 5: based on Embedis, updated rfb codes format
  24. int migrateVersion() {
  25. const static auto version = getSetting("cfg", CFG_VERSION);
  26. if (version == CFG_VERSION) {
  27. return 0;
  28. }
  29. return version;
  30. }
  31. void migrate() {
  32. // We either get 0, when version did not change
  33. // Or, the version we migrate from
  34. const auto version = migrateVersion();
  35. setSetting("cfg", CFG_VERSION);
  36. if (!version) return;
  37. switch (migrateVersion()) {
  38. // migrate old version with 1-based indices
  39. case 2:
  40. _cmpMoveIndexDown("ledGPIO");
  41. _cmpMoveIndexDown("ledLogic");
  42. _cmpMoveIndexDown("btnGPIO");
  43. _cmpMoveIndexDown("btnRelay", -1);
  44. _cmpMoveIndexDown("relayGPIO");
  45. _cmpMoveIndexDown("relayType");
  46. // fall through
  47. // get rid / move some existing keys from old migrate.ino
  48. case 3:
  49. moveSettings("chGPIO", "ltDimmerGPIO");
  50. moveSettings("myDIGPIO", "ltMy92DIGPIO");
  51. moveSettings("myDCKGPIO", "ltMy92DCKGPIO");
  52. moveSettings("myChips", "ltMy92Chips");
  53. moveSettings("myModel", "ltMy92Model");
  54. moveSettings("chLogic", "ltDimmerInv");
  55. moveSettings("ledLogic", "ledInv");
  56. delSetting("lightProvider");
  57. delSetting("relayProvider");
  58. delSetting("relays");
  59. delSetting("board");
  60. // fall through
  61. default:
  62. break;
  63. }
  64. saveSettings();
  65. }