From c1c24b42d07a127553a5a2aababd20c7fb92c679 Mon Sep 17 00:00:00 2001 From: debsahu Date: Sun, 22 Apr 2018 10:01:59 -0400 Subject: [PATCH 1/2] Solve getstatus not return values correctly Resolve https://github.com/toblum/McLighting/issues/146 --- Arduino/McLighting/request_handlers.h | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/Arduino/McLighting/request_handlers.h b/Arduino/McLighting/request_handlers.h index 3a3a7ec..ec3210a 100644 --- a/Arduino/McLighting/request_handlers.h +++ b/Arduino/McLighting/request_handlers.h @@ -283,18 +283,12 @@ void handleSetWS2812FXMode(uint8_t * mypayload) { char* listStatusJSON() { char json[255]; - char modeName[30]; - -// if (mode == SET_MODE) { - strncpy_P(modeName, (PGM_P)strip.getModeName((uint8_t) ws2812fx_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, ws2812fx_mode, modeName, ws2812fx_speed, brightness, main_color.red, main_color.green, main_color.blue); -// }else { -// 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]}", -// mode, strip.getMode(), modeName, ws2812fx_speed, brightness, 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; } @@ -1436,4 +1430,4 @@ bool readStateFS() { updateFS = false; return false; } -#endif \ No newline at end of file +#endif From ba5146d3d7687d9648b2d9ad99ea798873538e4c Mon Sep 17 00:00:00 2001 From: debsahu Date: Sun, 22 Apr 2018 10:36:00 -0400 Subject: [PATCH 2/2] Use global variables to handle websocket request modified handleSetWS2812FXMode to use global variables --- Arduino/McLighting/request_handlers.h | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/Arduino/McLighting/request_handlers.h b/Arduino/McLighting/request_handlers.h index ec3210a..7f42e47 100644 --- a/Arduino/McLighting/request_handlers.h +++ b/Arduino/McLighting/request_handlers.h @@ -273,12 +273,9 @@ void setModeByStateString(String saved_state_string) { #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.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() {