| @@ -50,19 +50,49 @@ void ConfigManager::resetConfig() { | |||
| Config& ConfigManager::setToDefaultConfig() { | |||
| memset(&_config, 0, sizeof(Config)); | |||
| String ssid = ""; | |||
| String pass = ""; | |||
| ssid.toCharArray(_config.ssid, sizeof(_config.ssid)); | |||
| pass.toCharArray(_config.pass, sizeof(_config.pass)); | |||
| _config.wifiValid = false; | |||
| _config.version = CONFIG_VERSION; | |||
| _config.mode = LM_SINGLE_COLOR; | |||
| _config.color.r = 0; | |||
| _config.color.g = 0; | |||
| _config.color.b = 0; | |||
| _config.color.w = 255; | |||
| _config.brightness = 128; | |||
| _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); | |||
| @@ -71,6 +101,54 @@ Config& ConfigManager::setToDefaultConfig() { | |||
| 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; | |||
| } | |||
| @@ -12,7 +12,7 @@ | |||
| #include <EEPROM.h> | |||
| #include "LEDModes.h" | |||
| #define CONFIG_VERSION 1 | |||
| #define CONFIG_VERSION 3 | |||
| typedef struct __attribute__((packed)) { | |||
| uint8_t r; | |||
| @@ -29,7 +29,16 @@ typedef struct __attribute__((packed)) { | |||
| bool wifiValid; | |||
| LEDModes mode; | |||
| uint8_t brightness; | |||
| RGBWColor color; | |||
| RGBWColor singleColor; | |||
| RGBWColor segmentColor1; | |||
| RGBWColor segmentColor2; | |||
| RGBWColor segmentColor3; | |||
| uint32_t rainbowDelay; | |||
| uint32_t spectralStepTime; | |||
| uint32_t fadingHoldTime; | |||
| uint32_t fadingFadeTime; | |||
| uint32_t flashOnTime; | |||
| uint32_t flashOffTime; | |||
| } Config; | |||
| class ConfigManager { | |||
| @@ -42,6 +51,8 @@ class ConfigManager { | |||
| bool saveConfig(const Config &config); | |||
| void resetConfig(); | |||
| Config& setToDefaultConfig(); | |||
| Config& setToDefaultWiFiConfig(Config &config); | |||
| Config& setToDefaultLEDConfig(Config &config); | |||
| Config& getConfig(); | |||
| private: | |||
| @@ -52,12 +52,7 @@ void handleSave() { | |||
| pass.toCharArray(cfg.pass, sizeof(cfg.pass)); | |||
| cfg.wifiValid = true; | |||
| cfg.version = CONFIG_VERSION; | |||
| cfg.mode = LM_SINGLE_COLOR; | |||
| cfg.color.r = 0; | |||
| cfg.color.g = 0; | |||
| cfg.color.b = 0; | |||
| cfg.color.w = 255; | |||
| cfg.brightness = 128; | |||
| cfg = configManager.setToDefaultLEDConfig(cfg); | |||
| configManager.saveConfig(cfg); | |||
| webServer.send(200, "text/html", getConnectionSuccessPage()); | |||
| @@ -45,7 +45,7 @@ void LEDStripManager::begin() { | |||
| switch (cfg.mode) { | |||
| case LM_SINGLE_COLOR: | |||
| this->setBrightness(cfg.brightness); | |||
| setAll(cfg.color.r, cfg.color.g, cfg.color.b, cfg.color.w); | |||
| setAll(cfg.singleColor.r, cfg.singleColor.g, cfg.singleColor.b, cfg.singleColor.w); | |||
| return; | |||
| case LM_SEGMENTS: | |||
| this->setBrightness(cfg.brightness); | |||
| @@ -115,7 +115,7 @@ void LEDStripManager::onModeChange(LEDModes mode) { | |||
| switch (mode) { | |||
| case LM_SINGLE_COLOR: | |||
| this->setBrightness(cfg.brightness); | |||
| setAll(cfg.color.r, cfg.color.g, cfg.color.b, cfg.color.w); | |||
| setAll(cfg.singleColor.r, cfg.singleColor.g, cfg.singleColor.b, cfg.singleColor.w); | |||
| return; | |||
| case LM_SEGMENTS: | |||
| this->setBrightness(cfg.brightness); | |||
| @@ -128,10 +128,10 @@ void LEDStripManager::onModeChange(LEDModes mode) { | |||
| void LEDStripManager::onColorChange(uint8_t red, uint8_t green, uint8_t blue, uint8_t white) { | |||
| Config cfg = configManager.getConfig(); | |||
| cfg.color.r = red; | |||
| cfg.color.g = green; | |||
| cfg.color.b = blue; | |||
| cfg.color.w = white; | |||
| cfg.singleColor.r = red; | |||
| cfg.singleColor.g = green; | |||
| cfg.singleColor.b = blue; | |||
| cfg.singleColor.w = white; | |||
| configManager.saveConfig(cfg); | |||
| this->setAll(red, green, blue, white); | |||
| @@ -146,16 +146,22 @@ void LEDStripManager::onBrightnessChange(uint8_t brightness) { | |||
| } | |||
| void LEDStripManager::setSegments() { | |||
| Config cfg = configManager.getConfig(); | |||
| RGBWColor c1 = cfg.segmentColor1; | |||
| RGBWColor c2 = cfg.segmentColor2; | |||
| RGBWColor c3 = cfg.segmentColor3; | |||
| int nbrPixel = strip.numPixels(); | |||
| int third = nbrPixel / 3; | |||
| for (int i = 0; i < nbrPixel; i++) { | |||
| if (i < third) | |||
| setPixel(i, 255, 0, 0, 0); | |||
| setPixel(i, c1.r, c1.g, c1.b, c1.w); | |||
| else if (i < 2 * third) | |||
| setPixel(i, 0, 255, 0, 0); | |||
| setPixel(i, c2.r, c2.g, c2.b, c2.w); | |||
| else | |||
| setPixel(i, 0, 0, 255, 0); | |||
| setPixel(i, c3.r, c3.g, c3.b, c3.w); | |||
| } | |||
| show(); | |||
| } | |||
| @@ -179,7 +185,9 @@ uint32_t LEDStripManager::wheel(uint8_t pos) { | |||
| void LEDStripManager::rainbow() { | |||
| static uint8_t delay = 20; | |||
| Config cfg = configManager.getConfig(); | |||
| const uint32_t delay = cfg.rainbowDelay; | |||
| static uint32_t lastUpdate = 0; | |||
| if (digitalRead(LED_STRIP_POWER_PIN) == HIGH) { | |||
| @@ -200,12 +208,15 @@ void LEDStripManager::rainbow() { | |||
| } | |||
| } | |||
| void LEDStripManager::doSpectral() { | |||
| Config cfg = configManager.getConfig(); | |||
| static uint16_t hue = 0; | |||
| static uint32_t lastUpdate = 0; | |||
| const uint32_t stepTime = 10000; // 5 s bis zur nächsten Farbe | |||
| const uint16_t hueStep = 65536 / 6; // Abstand der Hauptfarben | |||
| const uint32_t stepTime = cfg.spectralStepTime; // Zeit bis zur nächsten Farbe | |||
| if (digitalRead(LED_STRIP_POWER_PIN) == HIGH) { | |||
| @@ -245,17 +256,17 @@ void LEDStripManager::fade() { | |||
| FADE_IN | |||
| }; | |||
| Config cfg = configManager.getConfig(); | |||
| static State state = HOLD; | |||
| static uint8_t currentColor = 0; | |||
| static uint32_t stateStart = millis(); | |||
| const uint32_t holdTime = 5000; | |||
| const uint32_t fadeTime = 1000; | |||
| const uint32_t holdTime = cfg.fadingHoldTime; | |||
| const uint32_t fadeTime = cfg.fadingFadeTime; | |||
| if (digitalRead(LED_STRIP_POWER_PIN) == HIGH) { | |||
| Config cfg = configManager.getConfig(); | |||
| uint32_t now = millis(); | |||
| uint32_t elapsed = now - stateStart; | |||
| @@ -310,8 +321,10 @@ void LEDStripManager::fade() { | |||
| void LEDStripManager::flash() { | |||
| static const uint32_t onMillis = 1000; | |||
| static const uint32_t offMillis = 500; | |||
| Config cfg = configManager.getConfig(); | |||
| static const uint32_t onMillis = cfg.flashOnTime; | |||
| static const uint32_t offMillis = cfg.flashOffTime; | |||
| static bool ledOn = false; | |||
| static uint32_t lastChange = 0; | |||
| @@ -332,7 +345,7 @@ void LEDStripManager::flash() { | |||
| } else { | |||
| if (now - lastChange >= offMillis) { | |||
| // LEDs einschalten | |||
| setAll(cfg.color.r, cfg.color.g, cfg.color.b, cfg.color.w); | |||
| setAll(cfg.singleColor.r, cfg.singleColor.g, cfg.singleColor.b, cfg.singleColor.w); | |||
| ledOn = true; | |||
| lastChange = now; | |||
| } | |||
| @@ -2,7 +2,7 @@ | |||
| //This is a automatic generated file | |||
| //Please do not modify this file | |||
| //If you touch this file your change will be overwritten during the next build | |||
| //This file has been generated on 2026-06-29 10:34:17 | |||
| //This file has been generated on 2026-06-29 13:40:40 | |||
| #include "Arduino.h" | |||
| #include "Arduino.h" | |||