| @@ -29,6 +29,7 @@ | |||
| <listOptionValue builtIn="false" value=""${workspace_loc:/LEDLamp/libraries/ESP8266WiFi/src}""/> | |||
| <listOptionValue builtIn="false" value=""${workspace_loc:/LEDLamp/libraries/ArduinoJson/src}""/> | |||
| <listOptionValue builtIn="false" value=""${workspace_loc:/LEDLamp/libraries/Adafruit_NeoPixel}""/> | |||
| <listOptionValue builtIn="false" value=""${workspace_loc:/LEDLamp/libraries/NTPClient}""/> | |||
| </option> | |||
| <inputType id="io.sloeber.compiler.cpp.sketch.input.1770649762" name="CPP source files" superClass="io.sloeber.compiler.cpp.sketch.input"/> | |||
| </tool> | |||
| @@ -44,6 +45,7 @@ | |||
| <listOptionValue builtIn="false" value=""${workspace_loc:/LEDLamp/libraries/ESP8266WiFi/src}""/> | |||
| <listOptionValue builtIn="false" value=""${workspace_loc:/LEDLamp/libraries/ArduinoJson/src}""/> | |||
| <listOptionValue builtIn="false" value=""${workspace_loc:/LEDLamp/libraries/Adafruit_NeoPixel}""/> | |||
| <listOptionValue builtIn="false" value=""${workspace_loc:/LEDLamp/libraries/NTPClient}""/> | |||
| </option> | |||
| <inputType id="io.sloeber.compiler.c.sketch.input.1705705" name="C Source Files" superClass="io.sloeber.compiler.c.sketch.input"/> | |||
| </tool> | |||
| @@ -59,6 +61,7 @@ | |||
| <listOptionValue builtIn="false" value=""${workspace_loc:/LEDLamp/libraries/ESP8266WiFi/src}""/> | |||
| <listOptionValue builtIn="false" value=""${workspace_loc:/LEDLamp/libraries/ArduinoJson/src}""/> | |||
| <listOptionValue builtIn="false" value=""${workspace_loc:/LEDLamp/libraries/Adafruit_NeoPixel}""/> | |||
| <listOptionValue builtIn="false" value=""${workspace_loc:/LEDLamp/libraries/NTPClient}""/> | |||
| </option> | |||
| <inputType id="io.sloeber.compiler.S.sketch.input.1190005390" name="Assembly source files" superClass="io.sloeber.compiler.S.sketch.input"/> | |||
| </tool> | |||
| @@ -76,6 +76,11 @@ | |||
| <type>2</type> | |||
| <locationURI>ECLIPSE_HOME/arduinoPlugin/packages/esp8266/hardware/esp8266/3.1.2/libraries/Hash</locationURI> | |||
| </link> | |||
| <link> | |||
| <name>libraries/NTPClient</name> | |||
| <type>2</type> | |||
| <locationURI>ECLIPSE_HOME/arduinoPlugin/libraries/NTPClient/3.2.1</locationURI> | |||
| </link> | |||
| <link> | |||
| <name>libraries/WebSockets</name> | |||
| <type>2</type> | |||
| @@ -15,6 +15,7 @@ enum Commands { | |||
| CMD_CHG_COLOR, | |||
| CMD_CHG_BRIGHTNESS, | |||
| CMD_CHG_CFG_PARAM, | |||
| CMD_CHG_TIMER_INTERVAL, | |||
| CMD_RESET_WIFI_CFG, | |||
| CMD_GET_CONFIG, | |||
| CMD_ESP_RESTART | |||
| @@ -32,6 +33,8 @@ static const char* cmdToString(Commands cmd) { | |||
| return "CHG_BRIGHTNESS"; | |||
| case CMD_CHG_CFG_PARAM: | |||
| return "CHG_CFG_PARAM"; | |||
| case CMD_CHG_TIMER_INTERVAL: | |||
| return "CHG_TIMER_INTERVAL"; | |||
| case CMD_RESET_WIFI_CFG: | |||
| return "RESET_WIFI_CFG"; | |||
| case CMD_GET_CONFIG: | |||
| @@ -58,6 +61,8 @@ static Commands strToCommand(const char *cmd) { | |||
| return CMD_CHG_BRIGHTNESS; | |||
| if (strcmp(cmd, "CHG_CFG_PARAM") == 0) | |||
| return CMD_CHG_CFG_PARAM; | |||
| if (strcmp(cmd, "CHG_TIMER_INTERVAL") == 0) | |||
| return CMD_CHG_TIMER_INTERVAL; | |||
| if (strcmp(cmd, "RESET_WIFI_CFG") == 0) | |||
| return CMD_RESET_WIFI_CFG; | |||
| if (strcmp(cmd, "GET_CONFIG") == 0) | |||
| @@ -51,13 +51,10 @@ Config& ConfigManager::setToDefaultConfig() { | |||
| memset(&_config, 0, sizeof(Config)); | |||
| _config.version = CONFIG_VERSION; | |||
| _config = setToDefaultWiFiConfig(_config); | |||
| _config = setToDefaultLEDConfig(_config); | |||
| EEPROM.begin(sizeof(Config)); | |||
| EEPROM.put(0, _config); | |||
| EEPROM.commit(); | |||
| _config = setToDefaultTimerConfig(_config); | |||
| saveConfig(_config); | |||
| return _config; | |||
| } | |||
| @@ -109,6 +106,15 @@ Config& ConfigManager::setToDefaultLEDConfig(Config &config) { | |||
| return config; | |||
| } | |||
| Config& ConfigManager::setToDefaultTimerConfig(Config &config) { | |||
| config.timeInterval1.start = 0; | |||
| config.timeInterval1.end = 0; | |||
| config.timeInterval2.start = 0; | |||
| config.timeInterval2.end = 0; | |||
| return config; | |||
| } | |||
| Config& ConfigManager::getConfig() { | |||
| return _config; | |||
| } | |||
| @@ -134,6 +140,9 @@ void ConfigManager::getConfig(JsonDocument &doc) { | |||
| doc["fadingFadeTime"] = _config.fadingFadeTime; | |||
| doc["flashOnTime"] = _config.flashOnTime; | |||
| doc["flashOffTime"] = _config.flashOffTime; | |||
| timeIntervalToJson(_config.timeInterval1, doc["timeInterval1"].to<JsonObject>()); | |||
| timeIntervalToJson(_config.timeInterval2, doc["timeInterval2"].to<JsonObject>()); | |||
| } | |||
| void ConfigManager::rgbwToJson(const RGBWColor &c, JsonObject obj) { | |||
| @@ -142,3 +151,8 @@ void ConfigManager::rgbwToJson(const RGBWColor &c, JsonObject obj) { | |||
| obj["b"] = c.b; | |||
| obj["w"] = c.w; | |||
| } | |||
| void ConfigManager::timeIntervalToJson(const TimeInterval &ti, JsonObject obj) { | |||
| obj["start"] = ti.start; | |||
| obj["end"] = ti.end; | |||
| } | |||
| @@ -13,7 +13,7 @@ | |||
| #include <EEPROM.h> | |||
| #include "LEDModes.h" | |||
| #define CONFIG_VERSION 3 | |||
| #define CONFIG_VERSION 4 | |||
| typedef struct __attribute__((packed)) { | |||
| uint8_t r; | |||
| @@ -22,6 +22,11 @@ typedef struct __attribute__((packed)) { | |||
| uint8_t w; | |||
| } RGBWColor; | |||
| typedef struct __attribute__((packed)) { | |||
| uint32_t start; // Sekunden seit 00:00:00 | |||
| uint32_t end; | |||
| } TimeInterval; | |||
| typedef struct __attribute__((packed)) { | |||
| uint8_t version; | |||
| @@ -40,6 +45,9 @@ typedef struct __attribute__((packed)) { | |||
| uint32_t fadingFadeTime; | |||
| uint32_t flashOnTime; | |||
| uint32_t flashOffTime; | |||
| TimeInterval timeInterval1; | |||
| TimeInterval timeInterval2; | |||
| } Config; | |||
| class ConfigManager { | |||
| @@ -54,14 +62,15 @@ class ConfigManager { | |||
| Config& setToDefaultConfig(); | |||
| Config& setToDefaultWiFiConfig(Config &config); | |||
| Config& setToDefaultLEDConfig(Config &config); | |||
| Config& setToDefaultTimerConfig(Config &config); | |||
| Config& getConfig(); | |||
| void getConfig(JsonDocument &doc); | |||
| private: | |||
| Config _config; | |||
| void rgbwToJson(const RGBWColor &c, JsonObject obj); | |||
| void timeIntervalToJson(const TimeInterval &ti, JsonObject obj); | |||
| }; | |||
| #endif /* CONFIGMANAGER_H_ */ | |||
| @@ -10,6 +10,7 @@ | |||
| #include "ConfigManager.h" | |||
| #include "HtmlPages.h" | |||
| #include "LEDStripManager.h" | |||
| #include "TimerManager.h" | |||
| AppState state = STATE_BOOT; | |||
| #define LED_COUNT 12 // Nbr of LEDs on stripe TODO: move to eeprom, configurable over wifi | |||
| @@ -26,6 +27,7 @@ WebSocketsServer webSocket(81); | |||
| DNSServer dnsServer; | |||
| ConfigManager configManager; | |||
| LEDStripManager ledMngr(LED_COUNT, LED_STRIP_DATA_PIN, configManager); | |||
| TimerManager timerManager(configManager); | |||
| // ---------- CAPTIVE PORTAL PAGE ---------- | |||
| void handleSetupPage() { | |||
| @@ -44,6 +46,10 @@ void handleSTAControlPage() { | |||
| // ---------- SAVE ---------- | |||
| void handleSave() { | |||
| Config cfg; | |||
| cfg.version = CONFIG_VERSION; | |||
| cfg = configManager.setToDefaultWiFiConfig(cfg); | |||
| cfg = configManager.setToDefaultLEDConfig(cfg); | |||
| cfg = configManager.setToDefaultTimerConfig(cfg); | |||
| String ssid = webServer.arg("ssid"); | |||
| String pass = webServer.arg("pass"); | |||
| @@ -51,8 +57,6 @@ void handleSave() { | |||
| ssid.toCharArray(cfg.ssid, sizeof(cfg.ssid)); | |||
| pass.toCharArray(cfg.pass, sizeof(cfg.pass)); | |||
| cfg.wifiValid = true; | |||
| cfg.version = CONFIG_VERSION; | |||
| cfg = configManager.setToDefaultLEDConfig(cfg); | |||
| configManager.saveConfig(cfg); | |||
| webServer.send(200, "text/html", getConnectionSuccessPage()); | |||
| @@ -174,6 +178,10 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t *payload, size_t length) | |||
| if (sscanf(amount, "%u", &amountVal) == 1) { | |||
| ledMngr.onCfgParamChange(value, amountVal); | |||
| } | |||
| } else if (strToCommand(cmd) == CMD_CHG_TIMER_INTERVAL) { | |||
| const char *interval = doc["interval"]; | |||
| const char *timerange = doc["timerange"]; | |||
| timerManager.onTimerIntervalChange(interval, timerange); | |||
| } else if (strToCommand(cmd) == CMD_RESET_WIFI_CFG) { | |||
| resetWifiConfiguration(num); | |||
| @@ -13,51 +13,32 @@ class LEDStripManager { | |||
| public: | |||
| LEDStripManager(uint16_t numLeds, uint8_t pin, ConfigManager &configManager); | |||
| virtual ~LEDStripManager(); | |||
| void begin(); | |||
| void clear(); | |||
| void show(); | |||
| void on(); | |||
| void off(); | |||
| void setBrightness(uint8_t brightness); | |||
| void setPixel(uint16_t index, uint8_t red, uint8_t green, uint8_t blue, uint8_t white); | |||
| void setAll(uint8_t red, uint8_t green, uint8_t blue, uint8_t white); | |||
| void rainbow(); | |||
| void setSegments(); | |||
| void flash(); | |||
| void doSpectral(); | |||
| void fade(); | |||
| void onModeChange(LEDModes mode); | |||
| void onColorChange(String cfgVal, uint8_t red, uint8_t green, uint8_t blue, uint8_t white); | |||
| void onBrightnessChange(uint8_t brightness); | |||
| void onCfgParamChange(String cfgVal, uint32_t amount); | |||
| private: | |||
| Adafruit_NeoPixel strip; | |||
| uint32_t firstPixelHue = 0; | |||
| ConfigManager &configManager; | |||
| uint32_t wheel(uint8_t pos); | |||
| uint32_t firstPixelHue = 0; | |||
| }; | |||
| #endif | |||
| @@ -0,0 +1,63 @@ | |||
| /* | |||
| * TimerManager.cpp | |||
| * | |||
| * Created on: 12.07.2026 | |||
| * Author: FSmilari | |||
| */ | |||
| #include "TimerManager.h" | |||
| #include "ConfigManager.h" | |||
| TimerManager::TimerManager(ConfigManager &configManager) : configManager(configManager) { | |||
| } | |||
| TimerManager::~TimerManager() { | |||
| } | |||
| void TimerManager::onTimerIntervalChange(String timerIntervalName, const char *timerInterval) { | |||
| TimeInterval interval; | |||
| parseTimeInterval(timerInterval, interval); | |||
| saveTimerInterval(timerIntervalName, interval.start, interval.end); | |||
| } | |||
| void TimerManager::saveTimerInterval(String timerIntervalName, uint32_t start, uint32_t end) { | |||
| Config cfg = configManager.getConfig(); | |||
| if (timerIntervalName.equals("timeInterval1")) { | |||
| cfg.timeInterval1.start = start; | |||
| cfg.timeInterval1.end = end; | |||
| } else if (timerIntervalName.equals("timeInterval2")) { | |||
| cfg.timeInterval2.start = start; | |||
| cfg.timeInterval2.end = end; | |||
| } | |||
| configManager.saveConfig(cfg); | |||
| } | |||
| uint32_t TimerManager::timeToSeconds(uint8_t hour, uint8_t minute, uint8_t second) { | |||
| return (uint32_t) hour * 3600UL + | |||
| (uint32_t) minute * 60UL + | |||
| second; | |||
| } | |||
| bool TimerManager::parseTimeInterval(const char *str, TimeInterval &interval) { | |||
| unsigned int sh, sm, ss; | |||
| unsigned int eh, em, es; | |||
| if (sscanf(str, | |||
| "%u:%u:%u - %u:%u:%u", | |||
| &sh, &sm, &ss, | |||
| &eh, &em, &es) != 6) { | |||
| return false; | |||
| } | |||
| // Bereich prüfen | |||
| if (sh > 23 || eh > 23 || | |||
| sm > 59 || em > 59 || | |||
| ss > 59 || es > 59) { | |||
| return false; | |||
| } | |||
| interval.start = timeToSeconds(sh, sm, ss); | |||
| interval.end = timeToSeconds(eh, em, es); | |||
| return true; | |||
| } | |||
| @@ -0,0 +1,32 @@ | |||
| /* | |||
| * TimerManager.h | |||
| * | |||
| * Created on: 12.07.2026 | |||
| * Author: FSmilari | |||
| */ | |||
| #ifndef TIMERMANAGER_H_ | |||
| #define TIMERMANAGER_H_ | |||
| #include "ConfigManager.h" | |||
| class TimerManager { | |||
| public: | |||
| TimerManager(ConfigManager &configManager); | |||
| virtual ~TimerManager(); | |||
| void onTimerIntervalChange(String timerIntervalName, const char *timerInterval); | |||
| void saveTimerInterval(String timerIntervalName, uint32_t start, uint32_t end); | |||
| private: | |||
| ConfigManager &configManager; | |||
| uint32_t timeToSeconds(uint8_t hour, uint8_t minute, uint8_t second); | |||
| bool parseTimeInterval(const char *str, TimeInterval &interval); | |||
| }; | |||
| #endif /* TIMERMANAGER_H_ */ | |||
| @@ -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 16:12:29 | |||
| //This file has been generated on 2026-07-12 21:54:14 | |||
| #include "Arduino.h" | |||
| #include "Arduino.h" | |||
| @@ -17,6 +17,7 @@ | |||
| #include "ConfigManager.h" | |||
| #include "HtmlPages.h" | |||
| #include "LEDStripManager.h" | |||
| #include "TimerManager.h" | |||
| void handleSetupPage() ; | |||
| void handleSTAControlPage() ; | |||