Bug Fixes

Bug Fixes
This commit is contained in:
BPoH_Voodoo
2019-01-30 15:13:31 +01:00
parent 6d524787bd
commit 766b3fb76a
6 changed files with 59 additions and 96 deletions
+5 -1
View File
@@ -112,7 +112,11 @@ ESP8266HTTPUpdateServer httpUpdater;
#ifdef USE_WS2812FX_DMA #ifdef USE_WS2812FX_DMA
#include <NeoPixelBus.h> #include <NeoPixelBus.h>
#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) 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) //NeoEsp8266Dma400KbpsMethod dma = NeoEsp8266Dma400KbpsMethod(NUMLEDS, 3); //400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
#endif #endif
#ifdef USE_WS2812FX_UART #ifdef USE_WS2812FX_UART
@@ -711,7 +715,7 @@ DBG_OUTPUT_PORT.println("Starting....");
server.on("/get_color", []() { server.on("/get_color", []() {
char rgbcolor[9]; 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.sendHeader("Access-Control-Allow-Origin", "*");
server.send(200, "text/plain", rgbcolor ); server.send(200, "text/plain", rgbcolor );
DBG_OUTPUT_PORT.print("/get_color: "); DBG_OUTPUT_PORT.print("/get_color: ");
+1 -1
View File
@@ -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) { 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) { void WS2812FX::setColor(uint32_t c) {
+38 -42
View File
@@ -49,10 +49,10 @@ void tickerSpiffsSaveState(){
void getArgs() { void getArgs() {
if (server.arg("rgb") != "") { if (server.arg("rgb") != "") {
uint32_t rgb = (uint32_t) strtoul(server.arg("rgb").c_str(), NULL, 16); uint32_t rgb = (uint32_t) strtoul(server.arg("rgb").c_str(), NULL, 16);
main_color.red = ((rgb >> 24) & 0xFF); main_color.white = ((rgb >> 24) & 0xFF);
main_color.green = ((rgb >> 16) & 0xFF); main_color.red = ((rgb >> 16) & 0xFF);
main_color.blue = ((rgb >> 8) & 0xFF); main_color.green = ((rgb >> 8) & 0xFF);
main_color.white = ((rgb >> 0) & 0xFF); main_color.blue = ((rgb >> 0) & 0xFF);
} else { } else {
main_color.red = server.arg("r").toInt(); main_color.red = server.arg("r").toInt();
main_color.green = server.arg("g").toInt(); main_color.green = server.arg("g").toInt();
@@ -115,10 +115,10 @@ uint16_t convertSpeed(uint8_t mcl_speed) {
void handleSetMainColor(uint8_t * mypayload) { void handleSetMainColor(uint8_t * mypayload) {
// decode rgb data // decode rgb data
uint32_t rgb = (uint32_t) strtoul((const char *) &mypayload[1], NULL, 16); uint32_t rgb = (uint32_t) strtoul((const char *) &mypayload[1], NULL, 16);
main_color.red = ((rgb >> 24) & 0xFF); main_color.white = ((rgb >> 24) & 0xFF);
main_color.green = ((rgb >> 16) & 0xFF); main_color.red = ((rgb >> 16) & 0xFF);
main_color.blue = ((rgb >> 8) & 0xFF); main_color.green = ((rgb >> 8) & 0xFF);
main_color.white = ((rgb >> 0) & 0xFF); main_color.blue = ((rgb >> 0) & 0xFF);
// strip.setColor(main_color.red, main_color.green, main_color.blue); // strip.setColor(main_color.red, main_color.green, main_color.blue);
mode = SETCOLOR; mode = SETCOLOR;
} }
@@ -127,10 +127,10 @@ void handleSetAllMode(uint8_t * mypayload) {
// decode rgb data // decode rgb data
uint32_t rgb = (uint32_t) strtoul((const char *) &mypayload[1], NULL, 16); uint32_t rgb = (uint32_t) strtoul((const char *) &mypayload[1], NULL, 16);
main_color.red = ((rgb >> 24) & 0xFF); main_color.white = ((rgb >> 24) & 0xFF);
main_color.green = ((rgb >> 16) & 0xFF); main_color.red = ((rgb >> 16) & 0xFF);
main_color.blue = ((rgb >> 8) & 0xFF); main_color.green = ((rgb >> 8) & 0xFF);
main_color.white = ((rgb >> 0) & 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); 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 #ifdef ENABLE_LEGACY_ANIMATIONS
@@ -155,7 +155,7 @@ void handleSetSingleLED(uint8_t * mypayload, uint8_t firstChar = 0) {
strncpy (redhex, (const char *) &mypayload[2 + firstChar], 2 ); strncpy (redhex, (const char *) &mypayload[2 + firstChar], 2 );
strncpy (greenhex, (const char *) &mypayload[4 + firstChar], 2 ); strncpy (greenhex, (const char *) &mypayload[4 + firstChar], 2 );
strncpy (bluehex, (const char *) &mypayload[6 + 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].red = strtol(redhex, NULL, 16);
ledstates[led].green = strtol(greenhex, NULL, 16); ledstates[led].green = strtol(greenhex, NULL, 16);
ledstates[led].blue = strtol(bluehex, 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); 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; exit_func = true;
if (str_mode.startsWith("=off")) { if (str_mode.startsWith("=off") or str_mode.startsWith("/off")) {
mode = OFF; mode = OFF;
#ifdef ENABLE_HOMEASSISTANT #ifdef ENABLE_HOMEASSISTANT
stateOn = false; stateOn = false;
#endif #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")) { if (str_mode.startsWith("=auto")) {
mode = AUTO; mode = AUTO;
#ifdef ENABLE_HOMEASSISTANT #ifdef ENABLE_HOMEASSISTANT
@@ -309,28 +323,8 @@ void setModeByStateString(String saved_state_string) {
stateOn = true; stateOn = true;
#endif #endif
} }
if (str_mode.startsWith("=tv")) {
mode = TV;
#ifdef ENABLE_HOMEASSISTANT
stateOn = true;
#endif #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) { void handleSetWS2812FXMode(uint8_t * mypayload) {
mode = SET_MODE; mode = SET_MODE;
uint8_t ws2812fx_mode_tmp = (uint8_t) strtol((const char *) &mypayload[1], NULL, 10); 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["speed"] = ws2812fx_speed;
root["brightness"] = brightness; root["brightness"] = brightness;
JsonArray color = root.createNestedArray("color"); JsonArray color = root.createNestedArray("color");
color.add(main_color.white);
color.add(main_color.red); color.add(main_color.red);
color.add(main_color.green); color.add(main_color.green);
color.add(main_color.blue); color.add(main_color.blue);
color.add(main_color.white);
String json; String json;
serializeJson(root, 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; const size_t bufferSize = JSON_ARRAY_SIZE(strip.getModeCount()+1) + strip.getModeCount()*JSON_OBJECT_SIZE(2) + 1000;
DynamicJsonDocument jsonBuffer(bufferSize); DynamicJsonDocument jsonBuffer(bufferSize);
JsonArray json = jsonBuffer.to<JsonArray>(); JsonArray json = jsonBuffer.to<JsonArray>();
JsonObject objectoff = json.createNestedObject();
objectoff["mode"] = "off";
objectoff["name"] = "OFF";
JsonObject objecttv = json.createNestedObject();
objecttv["mode"] = "tv";
objecttv["name"] = "TV";
#ifdef ENABLE_E131 #ifdef ENABLE_E131
JsonObject objecte131 = json.createNestedObject(); JsonObject objecte131 = json.createNestedObject();
objecte131["mode"] = "e131"; objecte131["mode"] = "e131";
@@ -600,9 +600,6 @@ void checkpayload(uint8_t * payload, bool mqtt = false, uint8_t num = 0) {
String str_mode = String((char *) &payload[0]); String str_mode = String((char *) &payload[0]);
handleSetNamedMode(str_mode); 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); DBG_OUTPUT_PORT.printf("Activated mode [%u]!\n", mode);
#ifdef ENABLE_MQTT #ifdef ENABLE_MQTT
@@ -670,10 +667,8 @@ void checkpayload(uint8_t * payload, bool mqtt = false, uint8_t num = 0) {
// / ==> Set WS2812 mode. // / ==> Set WS2812 mode.
if (payload[0] == '/') { if (payload[0] == '/') {
handleSetWS2812FXMode(payload); handleSetWS2812FXMode(payload);
#ifdef ENABLE_E131
String str_mode = String((char *) &payload[0]); String str_mode = String((char *) &payload[0]);
handleE131NamedMode(str_mode); handleSetNamedMode(str_mode);
#endif
Dbg_Prefix(mqtt, num); Dbg_Prefix(mqtt, num);
DBG_OUTPUT_PORT.printf("Set WS2812 mode: [%s]\n", payload); DBG_OUTPUT_PORT.printf("Set WS2812 mode: [%s]\n", payload);
#ifdef ENABLE_MQTT #ifdef ENABLE_MQTT
@@ -815,6 +810,7 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t lenght
color["r"] = main_color.red; color["r"] = main_color.red;
color["g"] = main_color.green; color["g"] = main_color.green;
color["b"] = main_color.blue; color["b"] = main_color.blue;
color["w"] = main_color.white;
root["brightness"] = brightness; root["brightness"] = brightness;
+2 -20
View File
@@ -208,36 +208,18 @@ $(function(){
$('#status').css("backgroundColor", statusColor); $('#status').css("backgroundColor", statusColor);
$('#status_color').text(statusColor + "- R=" + data.color[1] + ", G=" + data.color[2] + ", B=" + data.color[3]); $('#status_color').text(statusColor + "- R=" + data.color[1] + ", G=" + data.color[2] + ", B=" + data.color[3]);
}); });
// Load modes async // Load modes async
// List of all color modes // List of all color modes
// enum MODE { SET_MODE, HOLD, AUTO, OFF, TV, CUSTOM, SETCOLOR, SETSPEED, BRIGHTNESS, WIPE, RAINBOW, RAINBOWCYCLE, THEATERCHASE, TWINKLERANDOM, THEATERCHASERAINBOW}; // 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) { $.getJSON("http://" + host + "/get_modes", function(data) {
console.log("modes", data); console.log("modes", data);
var modes_html = ""; var modes_html = "";
modes_html += '<div class="col s12 m6 l6 btn_grid">';
if (mode == "3") {
modes_html += '<a class="btn waves-effect waves-light btn_mode_static red" name="action" data-mode="off">OFF';
} else {
modes_html += '<a class="btn waves-effect waves-light btn_mode_static blue" name="action" data-mode="off">OFF';
}
modes_html += '<i class="material-icons right">send</i>';
modes_html += '</a>';
modes_html += '</div>'
modes_html += '<div class="col s12 m6 l6 btn_grid">';
if (mode == "4") {
modes_html += '<a class="btn waves-effect waves-light btn_mode_static red" name="action" data-mode="tv">TV';
} else {
modes_html += '<a class="btn waves-effect waves-light btn_mode_static blue" name="action" data-mode="tv">TV';
}
modes_html += '<i class="material-icons right">send</i>';
modes_html += '</a>';
modes_html += '</div>';
data.forEach(function(current_mode){ data.forEach(function(current_mode){
if (current_mode.mode !== undefined) { if (current_mode.mode !== undefined) {
modes_html += '<div class="col s12 m6 l6 btn_grid">'; modes_html += '<div class="col s12 m6 l6 btn_grid">';
if (mode == "1" && current_mode.mode == ws2812fx_mode) { 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 += '<a class="btn waves-effect waves-light btn_mode red" name="action" data-mode="' + current_mode.mode + '">(' + current_mode.mode +') '+ current_mode.name; modes_html += '<a class="btn waves-effect waves-light btn_mode red" name="action" data-mode="' + current_mode.mode + '">(' + current_mode.mode +') '+ current_mode.name;
} else { } else {
modes_html += '<a class="btn waves-effect waves-light btn_mode blue" name="action" data-mode="' + current_mode.mode + '">(' + current_mode.mode +') '+ current_mode.name; modes_html += '<a class="btn waves-effect waves-light btn_mode blue" name="action" data-mode="' + current_mode.mode + '">(' + current_mode.mode +') '+ current_mode.name;
} }
+2 -21
View File
@@ -56,34 +56,15 @@ $(function(){
// Load modes async // Load modes async
// List of all color modes // 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) { $.getJSON("http://" + host + "/get_modes", function(data) {
console.log("modes", data); console.log("modes", data);
var modes_html = ""; var modes_html = "";
modes_html += '<div class="col s12 m6 l6 btn_grid">';
if (mode == "3") {
modes_html += '<a class="btn waves-effect waves-light btn_mode_static red" name="action" data-mode="off">OFF';
} else {
modes_html += '<a class="btn waves-effect waves-light btn_mode_static blue" name="action" data-mode="off">OFF';
}
modes_html += '<i class="material-icons right">send</i>';
modes_html += '</a>';
modes_html += '</div>'
modes_html += '<div class="col s12 m6 l6 btn_grid">';
if (mode == "4") {
modes_html += '<a class="btn waves-effect waves-light btn_mode_static red" name="action" data-mode="tv">TV';
} else {
modes_html += '<a class="btn waves-effect waves-light btn_mode_static blue" name="action" data-mode="tv">TV';
}
modes_html += '<i class="material-icons right">send</i>';
modes_html += '</a>';
modes_html += '</div>';
data.forEach(function(current_mode){ data.forEach(function(current_mode){
if (current_mode.mode !== undefined) { if (current_mode.mode !== undefined) {
modes_html += '<div class="col s12 m6 l6 btn_grid">'; modes_html += '<div class="col s12 m6 l6 btn_grid">';
if (mode == "1" && current_mode.mode == ws2812fx_mode) { 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 += '<a class="btn waves-effect waves-light btn_mode red" name="action" data-mode="' + current_mode.mode + '">(' + current_mode.mode +') '+ current_mode.name; modes_html += '<a class="btn waves-effect waves-light btn_mode red" name="action" data-mode="' + current_mode.mode + '">(' + current_mode.mode +') '+ current_mode.name;
} else { } else {
modes_html += '<a class="btn waves-effect waves-light btn_mode blue" name="action" data-mode="' + current_mode.mode + '">(' + current_mode.mode +') '+ current_mode.name; modes_html += '<a class="btn waves-effect waves-light btn_mode blue" name="action" data-mode="' + current_mode.mode + '">(' + current_mode.mode +') '+ current_mode.name;
} }