Wemos D1 Mini Frimware zur Steuerung einer RGBW-LED-Lampe
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

ConfigManager.cpp 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /*
  2. * MemoryManager.cpp
  3. *
  4. * Created on: 21.06.2026
  5. * Author: FSmilari
  6. */
  7. #include "ConfigManager.h"
  8. ConfigManager::ConfigManager() {
  9. memset(&_config, 0, sizeof(Config));
  10. _config.wifiValid = false;
  11. }
  12. ConfigManager::~ConfigManager() {
  13. // TODO Auto-generated destructor stub
  14. }
  15. bool ConfigManager::loadConfig() {
  16. EEPROM.begin(sizeof(Config));
  17. EEPROM.get(0, _config);
  18. if (_config.wifiValid != true) {
  19. memset(&_config, 0, sizeof(Config));
  20. _config.wifiValid = false;
  21. return false;
  22. }
  23. return true;
  24. }
  25. bool ConfigManager::saveConfig(const Config &config) {
  26. _config = config;
  27. EEPROM.begin(sizeof(Config));
  28. EEPROM.put(0, _config);
  29. return EEPROM.commit();
  30. }
  31. void ConfigManager::resetConfig() {
  32. memset(&_config, 0, sizeof(Config));
  33. _config.wifiValid = false;
  34. EEPROM.begin(sizeof(Config));
  35. EEPROM.put(0, _config);
  36. EEPROM.commit();
  37. }
  38. Config& ConfigManager::setToDefaultConfig() {
  39. memset(&_config, 0, sizeof(Config));
  40. _config.version = CONFIG_VERSION;
  41. _config = setToDefaultWiFiConfig(_config);
  42. _config = setToDefaultLEDConfig(_config);
  43. // String ssid = "";
  44. // String pass = "";
  45. // ssid.toCharArray(_config.ssid, sizeof(_config.ssid));
  46. // pass.toCharArray(_config.pass, sizeof(_config.pass));
  47. //
  48. // _config.wifiValid = false;
  49. // _config.mode = LM_SINGLE_COLOR;
  50. // _config.singleColor.r = 0;
  51. // _config.singleColor.g = 0;
  52. // _config.singleColor.b = 0;
  53. // _config.singleColor.w = 255;
  54. //
  55. // _config.brightness = 128;
  56. //
  57. // _config.segmentColor1.r = 255;
  58. // _config.segmentColor1.g = 0;
  59. // _config.segmentColor1.b = 0;
  60. // _config.segmentColor1.w = 0;
  61. //
  62. // _config.segmentColor2.r = 0;
  63. // _config.segmentColor2.g = 255;
  64. // _config.segmentColor2.b = 0;
  65. // _config.segmentColor2.w = 0;
  66. //
  67. // _config.segmentColor3.r = 0;
  68. // _config.segmentColor3.g = 0;
  69. // _config.segmentColor3.b = 255;
  70. // _config.segmentColor3.w = 0;
  71. //
  72. // _config.rainbowDelay = 20;
  73. //
  74. // _config.spectralStepTime = 10000;
  75. //
  76. // _config.fadingHoldTime = 5000;
  77. // _config.fadingFadeTime = 1000;
  78. //
  79. // _config.flashOnTime = 1000;
  80. // _config.flashOffTime = 500;
  81. EEPROM.begin(sizeof(Config));
  82. EEPROM.put(0, _config);
  83. EEPROM.commit();
  84. return _config;
  85. }
  86. Config& ConfigManager::setToDefaultWiFiConfig(Config &config) {
  87. String ssid = "";
  88. String pass = "";
  89. ssid.toCharArray(config.ssid, sizeof(config.ssid));
  90. pass.toCharArray(config.pass, sizeof(config.pass));
  91. config.wifiValid = false;
  92. return config;
  93. }
  94. Config& ConfigManager::setToDefaultLEDConfig(Config &config) {
  95. config.mode = LM_SINGLE_COLOR;
  96. config.singleColor.r = 0;
  97. config.singleColor.g = 0;
  98. config.singleColor.b = 0;
  99. config.singleColor.w = 255;
  100. config.brightness = 128;
  101. config.segmentColor1.r = 255;
  102. config.segmentColor1.g = 0;
  103. config.segmentColor1.b = 0;
  104. config.segmentColor1.w = 0;
  105. config.segmentColor2.r = 0;
  106. config.segmentColor2.g = 255;
  107. config.segmentColor2.b = 0;
  108. config.segmentColor2.w = 0;
  109. config.segmentColor3.r = 0;
  110. config.segmentColor3.g = 0;
  111. config.segmentColor3.b = 255;
  112. config.segmentColor3.w = 0;
  113. config.rainbowDelay = 20;
  114. config.spectralStepTime = 10000;
  115. config.fadingHoldTime = 5000;
  116. config.fadingFadeTime = 1000;
  117. config.flashOnTime = 1000;
  118. config.flashOffTime = 500;
  119. return config;
  120. }
  121. Config& ConfigManager::getConfig() {
  122. return _config;
  123. }