| <listOptionValue builtIn="false" value=""${workspace_loc:/LEDLamp/libraries/ESP8266WiFi/src}""/> | <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/ArduinoJson/src}""/> | ||||
| <listOptionValue builtIn="false" value=""${workspace_loc:/LEDLamp/libraries/Adafruit_NeoPixel}""/> | <listOptionValue builtIn="false" value=""${workspace_loc:/LEDLamp/libraries/Adafruit_NeoPixel}""/> | ||||
| <listOptionValue builtIn="false" value=""${workspace_loc:/LEDLamp/libraries/NTPClient}""/> | |||||
| </option> | </option> | ||||
| <inputType id="io.sloeber.compiler.cpp.sketch.input.1770649762" name="CPP source files" superClass="io.sloeber.compiler.cpp.sketch.input"/> | <inputType id="io.sloeber.compiler.cpp.sketch.input.1770649762" name="CPP source files" superClass="io.sloeber.compiler.cpp.sketch.input"/> | ||||
| </tool> | </tool> | ||||
| <listOptionValue builtIn="false" value=""${workspace_loc:/LEDLamp/libraries/ESP8266WiFi/src}""/> | <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/ArduinoJson/src}""/> | ||||
| <listOptionValue builtIn="false" value=""${workspace_loc:/LEDLamp/libraries/Adafruit_NeoPixel}""/> | <listOptionValue builtIn="false" value=""${workspace_loc:/LEDLamp/libraries/Adafruit_NeoPixel}""/> | ||||
| <listOptionValue builtIn="false" value=""${workspace_loc:/LEDLamp/libraries/NTPClient}""/> | |||||
| </option> | </option> | ||||
| <inputType id="io.sloeber.compiler.c.sketch.input.1705705" name="C Source Files" superClass="io.sloeber.compiler.c.sketch.input"/> | <inputType id="io.sloeber.compiler.c.sketch.input.1705705" name="C Source Files" superClass="io.sloeber.compiler.c.sketch.input"/> | ||||
| </tool> | </tool> | ||||
| <listOptionValue builtIn="false" value=""${workspace_loc:/LEDLamp/libraries/ESP8266WiFi/src}""/> | <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/ArduinoJson/src}""/> | ||||
| <listOptionValue builtIn="false" value=""${workspace_loc:/LEDLamp/libraries/Adafruit_NeoPixel}""/> | <listOptionValue builtIn="false" value=""${workspace_loc:/LEDLamp/libraries/Adafruit_NeoPixel}""/> | ||||
| <listOptionValue builtIn="false" value=""${workspace_loc:/LEDLamp/libraries/NTPClient}""/> | |||||
| </option> | </option> | ||||
| <inputType id="io.sloeber.compiler.S.sketch.input.1190005390" name="Assembly source files" superClass="io.sloeber.compiler.S.sketch.input"/> | <inputType id="io.sloeber.compiler.S.sketch.input.1190005390" name="Assembly source files" superClass="io.sloeber.compiler.S.sketch.input"/> | ||||
| </tool> | </tool> |
| <type>2</type> | <type>2</type> | ||||
| <locationURI>ECLIPSE_HOME/arduinoPlugin/packages/esp8266/hardware/esp8266/3.1.2/libraries/Hash</locationURI> | <locationURI>ECLIPSE_HOME/arduinoPlugin/packages/esp8266/hardware/esp8266/3.1.2/libraries/Hash</locationURI> | ||||
| </link> | </link> | ||||
| <link> | |||||
| <name>libraries/NTPClient</name> | |||||
| <type>2</type> | |||||
| <locationURI>ECLIPSE_HOME/arduinoPlugin/libraries/NTPClient/3.2.1</locationURI> | |||||
| </link> | |||||
| <link> | <link> | ||||
| <name>libraries/WebSockets</name> | <name>libraries/WebSockets</name> | ||||
| <type>2</type> | <type>2</type> |
| CMD_CHG_COLOR, | CMD_CHG_COLOR, | ||||
| CMD_CHG_BRIGHTNESS, | CMD_CHG_BRIGHTNESS, | ||||
| CMD_CHG_CFG_PARAM, | CMD_CHG_CFG_PARAM, | ||||
| CMD_CHG_TIMER_INTERVAL, | |||||
| CMD_RESET_WIFI_CFG, | CMD_RESET_WIFI_CFG, | ||||
| CMD_GET_CONFIG, | CMD_GET_CONFIG, | ||||
| CMD_ESP_RESTART | CMD_ESP_RESTART | ||||
| return "CHG_BRIGHTNESS"; | return "CHG_BRIGHTNESS"; | ||||
| case CMD_CHG_CFG_PARAM: | case CMD_CHG_CFG_PARAM: | ||||
| return "CHG_CFG_PARAM"; | return "CHG_CFG_PARAM"; | ||||
| case CMD_CHG_TIMER_INTERVAL: | |||||
| return "CHG_TIMER_INTERVAL"; | |||||
| case CMD_RESET_WIFI_CFG: | case CMD_RESET_WIFI_CFG: | ||||
| return "RESET_WIFI_CFG"; | return "RESET_WIFI_CFG"; | ||||
| case CMD_GET_CONFIG: | case CMD_GET_CONFIG: | ||||
| return CMD_CHG_BRIGHTNESS; | return CMD_CHG_BRIGHTNESS; | ||||
| if (strcmp(cmd, "CHG_CFG_PARAM") == 0) | if (strcmp(cmd, "CHG_CFG_PARAM") == 0) | ||||
| return CMD_CHG_CFG_PARAM; | return CMD_CHG_CFG_PARAM; | ||||
| if (strcmp(cmd, "CHG_TIMER_INTERVAL") == 0) | |||||
| return CMD_CHG_TIMER_INTERVAL; | |||||
| if (strcmp(cmd, "RESET_WIFI_CFG") == 0) | if (strcmp(cmd, "RESET_WIFI_CFG") == 0) | ||||
| return CMD_RESET_WIFI_CFG; | return CMD_RESET_WIFI_CFG; | ||||
| if (strcmp(cmd, "GET_CONFIG") == 0) | if (strcmp(cmd, "GET_CONFIG") == 0) |
| memset(&_config, 0, sizeof(Config)); | memset(&_config, 0, sizeof(Config)); | ||||
| _config.version = CONFIG_VERSION; | _config.version = CONFIG_VERSION; | ||||
| _config = setToDefaultWiFiConfig(_config); | _config = setToDefaultWiFiConfig(_config); | ||||
| _config = setToDefaultLEDConfig(_config); | _config = setToDefaultLEDConfig(_config); | ||||
| EEPROM.begin(sizeof(Config)); | |||||
| EEPROM.put(0, _config); | |||||
| EEPROM.commit(); | |||||
| _config = setToDefaultTimerConfig(_config); | |||||
| saveConfig(_config); | |||||
| return _config; | return _config; | ||||
| } | } | ||||
| return 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() { | Config& ConfigManager::getConfig() { | ||||
| return _config; | return _config; | ||||
| } | } | ||||
| doc["fadingFadeTime"] = _config.fadingFadeTime; | doc["fadingFadeTime"] = _config.fadingFadeTime; | ||||
| doc["flashOnTime"] = _config.flashOnTime; | doc["flashOnTime"] = _config.flashOnTime; | ||||
| doc["flashOffTime"] = _config.flashOffTime; | 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) { | void ConfigManager::rgbwToJson(const RGBWColor &c, JsonObject obj) { | ||||
| obj["b"] = c.b; | obj["b"] = c.b; | ||||
| obj["w"] = c.w; | obj["w"] = c.w; | ||||
| } | } | ||||
| void ConfigManager::timeIntervalToJson(const TimeInterval &ti, JsonObject obj) { | |||||
| obj["start"] = ti.start; | |||||
| obj["end"] = ti.end; | |||||
| } |
| #include <EEPROM.h> | #include <EEPROM.h> | ||||
| #include "LEDModes.h" | #include "LEDModes.h" | ||||
| #define CONFIG_VERSION 3 | |||||
| #define CONFIG_VERSION 4 | |||||
| typedef struct __attribute__((packed)) { | typedef struct __attribute__((packed)) { | ||||
| uint8_t r; | uint8_t r; | ||||
| uint8_t w; | uint8_t w; | ||||
| } RGBWColor; | } RGBWColor; | ||||
| typedef struct __attribute__((packed)) { | |||||
| uint32_t start; // Sekunden seit 00:00:00 | |||||
| uint32_t end; | |||||
| } TimeInterval; | |||||
| typedef struct __attribute__((packed)) { | typedef struct __attribute__((packed)) { | ||||
| uint8_t version; | uint8_t version; | ||||
| uint32_t fadingFadeTime; | uint32_t fadingFadeTime; | ||||
| uint32_t flashOnTime; | uint32_t flashOnTime; | ||||
| uint32_t flashOffTime; | uint32_t flashOffTime; | ||||
| TimeInterval timeInterval1; | |||||
| TimeInterval timeInterval2; | |||||
| } Config; | } Config; | ||||
| class ConfigManager { | class ConfigManager { | ||||
| Config& setToDefaultConfig(); | Config& setToDefaultConfig(); | ||||
| Config& setToDefaultWiFiConfig(Config &config); | Config& setToDefaultWiFiConfig(Config &config); | ||||
| Config& setToDefaultLEDConfig(Config &config); | Config& setToDefaultLEDConfig(Config &config); | ||||
| Config& setToDefaultTimerConfig(Config &config); | |||||
| Config& getConfig(); | Config& getConfig(); | ||||
| void getConfig(JsonDocument &doc); | void getConfig(JsonDocument &doc); | ||||
| private: | private: | ||||
| Config _config; | Config _config; | ||||
| void rgbwToJson(const RGBWColor &c, JsonObject obj); | void rgbwToJson(const RGBWColor &c, JsonObject obj); | ||||
| void timeIntervalToJson(const TimeInterval &ti, JsonObject obj); | |||||
| }; | }; | ||||
| #endif /* CONFIGMANAGER_H_ */ | #endif /* CONFIGMANAGER_H_ */ |
| #include "ConfigManager.h" | #include "ConfigManager.h" | ||||
| #include "HtmlPages.h" | #include "HtmlPages.h" | ||||
| #include "LEDStripManager.h" | #include "LEDStripManager.h" | ||||
| #include "TimerManager.h" | |||||
| AppState state = STATE_BOOT; | AppState state = STATE_BOOT; | ||||
| #define LED_COUNT 12 // Nbr of LEDs on stripe TODO: move to eeprom, configurable over wifi | #define LED_COUNT 12 // Nbr of LEDs on stripe TODO: move to eeprom, configurable over wifi | ||||
| DNSServer dnsServer; | DNSServer dnsServer; | ||||
| ConfigManager configManager; | ConfigManager configManager; | ||||
| LEDStripManager ledMngr(LED_COUNT, LED_STRIP_DATA_PIN, configManager); | LEDStripManager ledMngr(LED_COUNT, LED_STRIP_DATA_PIN, configManager); | ||||
| TimerManager timerManager(configManager); | |||||
| // ---------- CAPTIVE PORTAL PAGE ---------- | // ---------- CAPTIVE PORTAL PAGE ---------- | ||||
| void handleSetupPage() { | void handleSetupPage() { | ||||
| // ---------- SAVE ---------- | // ---------- SAVE ---------- | ||||
| void handleSave() { | void handleSave() { | ||||
| Config cfg; | Config cfg; | ||||
| cfg.version = CONFIG_VERSION; | |||||
| cfg = configManager.setToDefaultWiFiConfig(cfg); | |||||
| cfg = configManager.setToDefaultLEDConfig(cfg); | |||||
| cfg = configManager.setToDefaultTimerConfig(cfg); | |||||
| String ssid = webServer.arg("ssid"); | String ssid = webServer.arg("ssid"); | ||||
| String pass = webServer.arg("pass"); | String pass = webServer.arg("pass"); | ||||
| ssid.toCharArray(cfg.ssid, sizeof(cfg.ssid)); | ssid.toCharArray(cfg.ssid, sizeof(cfg.ssid)); | ||||
| pass.toCharArray(cfg.pass, sizeof(cfg.pass)); | pass.toCharArray(cfg.pass, sizeof(cfg.pass)); | ||||
| cfg.wifiValid = true; | cfg.wifiValid = true; | ||||
| cfg.version = CONFIG_VERSION; | |||||
| cfg = configManager.setToDefaultLEDConfig(cfg); | |||||
| configManager.saveConfig(cfg); | configManager.saveConfig(cfg); | ||||
| webServer.send(200, "text/html", getConnectionSuccessPage()); | webServer.send(200, "text/html", getConnectionSuccessPage()); | ||||
| if (sscanf(amount, "%u", &amountVal) == 1) { | if (sscanf(amount, "%u", &amountVal) == 1) { | ||||
| ledMngr.onCfgParamChange(value, amountVal); | 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) { | } else if (strToCommand(cmd) == CMD_RESET_WIFI_CFG) { | ||||
| resetWifiConfiguration(num); | resetWifiConfiguration(num); |
| public: | public: | ||||
| LEDStripManager(uint16_t numLeds, uint8_t pin, ConfigManager &configManager); | LEDStripManager(uint16_t numLeds, uint8_t pin, ConfigManager &configManager); | ||||
| virtual ~LEDStripManager(); | virtual ~LEDStripManager(); | ||||
| void begin(); | void begin(); | ||||
| void clear(); | void clear(); | ||||
| void show(); | void show(); | ||||
| void on(); | void on(); | ||||
| void off(); | void off(); | ||||
| void setBrightness(uint8_t brightness); | void setBrightness(uint8_t brightness); | ||||
| void setPixel(uint16_t index, uint8_t red, uint8_t green, uint8_t blue, uint8_t white); | 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 setAll(uint8_t red, uint8_t green, uint8_t blue, uint8_t white); | ||||
| void rainbow(); | void rainbow(); | ||||
| void setSegments(); | void setSegments(); | ||||
| void flash(); | void flash(); | ||||
| void doSpectral(); | void doSpectral(); | ||||
| void fade(); | void fade(); | ||||
| void onModeChange(LEDModes mode); | void onModeChange(LEDModes mode); | ||||
| void onColorChange(String cfgVal, uint8_t red, uint8_t green, uint8_t blue, uint8_t white); | void onColorChange(String cfgVal, uint8_t red, uint8_t green, uint8_t blue, uint8_t white); | ||||
| void onBrightnessChange(uint8_t brightness); | void onBrightnessChange(uint8_t brightness); | ||||
| void onCfgParamChange(String cfgVal, uint32_t amount); | void onCfgParamChange(String cfgVal, uint32_t amount); | ||||
| private: | private: | ||||
| Adafruit_NeoPixel strip; | Adafruit_NeoPixel strip; | ||||
| uint32_t firstPixelHue = 0; | |||||
| ConfigManager &configManager; | ConfigManager &configManager; | ||||
| uint32_t wheel(uint8_t pos); | uint32_t wheel(uint8_t pos); | ||||
| uint32_t firstPixelHue = 0; | |||||
| }; | }; | ||||
| #endif | #endif |
| /* | |||||
| * 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; | |||||
| } |
| /* | |||||
| * 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_ */ |
| //This is a automatic generated file | //This is a automatic generated file | ||||
| //Please do not modify this file | //Please do not modify this file | ||||
| //If you touch this file your change will be overwritten during the next build | //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" | ||||
| #include "Arduino.h" | #include "Arduino.h" | ||||
| #include "ConfigManager.h" | #include "ConfigManager.h" | ||||
| #include "HtmlPages.h" | #include "HtmlPages.h" | ||||
| #include "LEDStripManager.h" | #include "LEDStripManager.h" | ||||
| #include "TimerManager.h" | |||||
| void handleSetupPage() ; | void handleSetupPage() ; | ||||
| void handleSTAControlPage() ; | void handleSTAControlPage() ; |