From 37605d12d76bc62ef2a54dc3905f1b885684129b Mon Sep 17 00:00:00 2001 From: Gergely Nagy Date: Sun, 28 Oct 2018 09:22:45 +0100 Subject: [PATCH 1/2] hardware::Model01: Handle LED index underflow Initially, we were using `uint8_t` as the type for led indexes, which could not go below zero, so we only needed one half of a bounds check. Since we switched to a signed int, we need to check the other half of the boundaries: if the index is below zero. Signed-off-by: Gergely Nagy --- src/kaleidoscope/hardware/Model01.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/kaleidoscope/hardware/Model01.cpp b/src/kaleidoscope/hardware/Model01.cpp index 539f6115..8fd342ff 100644 --- a/src/kaleidoscope/hardware/Model01.cpp +++ b/src/kaleidoscope/hardware/Model01.cpp @@ -86,6 +86,9 @@ void Model01::setup(void) { void Model01::setCrgbAt(int8_t i, cRGB crgb) { + if (i < 0) { + return; + } if (i < 32) { cRGB oldColor = getCrgbAt(i); isLEDChanged |= !(oldColor.r == crgb.r && oldColor.g == crgb.g && oldColor.b == crgb.b); @@ -112,12 +115,13 @@ int8_t Model01::getLedIndex(byte row, byte col) { } cRGB Model01::getCrgbAt(int8_t i) { + if (i < 0 || i > 64) + return {0, 0, 0}; + if (i < 32) { return leftHand.ledData.leds[i]; - } else if (i < 64) { - return rightHand.ledData.leds[i - 32] ; } else { - return {0, 0, 0}; + return rightHand.ledData.leds[i - 32] ; } } From ef2c6a3e95439e97512d55a8888444aa41696b70 Mon Sep 17 00:00:00 2001 From: Gergely Nagy Date: Sun, 28 Oct 2018 09:25:13 +0100 Subject: [PATCH 2/2] Chase: Properly flip the direction when pos goes below zero Signed-off-by: Gergely Nagy --- src/kaleidoscope/plugin/LEDEffect-Chase.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/kaleidoscope/plugin/LEDEffect-Chase.cpp b/src/kaleidoscope/plugin/LEDEffect-Chase.cpp index 0234a544..7a1088ce 100644 --- a/src/kaleidoscope/plugin/LEDEffect-Chase.cpp +++ b/src/kaleidoscope/plugin/LEDEffect-Chase.cpp @@ -48,7 +48,7 @@ void LEDChaseEffect::update(void) { // will be out of bounds. The simplest way to do this is to assign it a value that is // known to be invalid (LED_COUNT). pos += chase_sign; - if (pos < LED_COUNT) { + if (pos < LED_COUNT && pos > 0) { pos2 += chase_sign; } else { chase_sign = -chase_sign;