| @@ -15,6 +15,7 @@ enum Commands { | |||
| CMD_CHG_COLOR, | |||
| CMD_CHG_BRIGHTNESS, | |||
| CMD_CHG_CFG_PARAM, | |||
| CMD_CHG_TIMER, | |||
| CMD_CHG_TIMER_INTERVAL, | |||
| CMD_RESET_WIFI_CFG, | |||
| CMD_GET_CONFIG, | |||
| @@ -33,6 +34,8 @@ static const char* cmdToString(Commands cmd) { | |||
| return "CHG_BRIGHTNESS"; | |||
| case CMD_CHG_CFG_PARAM: | |||
| return "CHG_CFG_PARAM"; | |||
| case CMD_CHG_TIMER: | |||
| return "CHG_TIMER"; | |||
| case CMD_CHG_TIMER_INTERVAL: | |||
| return "CHG_TIMER_INTERVAL"; | |||
| case CMD_RESET_WIFI_CFG: | |||
| @@ -61,6 +64,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") == 0) | |||
| return CMD_CHG_TIMER; | |||
| if (strcmp(cmd, "CHG_TIMER_INTERVAL") == 0) | |||
| return CMD_CHG_TIMER_INTERVAL; | |||
| if (strcmp(cmd, "RESET_WIFI_CFG") == 0) | |||
| @@ -107,10 +107,11 @@ Config& ConfigManager::setToDefaultLEDConfig(Config &config) { | |||
| } | |||
| Config& ConfigManager::setToDefaultTimerConfig(Config &config) { | |||
| config.timeInterval1.start = 0; | |||
| config.timeInterval1.end = 0; | |||
| config.timeInterval2.start = 0; | |||
| config.timeInterval2.end = 0; | |||
| config.timer.on = false; | |||
| config.timer.timeInterval1.start = 0; | |||
| config.timer.timeInterval1.end = 0; | |||
| config.timer.timeInterval2.start = 0; | |||
| config.timer.timeInterval2.end = 0; | |||
| return config; | |||
| } | |||
| @@ -141,8 +142,9 @@ void ConfigManager::getConfig(JsonDocument &doc) { | |||
| doc["flashOnTime"] = _config.flashOnTime; | |||
| doc["flashOffTime"] = _config.flashOffTime; | |||
| timeIntervalToJson(_config.timeInterval1, doc["timeInterval1"].to<JsonObject>()); | |||
| timeIntervalToJson(_config.timeInterval2, doc["timeInterval2"].to<JsonObject>()); | |||
| doc["timer"]["on"] = _config.timer.on; | |||
| timeIntervalToJson(_config.timer.timeInterval1, doc["timer"]["timeInterval1"].to<JsonObject>()); | |||
| timeIntervalToJson(_config.timer.timeInterval2, doc["timer"]["timeInterval2"].to<JsonObject>()); | |||
| } | |||
| void ConfigManager::rgbwToJson(const RGBWColor &c, JsonObject obj) { | |||
| @@ -13,7 +13,7 @@ | |||
| #include <EEPROM.h> | |||
| #include "LEDModes.h" | |||
| #define CONFIG_VERSION 4 | |||
| #define CONFIG_VERSION 5 | |||
| typedef struct __attribute__((packed)) { | |||
| uint8_t r; | |||
| @@ -27,6 +27,12 @@ typedef struct __attribute__((packed)) { | |||
| uint32_t end; | |||
| } TimeInterval; | |||
| typedef struct __attribute__((packed)) { | |||
| bool on; | |||
| TimeInterval timeInterval1; | |||
| TimeInterval timeInterval2; | |||
| } Timer; | |||
| typedef struct __attribute__((packed)) { | |||
| uint8_t version; | |||
| @@ -45,9 +51,7 @@ typedef struct __attribute__((packed)) { | |||
| uint32_t fadingFadeTime; | |||
| uint32_t flashOnTime; | |||
| uint32_t flashOffTime; | |||
| TimeInterval timeInterval1; | |||
| TimeInterval timeInterval2; | |||
| Timer timer; | |||
| } Config; | |||
| class ConfigManager { | |||
| @@ -179,6 +179,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) { | |||
| const char *status = doc["status"]; | |||
| timerManager.onTimerStatusChange(status); | |||
| } else if (strToCommand(cmd) == CMD_CHG_TIMER_INTERVAL) { | |||
| const char *interval = doc["interval"]; | |||
| const char *timerange = doc["timerange"]; | |||
| @@ -260,6 +264,7 @@ void handleSTAMode() { | |||
| MDNS.update(); | |||
| static uint32_t lastNtpCheck = 0; | |||
| uint32_t now = millis(); | |||
| if (WiFi.status() != WL_CONNECTED) { | |||
| Serial.println("WLAN verloren"); | |||
| @@ -269,16 +274,17 @@ void handleSTAMode() { | |||
| return; | |||
| } | |||
| uint32_t now = millis(); | |||
| if (now - lastNtpCheck >= 5000) { | |||
| lastNtpCheck = now; | |||
| if (timerManager.isNowInTimeInterval()) { | |||
| if (ledMngr.isOn()) { | |||
| ledMngr.off(); | |||
| } | |||
| } else { | |||
| if (!ledMngr.isOn()) { | |||
| ledMngr.on(); | |||
| if (configManager.getConfig().timer.on) { | |||
| if (now - lastNtpCheck >= 5000) { | |||
| lastNtpCheck = now; | |||
| if (timerManager.isNowInTimeInterval()) { | |||
| if (ledMngr.isOn()) { | |||
| ledMngr.off(); | |||
| } | |||
| } else { | |||
| if (!ledMngr.isOn()) { | |||
| ledMngr.on(); | |||
| } | |||
| } | |||
| } | |||
| } | |||
| @@ -26,6 +26,13 @@ void TimerManager::begin() { | |||
| ntpClient.begin(); | |||
| } | |||
| void TimerManager::onTimerStatusChange(const char *timerStatus) { | |||
| Config cfg = configManager.getConfig(); | |||
| cfg.timer.on = String(timerStatus).equalsIgnoreCase("on"); | |||
| configManager.saveConfig(cfg); | |||
| } | |||
| void TimerManager::onTimerIntervalChange(String timerIntervalName, const char *timerInterval) { | |||
| TimeInterval interval; | |||
| parseTimeInterval(timerInterval, interval); | |||
| @@ -35,11 +42,11 @@ void TimerManager::onTimerIntervalChange(String timerIntervalName, const char *t | |||
| 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; | |||
| cfg.timer.timeInterval1.start = start; | |||
| cfg.timer.timeInterval1.end = end; | |||
| } else if (timerIntervalName.equals("timeInterval2")) { | |||
| cfg.timeInterval2.start = start; | |||
| cfg.timeInterval2.end = end; | |||
| cfg.timer.timeInterval2.start = start; | |||
| cfg.timer.timeInterval2.end = end; | |||
| } | |||
| configManager.saveConfig(cfg); | |||
| @@ -91,7 +98,7 @@ bool TimerManager::isNowInTimeInterval() { | |||
| Serial.print("localTime: "); | |||
| Serial.println(secondsToFormatedTime(localTime)); | |||
| return (isInInterval(localTime, cfg.timeInterval1) || isInInterval(localTime, cfg.timeInterval2)); | |||
| return (isInInterval(localTime, cfg.timer.timeInterval1) || isInInterval(localTime, cfg.timer.timeInterval2)); | |||
| } | |||
| bool TimerManager::isDST(int month, int day, int weekday) { | |||
| @@ -136,3 +143,4 @@ String TimerManager::secondsToFormatedTime(uint32_t seconds) { | |||
| return String(buffer); | |||
| } | |||
| @@ -19,6 +19,7 @@ class TimerManager { | |||
| virtual ~TimerManager(); | |||
| void begin(); | |||
| void onTimerStatusChange(const char *timerStatus); | |||
| void onTimerIntervalChange(String timerIntervalName, const char *timerInterval); | |||
| void saveTimerInterval(String timerIntervalName, uint32_t start, uint32_t end); | |||
| bool isNowInTimeInterval(); | |||
| @@ -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-07-16 22:35:32 | |||
| //This file has been generated on 2026-07-16 22:59:44 | |||
| #include "Arduino.h" | |||
| #include "Arduino.h" | |||