| CMD_CHG_COLOR, | CMD_CHG_COLOR, | ||||
| CMD_CHG_BRIGHTNESS, | CMD_CHG_BRIGHTNESS, | ||||
| CMD_CHG_CFG_PARAM, | CMD_CHG_CFG_PARAM, | ||||
| CMD_RESET_WIFI_CFG | |||||
| CMD_RESET_WIFI_CFG, | |||||
| CMD_GET_CONFIG, | |||||
| CMD_ESP_RESTART | |||||
| }; | }; | ||||
| static const char* cmdToString(Commands cmd) { | static const char* cmdToString(Commands cmd) { | ||||
| return "CHG_CFG_PARAM"; | return "CHG_CFG_PARAM"; | ||||
| case CMD_RESET_WIFI_CFG: | case CMD_RESET_WIFI_CFG: | ||||
| return "RESET_WIFI_CFG"; | return "RESET_WIFI_CFG"; | ||||
| case CMD_GET_CONFIG: | |||||
| return "GET_CONFIG"; | |||||
| case CMD_ESP_RESTART: | |||||
| return "ESP_RESTART"; | |||||
| default: | default: | ||||
| return "UNKNOWN"; | return "UNKNOWN"; | ||||
| } | } | ||||
| return CMD_CHG_CFG_PARAM; | return CMD_CHG_CFG_PARAM; | ||||
| 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) | |||||
| return CMD_GET_CONFIG; | |||||
| if (strcmp(cmd, "ESP_RESTART") == 0) | |||||
| return CMD_ESP_RESTART; | |||||
| return CMD_UNKNOWN; | return CMD_UNKNOWN; | ||||
| } | } |
| return config; | return config; | ||||
| } | } | ||||
| Config& ConfigManager::getConfig() { | Config& ConfigManager::getConfig() { | ||||
| return _config; | return _config; | ||||
| } | } | ||||
| void ConfigManager::getConfig(JsonDocument &doc) { | |||||
| doc.clear(); | |||||
| doc["version"] = _config.version; | |||||
| doc["ssid"] = _config.ssid; | |||||
| doc["pass"] = _config.pass; | |||||
| doc["wifiValid"] = _config.wifiValid; | |||||
| doc["mode"] = _config.mode; | |||||
| doc["brightness"] = _config.brightness; | |||||
| rgbwToJson(_config.singleColor, doc["singleColor"].to<JsonObject>()); | |||||
| rgbwToJson(_config.segmentColor1, doc["segmentColor1"].to<JsonObject>()); | |||||
| rgbwToJson(_config.segmentColor2, doc["segmentColor2"].to<JsonObject>()); | |||||
| rgbwToJson(_config.segmentColor3, doc["segmentColor3"].to<JsonObject>()); | |||||
| doc["rainbowDelay"] = _config.rainbowDelay; | |||||
| doc["spectralStepTime"] = _config.spectralStepTime; | |||||
| doc["fadingHoldTime"] = _config.fadingHoldTime; | |||||
| doc["fadingFadeTime"] = _config.fadingFadeTime; | |||||
| doc["flashOnTime"] = _config.flashOnTime; | |||||
| doc["flashOffTime"] = _config.flashOffTime; | |||||
| } | |||||
| void ConfigManager::rgbwToJson(const RGBWColor &c, JsonObject obj) { | |||||
| obj["r"] = c.r; | |||||
| obj["g"] = c.g; | |||||
| obj["b"] = c.b; | |||||
| obj["w"] = c.w; | |||||
| } |
| #define CONFIGMANAGER_H_ | #define CONFIGMANAGER_H_ | ||||
| #include <Arduino.h> | #include <Arduino.h> | ||||
| #include <ArduinoJson.h> | |||||
| #include <EEPROM.h> | #include <EEPROM.h> | ||||
| #include "LEDModes.h" | #include "LEDModes.h" | ||||
| Config& setToDefaultWiFiConfig(Config &config); | Config& setToDefaultWiFiConfig(Config &config); | ||||
| Config& setToDefaultLEDConfig(Config &config); | Config& setToDefaultLEDConfig(Config &config); | ||||
| Config& getConfig(); | Config& getConfig(); | ||||
| void getConfig(JsonDocument &doc); | |||||
| private: | private: | ||||
| Config _config; | Config _config; | ||||
| void rgbwToJson(const RGBWColor &c, JsonObject obj); | |||||
| }; | }; | ||||
| #endif /* CONFIGMANAGER_H_ */ | #endif /* CONFIGMANAGER_H_ */ |
| deserializeJson(doc, msg); | deserializeJson(doc, msg); | ||||
| const char *cmd = doc["cmd"]; | const char *cmd = doc["cmd"]; | ||||
| if (strToCommand(cmd) == CMD_SWITCH_LED) { | |||||
| if (strToCommand(cmd) == CMD_ESP_RESTART) { | |||||
| ESP.restart(); | |||||
| } else if (strToCommand(cmd) == CMD_GET_CONFIG) { | |||||
| JsonDocument doc; | |||||
| String json; | |||||
| configManager.getConfig(doc); | |||||
| serializeJson(doc, json); | |||||
| webSocket.sendTXT(num, json); | |||||
| } else if (strToCommand(cmd) == CMD_SWITCH_LED) { | |||||
| const char *value = doc["val"]; | const char *value = doc["val"]; | ||||
| if (strcmp(value, "on") == 0) { | if (strcmp(value, "on") == 0) { |
| //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 15:24:39 | |||||
| //This file has been generated on 2026-06-29 16:12:29 | |||||
| #include "Arduino.h" | #include "Arduino.h" | ||||
| #include "Arduino.h" | #include "Arduino.h" |