From 5b17de606f4dd3f11b2b04130bfcd2cd260bbe42 Mon Sep 17 00:00:00 2001 From: Gergely Nagy Date: Fri, 18 Oct 2019 15:48:44 +0200 Subject: [PATCH] LEDEffect-Rainbow: Support more than 128 LEDs properly We want to keep `key_hue` below 255, without clipping it there, otherwise the effect will come out glitchy. To achieve that, we simply substract 255 until we're above the cap. This results in the rainbow being laid out in a kind of wave. Previously, we didn't do this in a loop, which only worked when the device had less than 128 LEDs. For devices with more, we need to do this in a loop, until we get below the cap. Based on #664 by @mattvenn. Signed-off-by: Gergely Nagy --- src/kaleidoscope/plugin/LEDEffect-Rainbow.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/kaleidoscope/plugin/LEDEffect-Rainbow.cpp b/src/kaleidoscope/plugin/LEDEffect-Rainbow.cpp index 598bf8fb..8ccd4dc6 100644 --- a/src/kaleidoscope/plugin/LEDEffect-Rainbow.cpp +++ b/src/kaleidoscope/plugin/LEDEffect-Rainbow.cpp @@ -63,9 +63,14 @@ void LEDRainbowWaveEffect::TransientLEDMode::update(void) { for (auto key_addr : KeyAddr::all()) { uint16_t key_hue = rainbow_hue + 16 * (key_addr.toInt() / 4); - if (key_hue >= 255) { + // We want key_hue to be capped at 255, but we do not want to clip it to + // that, because that does not result in a nice animation. Instead, when it + // is higher than 255, we simply substract 255, and repeat that until we're + // within cap. This lays out the rainbow in a kind of wave. + while (key_hue >= 255) { key_hue -= 255; } + cRGB rainbow = hsvToRgb(key_hue, rainbow_saturation, parent_->rainbow_value); ::LEDControl.setCrgbAt(key_addr.toInt(), rainbow); }