| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154 |
- /*
- * MemoryManager.cpp
- *
- * Created on: 21.06.2026
- * Author: FSmilari
- */
-
- #include "ConfigManager.h"
-
- ConfigManager::ConfigManager() {
- memset(&_config, 0, sizeof(Config));
- _config.wifiValid = false;
- }
-
- ConfigManager::~ConfigManager() {
- // TODO Auto-generated destructor stub
- }
-
- bool ConfigManager::loadConfig() {
- EEPROM.begin(sizeof(Config));
- EEPROM.get(0, _config);
-
- if (_config.wifiValid != true) {
- memset(&_config, 0, sizeof(Config));
- _config.wifiValid = false;
- return false;
- }
-
- return true;
- }
-
- bool ConfigManager::saveConfig(const Config &config) {
- _config = config;
-
- EEPROM.begin(sizeof(Config));
- EEPROM.put(0, _config);
-
- return EEPROM.commit();
- }
-
- void ConfigManager::resetConfig() {
- memset(&_config, 0, sizeof(Config));
- _config.wifiValid = false;
-
- EEPROM.begin(sizeof(Config));
- EEPROM.put(0, _config);
- EEPROM.commit();
- }
-
- Config& ConfigManager::setToDefaultConfig() {
- memset(&_config, 0, sizeof(Config));
-
- _config.version = CONFIG_VERSION;
-
- _config = setToDefaultWiFiConfig(_config);
- _config = setToDefaultLEDConfig(_config);
-
- // String ssid = "";
- // String pass = "";
- // ssid.toCharArray(_config.ssid, sizeof(_config.ssid));
- // pass.toCharArray(_config.pass, sizeof(_config.pass));
- //
- // _config.wifiValid = false;
- // _config.mode = LM_SINGLE_COLOR;
- // _config.singleColor.r = 0;
- // _config.singleColor.g = 0;
- // _config.singleColor.b = 0;
- // _config.singleColor.w = 255;
- //
- // _config.brightness = 128;
- //
- // _config.segmentColor1.r = 255;
- // _config.segmentColor1.g = 0;
- // _config.segmentColor1.b = 0;
- // _config.segmentColor1.w = 0;
- //
- // _config.segmentColor2.r = 0;
- // _config.segmentColor2.g = 255;
- // _config.segmentColor2.b = 0;
- // _config.segmentColor2.w = 0;
- //
- // _config.segmentColor3.r = 0;
- // _config.segmentColor3.g = 0;
- // _config.segmentColor3.b = 255;
- // _config.segmentColor3.w = 0;
- //
- // _config.rainbowDelay = 20;
- //
- // _config.spectralStepTime = 10000;
- //
- // _config.fadingHoldTime = 5000;
- // _config.fadingFadeTime = 1000;
- //
- // _config.flashOnTime = 1000;
- // _config.flashOffTime = 500;
-
- EEPROM.begin(sizeof(Config));
- EEPROM.put(0, _config);
- EEPROM.commit();
-
- return _config;
- }
-
- Config& ConfigManager::setToDefaultWiFiConfig(Config &config) {
- String ssid = "";
- String pass = "";
- ssid.toCharArray(config.ssid, sizeof(config.ssid));
- pass.toCharArray(config.pass, sizeof(config.pass));
- config.wifiValid = false;
-
- return config;
- }
-
- Config& ConfigManager::setToDefaultLEDConfig(Config &config) {
- config.mode = LM_SINGLE_COLOR;
- config.singleColor.r = 0;
- config.singleColor.g = 0;
- config.singleColor.b = 0;
- config.singleColor.w = 255;
-
- config.brightness = 128;
-
- config.segmentColor1.r = 255;
- config.segmentColor1.g = 0;
- config.segmentColor1.b = 0;
- config.segmentColor1.w = 0;
-
- config.segmentColor2.r = 0;
- config.segmentColor2.g = 255;
- config.segmentColor2.b = 0;
- config.segmentColor2.w = 0;
-
- config.segmentColor3.r = 0;
- config.segmentColor3.g = 0;
- config.segmentColor3.b = 255;
- config.segmentColor3.w = 0;
-
- config.rainbowDelay = 20;
-
- config.spectralStepTime = 10000;
-
- config.fadingHoldTime = 5000;
- config.fadingFadeTime = 1000;
-
- config.flashOnTime = 1000;
- config.flashOffTime = 500;
-
- return config;
- }
-
-
- Config& ConfigManager::getConfig() {
- return _config;
- }
|