From a38e3865778865f3ea4f1b9b853f597133645f60 Mon Sep 17 00:00:00 2001 From: Matt Johnson Date: Wed, 22 Nov 2017 23:26:42 +0000 Subject: [PATCH 1/4] Remove unnecessary loop from handleSetSingleLED() --- Arduino/McLighting/request_handlers.h | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/Arduino/McLighting/request_handlers.h b/Arduino/McLighting/request_handlers.h index aeb4b21..3f7b3ba 100644 --- a/Arduino/McLighting/request_handlers.h +++ b/Arduino/McLighting/request_handlers.h @@ -73,17 +73,14 @@ void handleSetSingleLED(uint8_t * mypayload, uint8_t firstChar = 1) { char templed[3]; strncpy ( templed, (const char *) &mypayload[firstChar], 2 ); uint8_t led = atoi(templed); - + if (led <= strip.numPixels()) { ledstates[led].red = ((rgb >> 16) & 0xFF); ledstates[led].green = ((rgb >> 8) & 0xFF); ledstates[led].blue = ((rgb >> 0) & 0xFF); DBG_OUTPUT_PORT.printf("WS: Set single led [%u] to [%u] [%u] [%u] (%s)!\n", led, ledstates[led].red, ledstates[led].green, ledstates[led].blue, mypayload); - for (uint8_t i = 0; i < strip.numPixels(); i++) { - strip.setPixelColor(i, ledstates[i].red, ledstates[i].green, ledstates[i].blue); - //DBG_OUTPUT_PORT.printf("[%u]--[%u] [%u] [%u] [%u] LED index!\n", rgb, i, ledstates[i].red, ledstates[i].green, ledstates[i].blue); - } + strip.setPixelColor(led, ledstates[led].red, ledstates[led].green, ledstates[led].blue); strip.show(); } exit_func = true; From 19dbd5ccdbad33e61ef3c5697156d5d34ca7434a Mon Sep 17 00:00:00 2001 From: Matt Johnson Date: Thu, 23 Nov 2017 01:14:24 +0000 Subject: [PATCH 2/4] example working rewrite of handleSetSingleLED(). Fixes LED's between 80-99 for me --- Arduino/McLighting/request_handlers.h | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/Arduino/McLighting/request_handlers.h b/Arduino/McLighting/request_handlers.h index 3f7b3ba..255e0fd 100644 --- a/Arduino/McLighting/request_handlers.h +++ b/Arduino/McLighting/request_handlers.h @@ -67,19 +67,30 @@ void handleSetAllMode(uint8_t * mypayload) { mode = ALL; } -void handleSetSingleLED(uint8_t * mypayload, uint8_t firstChar = 1) { +void handleSetSingleLED(uint8_t * mypayload, uint8_t firstChar = 0) { // decode led index - uint64_t rgb = (uint64_t) strtol((const char *) &mypayload[firstChar], NULL, 16); char templed[3]; - strncpy ( templed, (const char *) &mypayload[firstChar], 2 ); + strncpy (templed, (const char *) &mypayload[firstChar], 2 ); uint8_t led = atoi(templed); - - if (led <= strip.numPixels()) { - ledstates[led].red = ((rgb >> 16) & 0xFF); - ledstates[led].green = ((rgb >> 8) & 0xFF); - ledstates[led].blue = ((rgb >> 0) & 0xFF); + + //DBG_OUTPUT_PORT.printf("led value: [%i]. Entry threshold: <= [%i]\n", led, strip.numPixels() ); + if (led <= strip.numPixels()) { + char redhex[3]; + char greenhex[3]; + char bluehex[3]; + strncpy (redhex, (const char *) &mypayload[2], 2 ); + strncpy (greenhex, (const char *) &mypayload[4], 2 ); + strncpy (bluehex, (const char *) &mypayload[6], 2 ); + ledstates[led].red = 0; + ledstates[led].green = 0; + ledstates[led].blue = 0; + 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.red: [%i] rgb.green: [%i] rgb.blue: [%i]\n", strtol(redhex, NULL, 16), strtol(greenhex, NULL, 16), strtol(bluehex, NULL, 16)); DBG_OUTPUT_PORT.printf("WS: Set single led [%u] to [%u] [%u] [%u] (%s)!\n", led, ledstates[led].red, ledstates[led].green, ledstates[led].blue, mypayload); + strip.setPixelColor(led, ledstates[led].red, ledstates[led].green, ledstates[led].blue); strip.show(); } From e34ffcb983f69b8171ce33b51b6ff793cb1813fb Mon Sep 17 00:00:00 2001 From: Matt Johnson Date: Thu, 23 Nov 2017 01:24:37 +0000 Subject: [PATCH 3/4] this debug printf fixes things... WTF --- Arduino/McLighting/request_handlers.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Arduino/McLighting/request_handlers.h b/Arduino/McLighting/request_handlers.h index 255e0fd..7a07337 100644 --- a/Arduino/McLighting/request_handlers.h +++ b/Arduino/McLighting/request_handlers.h @@ -87,8 +87,8 @@ void handleSetSingleLED(uint8_t * mypayload, uint8_t firstChar = 0) { 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.red: [%i] rgb.green: [%i] rgb.blue: [%i]\n", strtol(redhex, NULL, 16), strtol(greenhex, NULL, 16), strtol(bluehex, NULL, 16)); - DBG_OUTPUT_PORT.printf("WS: Set single led [%u] to [%u] [%u] [%u] (%s)!\n", led, ledstates[led].red, ledstates[led].green, ledstates[led].blue, mypayload); + DBG_OUTPUT_PORT.printf("rgb.red: [%i] rgb.green: [%i] rgb.blue: [%i]\n", 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] (%s)!\n", led, ledstates[led].red, ledstates[led].green, ledstates[led].blue, mypayload); strip.setPixelColor(led, ledstates[led].red, ledstates[led].green, ledstates[led].blue); From 066c8a47cbb3354d0ed35f1fda49dcd4d2be70b8 Mon Sep 17 00:00:00 2001 From: Matt Johnson Date: Thu, 23 Nov 2017 01:27:35 +0000 Subject: [PATCH 4/4] remove unnecessary lines --- Arduino/McLighting/request_handlers.h | 3 --- 1 file changed, 3 deletions(-) diff --git a/Arduino/McLighting/request_handlers.h b/Arduino/McLighting/request_handlers.h index 7a07337..ef72cd2 100644 --- a/Arduino/McLighting/request_handlers.h +++ b/Arduino/McLighting/request_handlers.h @@ -81,9 +81,6 @@ void handleSetSingleLED(uint8_t * mypayload, uint8_t firstChar = 0) { strncpy (redhex, (const char *) &mypayload[2], 2 ); strncpy (greenhex, (const char *) &mypayload[4], 2 ); strncpy (bluehex, (const char *) &mypayload[6], 2 ); - ledstates[led].red = 0; - ledstates[led].green = 0; - ledstates[led].blue = 0; ledstates[led].red = strtol(redhex, NULL, 16); ledstates[led].green = strtol(greenhex, NULL, 16); ledstates[led].blue = strtol(bluehex, NULL, 16);