Fix for all out of bounds LED addressing

This is a somewhat unwieldy fix for all the out of bounds (attempted) array addressing at
both ends. When `pos` goes out of bounds in either direction, the test is the same because
it's an unsigned integer. However, after the change of direction, the trailing LED will
still be out of bounds, so we check that every time we call `setCrgbAt()` for `pos2`.

It's rather ugly, but it does ensure that we don't call `setCrgbAt()` with an
out-of-bounds address.
pull/365/head
Michael Richters 7 years ago
parent 0cd6634f95
commit 1f2d32ed79

@ -6,15 +6,25 @@ void LEDChaseEffect::update(void) {
return;
}
current_chase_counter = 0;
::LEDControl.setCrgbAt(pos - (chase_sign * chase_pixels), {0, 0, 0});
byte pos2 = pos - (chase_sign * chase_pixels);
::LEDControl.setCrgbAt(pos, {0, 0, 0});
if (pos2 < LED_COUNT)
::LEDControl.setCrgbAt(pos2, {0, 0, 0});
pos += chase_sign;
if (pos >= (LED_COUNT - 1) || pos <= 0) {
if (! (pos < LED_COUNT)) {
chase_sign = -chase_sign;
pos += chase_sign;
pos2 = LED_COUNT;
} else {
pos2 += chase_sign;
}
::LEDControl.setCrgbAt(pos, {0, 0, 255});
::LEDControl.setCrgbAt(pos - (chase_sign * chase_pixels), {255, 0, 0});
if (pos2 < LED_COUNT)
::LEDControl.setCrgbAt(pos2, {255, 0, 0});
}
}

Loading…
Cancel
Save