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 <algernon@keyboard.io>
pull/676/head
Gergely Nagy 5 years ago
parent e50b393d5c
commit 5b17de606f
No known key found for this signature in database
GPG Key ID: AC1E90BAC433F68F

@ -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);
}

Loading…
Cancel
Save