update to 2.20
update to 2.20
This commit is contained in:
@@ -1,6 +1,40 @@
|
||||
// ***************************************************************************
|
||||
// Request handlers
|
||||
// ***************************************************************************
|
||||
#ifdef ENABLE_E131
|
||||
void checkForRequests(void); //prototype
|
||||
|
||||
void handleE131(){
|
||||
if (!e131.isEmpty())
|
||||
{
|
||||
e131_packet_t packet;
|
||||
e131.pull(&packet); // Pull packet from ring buffer
|
||||
|
||||
uint16_t universe = htons(packet.universe);
|
||||
uint8_t *data = packet.property_values + 1;
|
||||
|
||||
if (universe < START_UNIVERSE || universe > END_UNIVERSE) return; //async will take care about filling the buffer
|
||||
|
||||
// Serial.printf("Universe %u / %u Channels | Packet#: %u / Errors: %u / CH1: %u\n",
|
||||
// htons(packet.universe), // The Universe for this packet
|
||||
// htons(packet.property_value_count) - 1, // Start code is ignored, we're interested in dimmer data
|
||||
// e131.stats.num_packets, // Packet counter
|
||||
// e131.stats.packet_errors, // Packet error counter
|
||||
// packet.property_values[1]); // Dimmer data for Channel 1
|
||||
|
||||
uint16_t multipacketOffset = (universe - START_UNIVERSE) * 170; //if more than 170 LEDs (510 channels), client will send in next higher universe
|
||||
if (NUMLEDS <= multipacketOffset) return;
|
||||
uint16_t len = (170 + multipacketOffset > NUMLEDS) ? (NUMLEDS - multipacketOffset) : 170;
|
||||
for (uint16_t i = 0; i < len; i++){
|
||||
uint16_t j = i * 3;
|
||||
strip.setPixelColor(i + multipacketOffset, data[j], data[j + 1], data[j + 2]);
|
||||
}
|
||||
strip.show();
|
||||
checkForRequests();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_HOMEASSISTANT
|
||||
void tickerSendState(){
|
||||
new_ha_mqtt_msg = true;
|
||||
@@ -15,18 +49,18 @@ void tickerSpiffsSaveState(){
|
||||
void getArgs() {
|
||||
if (server.arg("rgb") != "") {
|
||||
uint32_t rgb = (uint32_t) strtoul(server.arg("rgb").c_str(), NULL, 16);
|
||||
main_color.white = ((rgb >> 24) & 0xFF);
|
||||
main_color.red = ((rgb >> 16) & 0xFF);
|
||||
main_color.green = ((rgb >> 8) & 0xFF);
|
||||
main_color.blue = ((rgb ) & 0xFF);
|
||||
main_color.red = ((rgb >> 24) & 0xFF);
|
||||
main_color.green = ((rgb >> 16) & 0xFF);
|
||||
main_color.blue = ((rgb >> 8) & 0xFF);
|
||||
main_color.white = ((rgb >> 0) & 0xFF);
|
||||
} else {
|
||||
main_color.white = server.arg("w").toInt();
|
||||
main_color.red = server.arg("r").toInt();
|
||||
main_color.red = server.arg("r").toInt();
|
||||
main_color.green = server.arg("g").toInt();
|
||||
main_color.blue = server.arg("b").toInt();
|
||||
main_color.blue = server.arg("b").toInt();
|
||||
main_color.white = server.arg("w").toInt();
|
||||
}
|
||||
if (server.arg("s") != "") {
|
||||
ws2812fx_speed = constrain(server.arg("s").toInt(), 0, 255);
|
||||
ws2812fx_speed = constrain(server.arg("s").toInt(), 0, 255);
|
||||
}
|
||||
|
||||
if (server.arg("m") != "") {
|
||||
@@ -39,21 +73,21 @@ void getArgs() {
|
||||
brightness = constrain(server.arg("p").toInt(), 0, 255);
|
||||
}
|
||||
|
||||
main_color.white = constrain(main_color.white, 0, 255);
|
||||
main_color.red = constrain(main_color.red, 0, 255);
|
||||
main_color.red = constrain(main_color.red, 0, 255);
|
||||
main_color.green = constrain(main_color.green, 0, 255);
|
||||
main_color.blue = constrain(main_color.blue, 0, 255);
|
||||
|
||||
main_color.blue = constrain(main_color.blue, 0, 255);
|
||||
main_color.white = constrain(main_color.white, 0, 255);
|
||||
|
||||
DBG_OUTPUT_PORT.print("Mode: ");
|
||||
DBG_OUTPUT_PORT.print(mode);
|
||||
DBG_OUTPUT_PORT.print(", Color: ");
|
||||
DBG_OUTPUT_PORT.print(main_color.white);
|
||||
DBG_OUTPUT_PORT.print(", ");
|
||||
DBG_OUTPUT_PORT.print(main_color.red);
|
||||
DBG_OUTPUT_PORT.print(", ");
|
||||
DBG_OUTPUT_PORT.print(main_color.green);
|
||||
DBG_OUTPUT_PORT.print(", ");
|
||||
DBG_OUTPUT_PORT.print(main_color.blue);
|
||||
DBG_OUTPUT_PORT.print(", ");
|
||||
DBG_OUTPUT_PORT.print(main_color.white);
|
||||
DBG_OUTPUT_PORT.print(", Speed:");
|
||||
DBG_OUTPUT_PORT.print(ws2812fx_speed);
|
||||
DBG_OUTPUT_PORT.print(", Brightness:");
|
||||
@@ -81,10 +115,11 @@ uint16_t convertSpeed(uint8_t mcl_speed) {
|
||||
void handleSetMainColor(uint8_t * mypayload) {
|
||||
// decode rgb data
|
||||
uint32_t rgb = (uint32_t) strtoul((const char *) &mypayload[1], NULL, 16);
|
||||
main_color.white = ((rgb >> 24) & 0xFF);
|
||||
main_color.red = ((rgb >> 16) & 0xFF);
|
||||
main_color.green = ((rgb >> 8) & 0xFF);
|
||||
main_color.blue = ((rgb ) & 0xFF);
|
||||
main_color.red = ((rgb >> 24) & 0xFF);
|
||||
main_color.green = ((rgb >> 16) & 0xFF);
|
||||
main_color.blue = ((rgb >> 8) & 0xFF);
|
||||
main_color.white = ((rgb >> 0) & 0xFF);
|
||||
// strip.setColor(main_color.red, main_color.green, main_color.blue);
|
||||
mode = SETCOLOR;
|
||||
}
|
||||
|
||||
@@ -92,12 +127,12 @@ void handleSetAllMode(uint8_t * mypayload) {
|
||||
// decode rgb data
|
||||
uint32_t rgb = (uint32_t) strtoul((const char *) &mypayload[1], NULL, 16);
|
||||
|
||||
main_color.white = ((rgb >> 24) & 0xFF);
|
||||
main_color.red = ((rgb >> 16) & 0xFF);
|
||||
main_color.green = ((rgb >> 8) & 0xFF);
|
||||
main_color.blue = ((rgb ) & 0xFF);
|
||||
main_color.red = ((rgb >> 24) & 0xFF);
|
||||
main_color.green = ((rgb >> 16) & 0xFF);
|
||||
main_color.blue = ((rgb >> 8) & 0xFF);
|
||||
main_color.white = ((rgb >> 0) & 0xFF);
|
||||
|
||||
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);
|
||||
DBG_OUTPUT_PORT.printf("WS: Set all leds to main color: R: [%u] G: [%u] B: [%u] W: [%u]\n", main_color.red, main_color.green, main_color.blue, main_color.white);
|
||||
#ifdef ENABLE_LEGACY_ANIMATIONS
|
||||
exit_func = true;
|
||||
#endif
|
||||
@@ -113,23 +148,21 @@ void handleSetSingleLED(uint8_t * mypayload, uint8_t firstChar = 0) {
|
||||
|
||||
DBG_OUTPUT_PORT.printf("led value: [%i]. Entry threshold: <= [%i] (=> %s)\n", led, strip.numPixels(), mypayload );
|
||||
if (led <= strip.numPixels()) {
|
||||
char whitehex[3];
|
||||
char redhex[3];
|
||||
char greenhex[3];
|
||||
char bluehex[3];
|
||||
strncpy (whitehex, (const char *) &mypayload[2 + firstChar], 2 );
|
||||
strncpy (redhex, (const char *) &mypayload[4 + firstChar], 2 );
|
||||
strncpy (greenhex, (const char *) &mypayload[6 + firstChar], 2 );
|
||||
strncpy (bluehex, (const char *) &mypayload[8 + firstChar], 2 );
|
||||
ledstates[led].white = strtol(whitehex, NULL, 16);
|
||||
char whitehex[3];
|
||||
strncpy (redhex, (const char *) &mypayload[2 + firstChar], 2 );
|
||||
strncpy (greenhex, (const char *) &mypayload[4 + firstChar], 2 );
|
||||
strncpy (bluehex, (const char *) &mypayload[6 + firstChar], 2 );
|
||||
strncpy (whitehex, (const char *) &mypayload[2 + firstChar], 2 );
|
||||
ledstates[led].red = strtol(redhex, NULL, 16);
|
||||
ledstates[led].green = strtol(greenhex, NULL, 16);
|
||||
ledstates[led].blue = strtol(bluehex, NULL, 16);
|
||||
DBG_OUTPUT_PORT.printf(" rgb.white: [%s] rgb.red: [%s] rgb.green: [%s] rgb.blue: [%s]\n", whitehex, redhex, greenhex, bluehex);
|
||||
DBG_OUTPUT_PORT.printf(" rgb.white: [%i] rgb.red: [%i] rgb.green: [%i] rgb.blue: [%i]\n", strtol(whitehex, NULL, 16), strtol(redhex, NULL, 16), strtol(greenhex, NULL, 16), strtol(bluehex, NULL, 16));
|
||||
DBG_OUTPUT_PORT.printf("WS: Set single led [%i] to [%i] [%i] [%i] [%i] (%s)!\n", led, ledstates[led].white, ledstates[led].red, ledstates[led].green, ledstates[led].blue, mypayload);
|
||||
|
||||
|
||||
ledstates[led].white = strtol(whitehex, NULL, 16);
|
||||
DBG_OUTPUT_PORT.printf("rgb.red: [%s] rgb.green: [%s] rgb.blue: [%s] rgb.white: [%s]\n", redhex, greenhex, bluehex, whitehex);
|
||||
DBG_OUTPUT_PORT.printf("rgb.red: [%i] rgb.green: [%i] rgb.blue: [%i] rgb.white: [%i]\n", strtol(redhex, NULL, 16), strtol(greenhex, NULL, 16), strtol(bluehex, NULL, 16), strtol(whitehex, NULL, 16));
|
||||
DBG_OUTPUT_PORT.printf("WS: Set single led [%i] to [%i] [%i] [%i] [%i] (%s)!\n", led, ledstates[led].red, ledstates[led].green, ledstates[led].blue, ledstates[led].white, mypayload);
|
||||
strip.setPixelColor(led, ledstates[led].red, ledstates[led].green, ledstates[led].blue, ledstates[led].white);
|
||||
strip.show();
|
||||
}
|
||||
@@ -194,27 +227,27 @@ void setModeByStateString(String saved_state_string) {
|
||||
ws2812fx_speed = str_ws2812fx_speed.toInt();
|
||||
String str_brightness = getValue(saved_state_string, '|', 4);
|
||||
brightness = str_brightness.toInt();
|
||||
String str_white = getValue(saved_state_string, '|', 5);
|
||||
main_color.white = str_white.toInt();
|
||||
String str_red = getValue(saved_state_string, '|', 6);
|
||||
String str_red = getValue(saved_state_string, '|', 5);
|
||||
main_color.red = str_red.toInt();
|
||||
String str_green = getValue(saved_state_string, '|', 7);
|
||||
String str_green = getValue(saved_state_string, '|', 6);
|
||||
main_color.green = str_green.toInt();
|
||||
String str_blue = getValue(saved_state_string, '|', 8);
|
||||
String str_blue = getValue(saved_state_string, '|', 7);
|
||||
main_color.blue = str_blue.toInt();
|
||||
String str_white = getValue(saved_state_string, '|', 8);
|
||||
main_color.white = str_white.toInt();
|
||||
|
||||
DBG_OUTPUT_PORT.printf("ws2812fx_mode: %d\n", ws2812fx_mode);
|
||||
DBG_OUTPUT_PORT.printf("ws2812fx_speed: %d\n", ws2812fx_speed);
|
||||
DBG_OUTPUT_PORT.printf("brightness: %d\n", brightness);
|
||||
DBG_OUTPUT_PORT.printf("main_color.white: %d\n", main_color.white);
|
||||
DBG_OUTPUT_PORT.printf("main_color.red: %d\n", main_color.red);
|
||||
DBG_OUTPUT_PORT.printf("main_color.green: %d\n", main_color.green);
|
||||
DBG_OUTPUT_PORT.printf("main_color.blue: %d\n", main_color.blue);
|
||||
DBG_OUTPUT_PORT.printf("main_color.white: %d\n", main_color.white);
|
||||
|
||||
strip.setMode(ws2812fx_mode);
|
||||
strip.setSpeed(convertSpeed(ws2812fx_speed));
|
||||
strip.setBrightness(brightness);
|
||||
strip.setColor(main_color.white, main_color.red, main_color.green, main_color.blue);
|
||||
strip.setColor(main_color.red, main_color.green, main_color.blue, main_color.white);
|
||||
}
|
||||
|
||||
#ifdef ENABLE_LEGACY_ANIMATIONS
|
||||
@@ -285,6 +318,19 @@ void setModeByStateString(String saved_state_string) {
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_E131
|
||||
void handleE131NamedMode(String str_mode) {
|
||||
exit_func = true;
|
||||
if (str_mode.startsWith("=e131") or str_mode.startsWith("/e131")) {
|
||||
if(strip.isRunning()) strip.stop();
|
||||
mode = E131;
|
||||
#ifdef ENABLE_HOMEASSISTANT
|
||||
stateOn = true;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void handleSetWS2812FXMode(uint8_t * mypayload) {
|
||||
mode = SET_MODE;
|
||||
uint8_t ws2812fx_mode_tmp = (uint8_t) strtol((const char *) &mypayload[1], NULL, 10);
|
||||
@@ -294,7 +340,7 @@ void handleSetWS2812FXMode(uint8_t * mypayload) {
|
||||
String listStatusJSON(void) {
|
||||
uint8_t tmp_mode = (mode == SET_MODE) ? (uint8_t) ws2812fx_mode : strip.getMode();
|
||||
|
||||
const size_t bufferSize = JSON_ARRAY_SIZE(3) + JSON_OBJECT_SIZE(6);
|
||||
const size_t bufferSize = JSON_ARRAY_SIZE(3) + JSON_OBJECT_SIZE(6) + 500;
|
||||
DynamicJsonDocument jsonBuffer(bufferSize);
|
||||
JsonObject root = jsonBuffer.to<JsonObject>();
|
||||
root["mode"] = (uint8_t) mode;
|
||||
@@ -303,11 +349,11 @@ String listStatusJSON(void) {
|
||||
root["speed"] = ws2812fx_speed;
|
||||
root["brightness"] = brightness;
|
||||
JsonArray color = root.createNestedArray("color");
|
||||
color.add(main_color.white);
|
||||
color.add(main_color.red);
|
||||
color.add(main_color.green);
|
||||
color.add(main_color.blue);
|
||||
|
||||
color.add(main_color.white);
|
||||
|
||||
String json;
|
||||
serializeJson(root, json);
|
||||
|
||||
@@ -320,9 +366,14 @@ void getStatusJSON() {
|
||||
}
|
||||
|
||||
String listModesJSON(void) {
|
||||
const size_t bufferSize = JSON_ARRAY_SIZE(strip.getModeCount()+1) + strip.getModeCount()*JSON_OBJECT_SIZE(2);
|
||||
const size_t bufferSize = JSON_ARRAY_SIZE(strip.getModeCount()+1) + strip.getModeCount()*JSON_OBJECT_SIZE(2) + 1000;
|
||||
DynamicJsonDocument jsonBuffer(bufferSize);
|
||||
JsonArray json = jsonBuffer.to<JsonArray>();
|
||||
#ifdef ENABLE_E131
|
||||
JsonObject objecte131 = json.createNestedObject();
|
||||
objecte131["mode"] = "e131";
|
||||
objecte131["name"] = "E131";
|
||||
#endif
|
||||
for (uint8_t i = 0; i < strip.getModeCount(); i++) {
|
||||
JsonObject object = json.createNestedObject();
|
||||
object["mode"] = i;
|
||||
@@ -425,7 +476,7 @@ void checkpayload(uint8_t * payload, bool mqtt = false, uint8_t num = 0) {
|
||||
if (payload[0] == '#') {
|
||||
handleSetMainColor(payload);
|
||||
Dbg_Prefix(mqtt, num);
|
||||
DBG_OUTPUT_PORT.printf("Set main color to: W: [%u] R: [%u] G: [%u] B: [%u]\n", main_color.white, main_color.red, main_color.green, main_color.blue);
|
||||
DBG_OUTPUT_PORT.printf("Set main color to: R: [%u] G: [%u] B: [%u] W: [%u]\n", main_color.red, main_color.green, main_color.blue, main_color.white);
|
||||
#ifdef ENABLE_MQTT
|
||||
mqtt_client.publish(mqtt_outtopic, String(String("OK ") + String((char *)payload)).c_str());
|
||||
#endif
|
||||
@@ -434,7 +485,7 @@ void checkpayload(uint8_t * payload, bool mqtt = false, uint8_t num = 0) {
|
||||
#endif
|
||||
#ifdef ENABLE_HOMEASSISTANT
|
||||
stateOn = true;
|
||||
if(!ha_send_data.active()) ha_send_data.once(5, tickerSendState);
|
||||
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);
|
||||
@@ -449,6 +500,7 @@ void checkpayload(uint8_t * payload, bool mqtt = false, uint8_t num = 0) {
|
||||
Dbg_Prefix(mqtt, num);
|
||||
DBG_OUTPUT_PORT.printf("Set speed to: [%u]\n", ws2812fx_speed);
|
||||
#ifdef ENABLE_HOMEASSISTANT
|
||||
stateOn = true;
|
||||
if(!ha_send_data.active()) ha_send_data.once(5, tickerSendState);
|
||||
#endif
|
||||
#ifdef ENABLE_MQTT
|
||||
@@ -548,7 +600,10 @@ void checkpayload(uint8_t * payload, bool mqtt = false, uint8_t num = 0) {
|
||||
String str_mode = String((char *) &payload[0]);
|
||||
|
||||
handleSetNamedMode(str_mode);
|
||||
Dbg_Prefix(mqtt, num);
|
||||
#ifdef ENABLE_E131
|
||||
handleE131NamedMode(str_mode);
|
||||
#endif
|
||||
Dbg_Prefix(mqtt, num);
|
||||
DBG_OUTPUT_PORT.printf("Activated mode [%u]!\n", mode);
|
||||
#ifdef ENABLE_MQTT
|
||||
mqtt_client.publish(mqtt_outtopic, String(String("OK ") + String((char *)payload)).c_str());
|
||||
@@ -615,6 +670,10 @@ void checkpayload(uint8_t * payload, bool mqtt = false, uint8_t num = 0) {
|
||||
// / ==> Set WS2812 mode.
|
||||
if (payload[0] == '/') {
|
||||
handleSetWS2812FXMode(payload);
|
||||
#ifdef ENABLE_E131
|
||||
String str_mode = String((char *) &payload[0]);
|
||||
handleE131NamedMode(str_mode);
|
||||
#endif
|
||||
Dbg_Prefix(mqtt, num);
|
||||
DBG_OUTPUT_PORT.printf("Set WS2812 mode: [%s]\n", payload);
|
||||
#ifdef ENABLE_MQTT
|
||||
@@ -747,7 +806,7 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t lenght
|
||||
}
|
||||
|
||||
void sendState() {
|
||||
const size_t bufferSize = JSON_OBJECT_SIZE(3) + JSON_OBJECT_SIZE(6);
|
||||
const size_t bufferSize = JSON_OBJECT_SIZE(3) + JSON_OBJECT_SIZE(6) + 500;
|
||||
DynamicJsonDocument jsonBuffer(bufferSize);
|
||||
JsonObject root = jsonBuffer.to<JsonObject>();
|
||||
|
||||
@@ -763,9 +822,16 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t lenght
|
||||
|
||||
root["speed"] = ws2812fx_speed;
|
||||
|
||||
char modeName[30];
|
||||
strncpy_P(modeName, (PGM_P)strip.getModeName(strip.getMode()), sizeof(modeName)); // copy from progmem
|
||||
root["effect"] = modeName;
|
||||
//char modeName[30];
|
||||
//strncpy_P(modeName, (PGM_P)strip.getModeName(strip.getMode()), sizeof(modeName)); // copy from progmem
|
||||
#if defined(ENABLE_E131) and defined(ENABLE_HOMEASSISTANT)
|
||||
if (mode == E131)
|
||||
root["effect"] = "E131";
|
||||
else
|
||||
root["effect"] = strip.getModeName(strip.getMode());
|
||||
#else
|
||||
root["effect"] = strip.getModeName(strip.getMode());
|
||||
#endif
|
||||
|
||||
char buffer[measureJson(root) + 1];
|
||||
serializeJson(root, buffer, sizeof(buffer));
|
||||
@@ -835,9 +901,7 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t lenght
|
||||
}
|
||||
|
||||
if (root.containsKey("brightness")) {
|
||||
const char * brightness_json = root["brightness"];
|
||||
uint8_t b = (uint8_t) strtol((const char *) &brightness_json[0], NULL, 10);
|
||||
brightness = constrain(b, 0, 255);
|
||||
brightness = constrain((uint8_t) root["brightness"], 0, 255); //fix #224
|
||||
mode = BRIGHTNESS;
|
||||
}
|
||||
|
||||
@@ -846,6 +910,13 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t lenght
|
||||
String effectString = root["effect"].as<String>();
|
||||
|
||||
for (uint8_t i = 0; i < strip.getModeCount(); i++) {
|
||||
#if defined(ENABLE_E131) and defined(ENABLE_HOMEASSISTANT)
|
||||
if(effectString == "E131"){
|
||||
if(strip.isRunning()) strip.stop();
|
||||
mode = E131;
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
if(String(strip.getModeName(i)) == effectString) {
|
||||
mode = SET_MODE;
|
||||
ws2812fx_mode = i;
|
||||
@@ -920,10 +991,14 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t lenght
|
||||
ha_send_data.detach();
|
||||
mqtt_client.subscribe(mqtt_ha_state_in.c_str(), qossub);
|
||||
#ifdef MQTT_HOME_ASSISTANT_SUPPORT
|
||||
DynamicJsonDocument jsonBuffer(JSON_ARRAY_SIZE(strip.getModeCount()) + JSON_OBJECT_SIZE(11));
|
||||
DynamicJsonDocument jsonBuffer(JSON_ARRAY_SIZE(strip.getModeCount()) + JSON_OBJECT_SIZE(12) + 1500);
|
||||
JsonObject json = jsonBuffer.to<JsonObject>();
|
||||
json["name"] = HOSTNAME;
|
||||
#ifdef MQTT_HOME_ASSISTANT_0_84_SUPPORT
|
||||
json["schema"] = "json";
|
||||
#else
|
||||
json["platform"] = "mqtt_json";
|
||||
#endif
|
||||
json["state_topic"] = mqtt_ha_state_out;
|
||||
json["command_topic"] = mqtt_ha_state_in;
|
||||
json["on_command_type"] = "first";
|
||||
@@ -936,6 +1011,9 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t lenght
|
||||
for (uint8_t i = 0; i < strip.getModeCount(); i++) {
|
||||
effect_list.add(strip.getModeName(i));
|
||||
}
|
||||
#if defined(ENABLE_E131) and defined(MQTT_HOME_ASSISTANT_SUPPORT)
|
||||
effect_list.add("E131");
|
||||
#endif
|
||||
char buffer[measureJson(json) + 1];
|
||||
serializeJson(json, buffer, sizeof(buffer));
|
||||
mqtt_client.publish(String("homeassistant/light/" + String(HOSTNAME) + "/config").c_str(), buffer, true);
|
||||
@@ -1016,6 +1094,9 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t lenght
|
||||
for (uint8_t i = 0; i < strip.getModeCount(); i++) {
|
||||
effect_list.add(strip.getModeName(i));
|
||||
}
|
||||
#if defined(ENABLE_E131) and defined(MQTT_HOME_ASSISTANT_SUPPORT)
|
||||
effect_list.add("E131");
|
||||
#endif
|
||||
char buffer[measureJson(json) + 1];
|
||||
serializeJson(json, buffer, sizeof(buffer));
|
||||
DBG_OUTPUT_PORT.println(buffer);
|
||||
@@ -1172,7 +1253,7 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t lenght
|
||||
uint8_t r, g, b, col, conf;
|
||||
tcs.getData(&r, &g, &b, &col, &conf);
|
||||
DBG_OUTPUT_PORT.printf("Colors: R: [%d] G: [%d] B: [%d] Color: [%d] Conf: [%d]\n", (int)r, (int)g, (int)b, (int)col, (int)conf);
|
||||
main_color.white = 0; main_color.red = (pow((r/255.0), 2.5)*255); main_color.green = (pow((g/255.0), 2.5)*255); main_color.blue = (pow((b/255.0), 2.5)*255);
|
||||
main_color.red = (pow((r/255.0), 2.5)*255); main_color.green = (pow((g/255.0), 2.5)*255); main_color.blue = (pow((b/255.0), 2.5)*255);main_color.white = 0;
|
||||
ws2812fx_mode = 0;
|
||||
mode = SET_MODE;
|
||||
buttonState = true;
|
||||
@@ -1241,14 +1322,14 @@ bool writeConfigFS(bool saveConfig){
|
||||
//FS save
|
||||
updateFS = true;
|
||||
DBG_OUTPUT_PORT.print("Saving config: ");
|
||||
DynamicJsonDocument jsonBuffer(JSON_OBJECT_SIZE(4));
|
||||
DynamicJsonDocument jsonBuffer;
|
||||
JsonObject json = jsonBuffer.to<JsonObject>();
|
||||
json["mqtt_host"] = mqtt_host;
|
||||
json["mqtt_port"] = mqtt_port;
|
||||
json["mqtt_user"] = mqtt_user;
|
||||
json["mqtt_pass"] = mqtt_pass;
|
||||
|
||||
// SPIFFS.remove("/config.json") ? DBG_OUTPUT_PORT.println("removed file") : DBG_OUTPUT_PORT.println("failed removing file");
|
||||
//SPIFFS.remove("/config.json") ? DBG_OUTPUT_PORT.println("removed file") : DBG_OUTPUT_PORT.println("failed removing file");
|
||||
File configFile = SPIFFS.open("/config.json", "w");
|
||||
if (!configFile) DBG_OUTPUT_PORT.println("failed to open config file for writing");
|
||||
|
||||
@@ -1310,18 +1391,18 @@ bool writeStateFS(){
|
||||
updateFS = true;
|
||||
//save the strip state to FS JSON
|
||||
DBG_OUTPUT_PORT.print("Saving cfg: ");
|
||||
DynamicJsonDocument jsonBuffer(JSON_OBJECT_SIZE(7));
|
||||
DynamicJsonDocument jsonBuffer;
|
||||
JsonObject json = jsonBuffer.to<JsonObject>();
|
||||
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["white"] = main_color.white;
|
||||
|
||||
// SPIFFS.remove("/state.json") ? DBG_OUTPUT_PORT.println("removed file") : DBG_OUTPUT_PORT.println("failed removing file");
|
||||
//SPIFFS.remove("/stripstate.json") ? DBG_OUTPUT_PORT.println("removed file") : DBG_OUTPUT_PORT.println("failed removing file");
|
||||
File configFile = SPIFFS.open("/stripstate.json", "w");
|
||||
if (!configFile) {
|
||||
DBG_OUTPUT_PORT.println("Failed!");
|
||||
@@ -1362,15 +1443,21 @@ bool readStateFS() {
|
||||
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"];
|
||||
main_color.blue = json["blue"];
|
||||
|
||||
main_color.white = json["white"];
|
||||
|
||||
strip.setMode(ws2812fx_mode);
|
||||
strip.setSpeed(convertSpeed(ws2812fx_speed));
|
||||
strip.setBrightness(brightness);
|
||||
strip.setColor(main_color.white, main_color.red, main_color.green, main_color.blue);
|
||||
strip.setColor(main_color.red, main_color.green, main_color.blue, main_color.white);
|
||||
|
||||
#ifdef ENABLE_E131
|
||||
if (mode == E131) {
|
||||
strip.stop();
|
||||
}
|
||||
#endif
|
||||
|
||||
updateFS = false;
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user