From 766b3fb76a968645b95a2d0086b7a53a78a377e8 Mon Sep 17 00:00:00 2001 From: BPoH_Voodoo Date: Wed, 30 Jan 2019 15:13:31 +0100 Subject: [PATCH] Bug Fixes Bug Fixes --- Arduino/McLighting/McLighting.ino | 8 ++- Arduino/McLighting/WS2812FX.cpp | 2 +- Arduino/McLighting/WS2812FX.h | 2 +- Arduino/McLighting/request_handlers.h | 92 +++++++++++++-------------- clients/web(RGBW)/build/index.htm | 26 ++------ clients/web(RGBW)/src/js/script.js | 25 +------- 6 files changed, 59 insertions(+), 96 deletions(-) diff --git a/Arduino/McLighting/McLighting.ino b/Arduino/McLighting/McLighting.ino index b357bf7..0ba8cc5 100644 --- a/Arduino/McLighting/McLighting.ino +++ b/Arduino/McLighting/McLighting.ino @@ -112,7 +112,11 @@ ESP8266HTTPUpdateServer httpUpdater; #ifdef USE_WS2812FX_DMA #include - NeoEsp8266Dma800KbpsMethod dma = NeoEsp8266Dma800KbpsMethod(NUMLEDS, 3); //800 KHz bitstream (most NeoPixel products w/WS2812 LEDs) + #ifdef RGBW + NeoEsp8266Dma800KbpsMethod dma = NeoEsp8266Dma800KbpsMethod(NUMLEDS, 4); //800 KHz bitstream (most NeoPixel products w/WS2812 LEDs) + #else + NeoEsp8266Dma800KbpsMethod dma = NeoEsp8266Dma800KbpsMethod(NUMLEDS, 3); //800 KHz bitstream (most NeoPixel products w/WS2812 LEDs) + #endif //NeoEsp8266Dma400KbpsMethod dma = NeoEsp8266Dma400KbpsMethod(NUMLEDS, 3); //400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers) #endif #ifdef USE_WS2812FX_UART @@ -711,7 +715,7 @@ DBG_OUTPUT_PORT.println("Starting...."); server.on("/get_color", []() { char rgbcolor[9]; - snprintf(rgbcolor, sizeof(rgbcolor), "%02X%02X%02X%02X", main_color.red, main_color.green, main_color.blue, main_color.white); + snprintf(rgbcolor, sizeof(rgbcolor), "%02X%02X%02X%02X", main_color.white, main_color.red, main_color.green, main_color.blue); server.sendHeader("Access-Control-Allow-Origin", "*"); server.send(200, "text/plain", rgbcolor ); DBG_OUTPUT_PORT.print("/get_color: "); diff --git a/Arduino/McLighting/WS2812FX.cpp b/Arduino/McLighting/WS2812FX.cpp index c03196c..55fbb6e 100644 --- a/Arduino/McLighting/WS2812FX.cpp +++ b/Arduino/McLighting/WS2812FX.cpp @@ -193,7 +193,7 @@ void WS2812FX::setColor(uint8_t r, uint8_t g, uint8_t b) { } void WS2812FX::setColor(uint8_t r, uint8_t g, uint8_t b, uint8_t w) { - setColor((((uint32_t)r << 24)| ((uint32_t)g << 16) | ((uint32_t)b << 8)| ((uint32_t)w))); + setColor((((uint32_t)w << 24)| ((uint32_t)r << 16) | ((uint32_t)g << 8)| ((uint32_t)b))); } void WS2812FX::setColor(uint32_t c) { diff --git a/Arduino/McLighting/WS2812FX.h b/Arduino/McLighting/WS2812FX.h index bfc3ef4..0c2503a 100644 --- a/Arduino/McLighting/WS2812FX.h +++ b/Arduino/McLighting/WS2812FX.h @@ -431,7 +431,7 @@ class WS2812FX : public Adafruit_NeoPixel { increaseSpeed(uint8_t s), decreaseSpeed(uint8_t s), setColor(uint8_t r, uint8_t g, uint8_t b), - setColor(uint8_t r, uint8_t g, uint8_t b, uint8_t w), + setColor(uint8_t r, uint8_t g, uint8_t b, uint8_t w), setColor(uint32_t c), setColor(uint8_t seg, uint32_t c), setColors(uint8_t seg, uint32_t* c), diff --git a/Arduino/McLighting/request_handlers.h b/Arduino/McLighting/request_handlers.h index 030bdab..26c8a3f 100644 --- a/Arduino/McLighting/request_handlers.h +++ b/Arduino/McLighting/request_handlers.h @@ -49,15 +49,15 @@ void tickerSpiffsSaveState(){ void getArgs() { if (server.arg("rgb") != "") { uint32_t rgb = (uint32_t) strtoul(server.arg("rgb").c_str(), NULL, 16); - main_color.red = ((rgb >> 24) & 0xFF); - main_color.green = ((rgb >> 16) & 0xFF); - main_color.blue = ((rgb >> 8) & 0xFF); - main_color.white = ((rgb >> 0) & 0xFF); + main_color.white = ((rgb >> 24) & 0xFF); + main_color.red = ((rgb >> 16) & 0xFF); + main_color.green = ((rgb >> 8) & 0xFF); + main_color.blue = ((rgb >> 0) & 0xFF); } else { main_color.red = server.arg("r").toInt(); main_color.green = server.arg("g").toInt(); main_color.blue = server.arg("b").toInt(); - main_color.white = server.arg("w").toInt(); + main_color.white = server.arg("w").toInt(); } if (server.arg("s") != "") { ws2812fx_speed = constrain(server.arg("s").toInt(), 0, 255); @@ -115,10 +115,10 @@ 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.red = ((rgb >> 24) & 0xFF); - main_color.green = ((rgb >> 16) & 0xFF); - main_color.blue = ((rgb >> 8) & 0xFF); - main_color.white = ((rgb >> 0) & 0xFF); + main_color.white = ((rgb >> 24) & 0xFF); + main_color.red = ((rgb >> 16) & 0xFF); + main_color.green = ((rgb >> 8) & 0xFF); + main_color.blue = ((rgb >> 0) & 0xFF); // strip.setColor(main_color.red, main_color.green, main_color.blue); mode = SETCOLOR; } @@ -127,10 +127,10 @@ void handleSetAllMode(uint8_t * mypayload) { // decode rgb data uint32_t rgb = (uint32_t) strtoul((const char *) &mypayload[1], NULL, 16); - main_color.red = ((rgb >> 24) & 0xFF); - main_color.green = ((rgb >> 16) & 0xFF); - main_color.blue = ((rgb >> 8) & 0xFF); - main_color.white = ((rgb >> 0) & 0xFF); + main_color.white = ((rgb >> 24) & 0xFF); + main_color.red = ((rgb >> 16) & 0xFF); + main_color.green = ((rgb >> 8) & 0xFF); + main_color.blue = ((rgb >> 0) & 0xFF); 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 @@ -151,11 +151,11 @@ void handleSetSingleLED(uint8_t * mypayload, uint8_t firstChar = 0) { char redhex[3]; char greenhex[3]; char bluehex[3]; - char whitehex[3]; + 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 ); + strncpy (whitehex, (const char *) &mypayload[8 + firstChar], 2 ); ledstates[led].red = strtol(redhex, NULL, 16); ledstates[led].green = strtol(greenhex, NULL, 16); ledstates[led].blue = strtol(bluehex, NULL, 16); @@ -250,16 +250,30 @@ void setModeByStateString(String saved_state_string) { strip.setColor(main_color.red, main_color.green, main_color.blue, main_color.white); } -#ifdef ENABLE_LEGACY_ANIMATIONS - void handleSetNamedMode(String str_mode) { + +void handleSetNamedMode(String str_mode) { exit_func = true; - if (str_mode.startsWith("=off")) { + if (str_mode.startsWith("=off") or str_mode.startsWith("/off")) { mode = OFF; #ifdef ENABLE_HOMEASSISTANT stateOn = false; #endif } + if (str_mode.startsWith("=tv") or str_mode.startsWith("/tv")) { + mode = TV; + #ifdef ENABLE_HOMEASSISTANT + stateOn = true; + #endif + } + if (str_mode.startsWith("=e131") or str_mode.startsWith("/e131")) { + if(strip.isRunning()) strip.stop(); + mode = E131; + #ifdef ENABLE_HOMEASSISTANT + stateOn = true; + #endif + } +#ifdef ENABLE_LEGACY_ANIMATIONS if (str_mode.startsWith("=auto")) { mode = AUTO; #ifdef ENABLE_HOMEASSISTANT @@ -309,28 +323,8 @@ void setModeByStateString(String saved_state_string) { stateOn = true; #endif } - if (str_mode.startsWith("=tv")) { - mode = TV; - #ifdef ENABLE_HOMEASSISTANT - stateOn = true; - #endif - } - } #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); @@ -349,10 +343,10 @@ 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); @@ -369,6 +363,12 @@ String listModesJSON(void) { const size_t bufferSize = JSON_ARRAY_SIZE(strip.getModeCount()+1) + strip.getModeCount()*JSON_OBJECT_SIZE(2) + 1000; DynamicJsonDocument jsonBuffer(bufferSize); JsonArray json = jsonBuffer.to(); + JsonObject objectoff = json.createNestedObject(); + objectoff["mode"] = "off"; + objectoff["name"] = "OFF"; + JsonObject objecttv = json.createNestedObject(); + objecttv["mode"] = "tv"; + objecttv["name"] = "TV"; #ifdef ENABLE_E131 JsonObject objecte131 = json.createNestedObject(); objecte131["mode"] = "e131"; @@ -600,10 +600,7 @@ void checkpayload(uint8_t * payload, bool mqtt = false, uint8_t num = 0) { String str_mode = String((char *) &payload[0]); handleSetNamedMode(str_mode); - #ifdef ENABLE_E131 - handleE131NamedMode(str_mode); - #endif - Dbg_Prefix(mqtt, num); + 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()); @@ -670,10 +667,8 @@ 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 + handleSetNamedMode(str_mode); Dbg_Prefix(mqtt, num); DBG_OUTPUT_PORT.printf("Set WS2812 mode: [%s]\n", payload); #ifdef ENABLE_MQTT @@ -815,7 +810,8 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t lenght color["r"] = main_color.red; color["g"] = main_color.green; color["b"] = main_color.blue; - + color["w"] = main_color.white; + root["brightness"] = brightness; root["color_temp"] = color_temp; diff --git a/clients/web(RGBW)/build/index.htm b/clients/web(RGBW)/build/index.htm index d176d47..0f38b88 100644 --- a/clients/web(RGBW)/build/index.htm +++ b/clients/web(RGBW)/build/index.htm @@ -208,36 +208,18 @@ $(function(){ $('#status').css("backgroundColor", statusColor); $('#status_color').text(statusColor + "- R=" + data.color[1] + ", G=" + data.color[2] + ", B=" + data.color[3]); }); + // Load modes async // List of all color modes // enum MODE { SET_MODE, HOLD, AUTO, OFF, TV, CUSTOM, SETCOLOR, SETSPEED, BRIGHTNESS, WIPE, RAINBOW, RAINBOWCYCLE, THEATERCHASE, TWINKLERANDOM, THEATERCHASERAINBOW}; $.getJSON("http://" + host + "/get_modes", function(data) { console.log("modes", data); var modes_html = ""; - modes_html += '
'; - if (mode == "3") { - modes_html += 'OFF'; - } else { - modes_html += 'OFF'; - } - modes_html += 'send'; - modes_html += ''; - modes_html += '
' - modes_html += '
'; - if (mode == "4") { - modes_html += 'TV'; - } else { - modes_html += 'TV'; - } - modes_html += 'send'; - modes_html += ''; - modes_html += '
'; data.forEach(function(current_mode){ if (current_mode.mode !== undefined) { modes_html += '
'; - if (mode == "1" && current_mode.mode == ws2812fx_mode) { - modes_html += '(' + current_mode.mode +') '+ current_mode.name; - + if ((mode == "1" && current_mode.mode == ws2812fx_mode) || (mode == "3" && current_mode.mode == "off") || (mode == "4" && current_mode.mode == "tv") || (mode == "15" && current_mode.mode == "e131")){ + modes_html += '(' + current_mode.mode +') '+ current_mode.name; } else { modes_html += '(' + current_mode.mode +') '+ current_mode.name; } @@ -457,7 +439,7 @@ $(function(){ hexColor = "#" + hexColor; $('#status').css("backgroundColor", hexColor); - $('#status_color').text(hexColor + "- R=" + color[0] + ", G=" + color[1] + ", B=" + color[2]); + $('#status_color').text(hexColor + " - R=" + color[0] + ", G=" + color[1] + ", B=" + color[2]); $('#status_pos').text("x: " + pos.x + " - y: " + pos.y); $("#rng_white").val(0); diff --git a/clients/web(RGBW)/src/js/script.js b/clients/web(RGBW)/src/js/script.js index 23e6651..4640076 100644 --- a/clients/web(RGBW)/src/js/script.js +++ b/clients/web(RGBW)/src/js/script.js @@ -56,34 +56,15 @@ $(function(){ // Load modes async // List of all color modes - // enum MODE { SET_MODE, HOLD, OFF, ALL, WIPE, RAINBOW, RAINBOWCYCLE, THEATERCHASE, TWINKLERANDOM, THEATERCHASERAINBOW, TV, CUSTOM, AUTO }; + // enum MODE { SET_MODE, HOLD, AUTO, OFF, TV, CUSTOM, SETCOLOR, SETSPEED, BRIGHTNESS, WIPE, RAINBOW, RAINBOWCYCLE, THEATERCHASE, TWINKLERANDOM, THEATERCHASERAINBOW}; $.getJSON("http://" + host + "/get_modes", function(data) { console.log("modes", data); var modes_html = ""; - modes_html += '' - modes_html += '
'; - if (mode == "4") { - modes_html += 'TV'; - } else { - modes_html += 'TV'; - } - modes_html += 'send'; - modes_html += ''; - modes_html += '
'; data.forEach(function(current_mode){ if (current_mode.mode !== undefined) { modes_html += '