Integrated Changes from Original repository
This commit is contained in:
@@ -33,13 +33,12 @@ void getArgs() {
|
||||
if (server.arg("m") != "") {
|
||||
ws2812fx_mode = constrain(server.arg("m").toInt(), 0, strip.getModeCount() - 1);
|
||||
}
|
||||
|
||||
|
||||
if (server.arg("c").toInt() > 0) {
|
||||
brightness = (int) server.arg("c").toInt() * 2.55;
|
||||
} else {
|
||||
brightness = server.arg("p").toInt();
|
||||
brightness = constrain((int) server.arg("c").toInt() * 2.55, 0, 255);
|
||||
} else if (server.arg("p").toInt() > 0) {
|
||||
brightness = constrain(server.arg("p").toInt(), 0, 255);
|
||||
}
|
||||
brightness = constrain(brightness, 0, 255);
|
||||
|
||||
main_color.white = constrain(main_color.white, 0, 255);
|
||||
main_color.red = constrain(main_color.red, 0, 255);
|
||||
@@ -88,6 +87,7 @@ void handleSetMainColor(uint8_t * mypayload) {
|
||||
main_color.green = ((rgb >> 8) & 0xFF);
|
||||
main_color.blue = ((rgb ) & 0xFF);
|
||||
strip.setColor(main_color.white, main_color.red, main_color.green, main_color.blue);
|
||||
mode = SETCOLOR;
|
||||
}
|
||||
|
||||
void handleSetAllMode(uint8_t * mypayload) {
|
||||
@@ -99,13 +99,16 @@ void handleSetAllMode(uint8_t * mypayload) {
|
||||
main_color.green = ((rgb >> 8) & 0xFF);
|
||||
main_color.blue = ((rgb ) & 0xFF);
|
||||
|
||||
for (int i = 0; i < strip.numPixels(); i++) {
|
||||
strip.setPixelColor(i, main_color.red, main_color.green, main_color.blue, main_color.white);
|
||||
}
|
||||
strip.show();
|
||||
// for (int i = 0; i < strip.numPixels(); i++) {
|
||||
// strip.setPixelColor(i, main_color.red, main_color.green, main_color.blue);
|
||||
// }
|
||||
// strip.show();
|
||||
DBG_OUTPUT_PORT.printf("WS: Set all leds to main color: W: [%u] R: [%u] G: [%u] B: [%u]\n", main_color.white, main_color.red, main_color.green, main_color.blue);
|
||||
exit_func = true;
|
||||
mode = ALL;
|
||||
#ifdef ENABLE_LEGACY_ANIMATIONS
|
||||
exit_func = true;
|
||||
#endif
|
||||
ws2812fx_mode = FX_MODE_STATIC;
|
||||
mode = SET_MODE;
|
||||
}
|
||||
|
||||
void handleSetSingleLED(uint8_t * mypayload, uint8_t firstChar = 0) {
|
||||
@@ -136,7 +139,9 @@ void handleSetSingleLED(uint8_t * mypayload, uint8_t firstChar = 0) {
|
||||
strip.setPixelColor(led, ledstates[led].red, ledstates[led].green, ledstates[led].blue, ledstates[led].white);
|
||||
strip.show();
|
||||
}
|
||||
exit_func = true;
|
||||
#ifdef ENABLE_LEGACY_ANIMATIONS
|
||||
exit_func = true;
|
||||
#endif
|
||||
mode = CUSTOM;
|
||||
}
|
||||
|
||||
@@ -218,82 +223,82 @@ void setModeByStateString(String saved_state_string) {
|
||||
strip.setColor(main_color.white, main_color.red, main_color.green, main_color.blue);
|
||||
}
|
||||
|
||||
void handleSetNamedMode(String str_mode) {
|
||||
exit_func = true;
|
||||
|
||||
if (str_mode.startsWith("=off")) {
|
||||
mode = OFF;
|
||||
#ifdef ENABLE_HOMEASSISTANT
|
||||
stateOn = false;
|
||||
#endif
|
||||
#ifdef ENABLE_LEGACY_ANIMATIONS
|
||||
void handleSetNamedMode(String str_mode) {
|
||||
exit_func = true;
|
||||
|
||||
if (str_mode.startsWith("=off")) {
|
||||
mode = OFF;
|
||||
#ifdef ENABLE_HOMEASSISTANT
|
||||
stateOn = false;
|
||||
#endif
|
||||
}
|
||||
if (str_mode.startsWith("=all")) {
|
||||
ws2812fx_mode = FX_MODE_STATIC;
|
||||
mode = SET_MODE;
|
||||
#ifdef ENABLE_HOMEASSISTANT
|
||||
stateOn = true;
|
||||
#endif
|
||||
}
|
||||
if (str_mode.startsWith("=wipe")) {
|
||||
mode = WIPE;
|
||||
#ifdef ENABLE_HOMEASSISTANT
|
||||
stateOn = true;
|
||||
#endif
|
||||
}
|
||||
if (str_mode.startsWith("=rainbow")) {
|
||||
mode = RAINBOW;
|
||||
#ifdef ENABLE_HOMEASSISTANT
|
||||
stateOn = true;
|
||||
#endif
|
||||
}
|
||||
if (str_mode.startsWith("=rainbowCycle")) {
|
||||
mode = RAINBOWCYCLE;
|
||||
#ifdef ENABLE_HOMEASSISTANT
|
||||
stateOn = true;
|
||||
#endif
|
||||
}
|
||||
if (str_mode.startsWith("=theaterchase")) {
|
||||
mode = THEATERCHASE;
|
||||
#ifdef ENABLE_HOMEASSISTANT
|
||||
stateOn = true;
|
||||
#endif
|
||||
}
|
||||
if (str_mode.startsWith("=twinkleRandom")) {
|
||||
mode = TWINKLERANDOM;
|
||||
#ifdef ENABLE_HOMEASSISTANT
|
||||
stateOn = true;
|
||||
#endif
|
||||
}
|
||||
if (str_mode.startsWith("=theaterchaseRainbow")) {
|
||||
mode = THEATERCHASERAINBOW;
|
||||
#ifdef ENABLE_HOMEASSISTANT
|
||||
stateOn = true;
|
||||
#endif
|
||||
}
|
||||
if (str_mode.startsWith("=tv")) {
|
||||
mode = TV;
|
||||
#ifdef ENABLE_HOMEASSISTANT
|
||||
stateOn = true;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
if (str_mode.startsWith("=all")) {
|
||||
mode = ALL;
|
||||
#ifdef ENABLE_HOMEASSISTANT
|
||||
stateOn = true;
|
||||
#endif
|
||||
}
|
||||
if (str_mode.startsWith("=wipe")) {
|
||||
mode = WIPE;
|
||||
#ifdef ENABLE_HOMEASSISTANT
|
||||
stateOn = true;
|
||||
#endif
|
||||
}
|
||||
if (str_mode.startsWith("=rainbow")) {
|
||||
mode = RAINBOW;
|
||||
#ifdef ENABLE_HOMEASSISTANT
|
||||
stateOn = true;
|
||||
#endif
|
||||
}
|
||||
if (str_mode.startsWith("=rainbowCycle")) {
|
||||
mode = RAINBOWCYCLE;
|
||||
#ifdef ENABLE_HOMEASSISTANT
|
||||
stateOn = true;
|
||||
#endif
|
||||
}
|
||||
if (str_mode.startsWith("=theaterchase")) {
|
||||
mode = THEATERCHASE;
|
||||
#ifdef ENABLE_HOMEASSISTANT
|
||||
stateOn = true;
|
||||
#endif
|
||||
}
|
||||
if (str_mode.startsWith("=twinkleRandom")) {
|
||||
mode = TWINKLERANDOM;
|
||||
#ifdef ENABLE_HOMEASSISTANT
|
||||
stateOn = true;
|
||||
#endif
|
||||
}
|
||||
if (str_mode.startsWith("=theaterchaseRainbow")) {
|
||||
mode = THEATERCHASERAINBOW;
|
||||
#ifdef ENABLE_HOMEASSISTANT
|
||||
stateOn = true;
|
||||
#endif
|
||||
}
|
||||
if (str_mode.startsWith("=tv")) {
|
||||
mode = TV;
|
||||
#ifdef ENABLE_HOMEASSISTANT
|
||||
stateOn = true;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void handleSetWS2812FXMode(uint8_t * mypayload) {
|
||||
mode = HOLD;
|
||||
uint8_t ws2812fx_mode = (uint8_t) strtol((const char *) &mypayload[1], NULL, 10);
|
||||
ws2812fx_mode = constrain(ws2812fx_mode, 0, 255);
|
||||
strip.setColor(main_color.white, main_color.red, main_color.green, main_color.blue);
|
||||
strip.setMode(ws2812fx_mode);
|
||||
strip.start();
|
||||
mode = SET_MODE;
|
||||
uint8_t ws2812fx_mode_tmp = (uint8_t) strtol((const char *) &mypayload[1], NULL, 10);
|
||||
ws2812fx_mode = constrain(ws2812fx_mode_tmp, 0, strip.getModeCount() - 1);
|
||||
}
|
||||
|
||||
char* listStatusJSON() {
|
||||
char json[255];
|
||||
|
||||
char modeName[30];
|
||||
strncpy_P(modeName, (PGM_P)strip.getModeName(strip.getMode()), sizeof(modeName)); // copy from progmem
|
||||
|
||||
snprintf(json, sizeof(json), "{\"mode\":%d, \"ws2812fx_mode\":%d, \"ws2812fx_mode_name\":\"%s\", \"speed\":%d, \"brightness\":%d, \"color\":[%d, %d, %d, %d]}",
|
||||
mode, strip.getMode(), modeName, ws2812fx_speed, brightness, main_color.white, main_color.red, main_color.green, main_color.blue);
|
||||
uint8_t tmp_mode = (mode == SET_MODE) ? (uint8_t) ws2812fx_mode : strip.getMode();
|
||||
|
||||
strncpy_P(modeName, (PGM_P)strip.getModeName(tmp_mode), sizeof(modeName)); // copy from progmem
|
||||
snprintf(json, sizeof(json), "{\"mode\":%d, \"ws2812fx_mode\":%d, \"ws2812fx_mode_name\":\"%s\", \"speed\":%d, \"brightness\":%d, \"color\":[%d, %d, %d]}",
|
||||
mode, tmp_mode, modeName, ws2812fx_speed, brightness, main_color.red, main_color.green, main_color.blue);
|
||||
return json;
|
||||
}
|
||||
|
||||
@@ -525,28 +530,30 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t lenght
|
||||
#endif
|
||||
}
|
||||
|
||||
// = ==> Activate named mode
|
||||
if (payload[0] == '=') {
|
||||
// we get mode data
|
||||
String str_mode = String((char *) &payload[0]);
|
||||
|
||||
handleSetNamedMode(str_mode);
|
||||
|
||||
DBG_OUTPUT_PORT.printf("Activated mode [%u]!\n", mode);
|
||||
webSocket.sendTXT(num, "OK");
|
||||
#ifdef ENABLE_MQTT
|
||||
mqtt_client.publish(mqtt_outtopic, String(String("OK ") + String((char *)payload)).c_str());
|
||||
#endif
|
||||
#ifdef ENABLE_AMQTT
|
||||
amqttClient.publish(mqtt_outtopic.c_str(), qospub, false, String(String("OK ") + String((char *)payload)).c_str());
|
||||
#endif
|
||||
#ifdef ENABLE_HOMEASSISTANT
|
||||
if(!ha_send_data.active()) ha_send_data.once(5, tickerSendState);
|
||||
#endif
|
||||
#ifdef ENABLE_STATE_SAVE_SPIFFS
|
||||
if(!spiffs_save_state.active()) spiffs_save_state.once(3, tickerSpiffsSaveState);
|
||||
#endif
|
||||
}
|
||||
#ifdef ENABLE_LEGACY_ANIMATIONS
|
||||
// = ==> Activate named mode
|
||||
if (payload[0] == '=') {
|
||||
// we get mode data
|
||||
String str_mode = String((char *) &payload[0]);
|
||||
|
||||
handleSetNamedMode(str_mode);
|
||||
|
||||
DBG_OUTPUT_PORT.printf("Activated mode [%u]!\n", mode);
|
||||
webSocket.sendTXT(num, "OK");
|
||||
#ifdef ENABLE_MQTT
|
||||
mqtt_client.publish(mqtt_outtopic, String(String("OK ") + String((char *)payload)).c_str());
|
||||
#endif
|
||||
#ifdef ENABLE_AMQTT
|
||||
amqttClient.publish(mqtt_outtopic.c_str(), qospub, false, String(String("OK ") + String((char *)payload)).c_str());
|
||||
#endif
|
||||
#ifdef ENABLE_HOMEASSISTANT
|
||||
if(!ha_send_data.active()) ha_send_data.once(5, tickerSendState);
|
||||
#endif
|
||||
#ifdef ENABLE_STATE_SAVE_SPIFFS
|
||||
if(!spiffs_save_state.active()) spiffs_save_state.once(3, tickerSpiffsSaveState);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
// $ ==> Get status Info.
|
||||
if (payload[0] == '$') {
|
||||
@@ -619,13 +626,15 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t lenght
|
||||
}
|
||||
}
|
||||
|
||||
void checkForRequests() {
|
||||
webSocket.loop();
|
||||
server.handleClient();
|
||||
#ifdef ENABLE_MQTT
|
||||
mqtt_client.loop();
|
||||
#endif
|
||||
}
|
||||
#ifdef ENABLE_LEGACY_ANIMATIONS
|
||||
void checkForRequests() {
|
||||
webSocket.loop();
|
||||
server.handleClient();
|
||||
#ifdef ENABLE_MQTT
|
||||
mqtt_client.loop();
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
// ***************************************************************************
|
||||
@@ -746,7 +755,8 @@ void checkForRequests() {
|
||||
const char* state_in = root["state"];
|
||||
if (strcmp(state_in, on_cmd) == 0 and !(animation_on)) {
|
||||
stateOn = true;
|
||||
mode = ALL;
|
||||
ws2812fx_mode = FX_MODE_STATIC;
|
||||
mode = SET_MODE;
|
||||
}
|
||||
else if (strcmp(state_in, off_cmd) == 0) {
|
||||
stateOn = false;
|
||||
@@ -949,24 +959,26 @@ void checkForRequests() {
|
||||
#endif
|
||||
}
|
||||
|
||||
// = ==> Activate named mode
|
||||
if (payload[0] == '=') {
|
||||
String str_mode = String((char *) &payload[0]);
|
||||
handleSetNamedMode(str_mode);
|
||||
DBG_OUTPUT_PORT.printf("MQTT: Activate named mode [%s]\n", payload);
|
||||
#ifdef ENABLE_MQTT
|
||||
mqtt_client.publish(mqtt_outtopic, String(String("OK ") + String((char *)payload)).c_str());
|
||||
#endif
|
||||
#ifdef ENABLE_AMQTT
|
||||
amqttClient.publish(mqtt_outtopic.c_str(), qospub, false, String(String("OK ") + String((char *)payload)).c_str());
|
||||
#endif
|
||||
#ifdef ENABLE_HOMEASSISTANT
|
||||
if(!ha_send_data.active()) ha_send_data.once(5, tickerSendState);
|
||||
#endif
|
||||
#ifdef ENABLE_STATE_SAVE_SPIFFS
|
||||
if(!spiffs_save_state.active()) spiffs_save_state.once(3, tickerSpiffsSaveState);
|
||||
#endif
|
||||
}
|
||||
#ifdef ENABLE_LEGACY_ANIMATIONS
|
||||
// = ==> Activate named mode
|
||||
if (payload[0] == '=') {
|
||||
String str_mode = String((char *) &payload[0]);
|
||||
handleSetNamedMode(str_mode);
|
||||
DBG_OUTPUT_PORT.printf("MQTT: Activate named mode [%s]\n", payload);
|
||||
#ifdef ENABLE_MQTT
|
||||
mqtt_client.publish(mqtt_outtopic, String(String("OK ") + String((char *)payload)).c_str());
|
||||
#endif
|
||||
#ifdef ENABLE_AMQTT
|
||||
amqttClient.publish(mqtt_outtopic.c_str(), qospub, false, String(String("OK ") + String((char *)payload)).c_str());
|
||||
#endif
|
||||
#ifdef ENABLE_HOMEASSISTANT
|
||||
if(!ha_send_data.active()) ha_send_data.once(5, tickerSendState);
|
||||
#endif
|
||||
#ifdef ENABLE_STATE_SAVE_SPIFFS
|
||||
if(!spiffs_save_state.active()) spiffs_save_state.once(3, tickerSpiffsSaveState);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
// $ ==> Get status Info.
|
||||
if (payload[0] == '$') {
|
||||
@@ -1440,14 +1452,14 @@ bool writeStateFS(){
|
||||
DynamicJsonBuffer jsonBuffer(JSON_OBJECT_SIZE(7));
|
||||
// StaticJsonBuffer<JSON_OBJECT_SIZE(7)> jsonBuffer;
|
||||
JsonObject& json = jsonBuffer.createObject();
|
||||
json["mode"] = static_cast<int>(mode);
|
||||
json["mode"] = static_cast<int>(mode);
|
||||
json["strip_mode"] = (int) strip.getMode();
|
||||
json["brightness"] = brightness;
|
||||
json["speed"] = ws2812fx_speed;
|
||||
json["white"] = main_color.white;
|
||||
json["red"] = main_color.red;
|
||||
json["green"] = main_color.green;
|
||||
json["blue"] = main_color.blue;
|
||||
json["speed"] = ws2812fx_speed;
|
||||
json["white"] = main_color.white;
|
||||
json["red"] = main_color.red;
|
||||
json["green"] = main_color.green;
|
||||
json["blue"] = main_color.blue;
|
||||
|
||||
// SPIFFS.remove("/state.json") ? DBG_OUTPUT_PORT.println("removed file") : DBG_OUTPUT_PORT.println("failed removing file");
|
||||
File configFile = SPIFFS.open("/stripstate.json", "w");
|
||||
@@ -1487,9 +1499,9 @@ bool readStateFS() {
|
||||
json.printTo(DBG_OUTPUT_PORT);
|
||||
if (json.success()) {
|
||||
mode = static_cast<MODE>((int) json["mode"]);
|
||||
ws2812fx_mode = json["strip_mode"];
|
||||
brightness = json["brightness"];
|
||||
ws2812fx_speed = json["speed"];
|
||||
ws2812fx_mode = json["strip_mode"];
|
||||
brightness = json["brightness"];
|
||||
ws2812fx_speed = json["speed"];
|
||||
main_color.white = json["white"];
|
||||
main_color.red = json["red"];
|
||||
main_color.green = json["green"];
|
||||
@@ -1516,4 +1528,3 @@ bool readStateFS() {
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user