From 5aba53b75e9376698b1d05938f2d537d842f78d0 Mon Sep 17 00:00:00 2001 From: Brian Cully Date: Mon, 13 Aug 2018 22:10:51 -0400 Subject: [PATCH] Smooth out hue transitions. In spite of the API taking uint16_t for the HSV parameters for hsv() (which appears to be in order to retain compatibility with existing plugins), the expected values are actually in the 0 ... 255 range. Update calls to make sure values passed are within that range. This did mean flattening out the value portion from 128 ... 255 to a flat 255, which isn't ideal, but I didn't have a better idea off the top of my head. The effect of this change is that there are no longer oddly flashing colors while cycling through the ripple effect. In addition I've added a starting_hue constant (set to a shade of purple I like, but easily changed), and a compile time #ifdef that controls whether or not to cycle hues, called CONSTANT_HUE. Personally, I prefer the CONSTANT_HUE effect, which is less blingy, but IMHO shows the ripple effect better. This should probably be turned into a run time switch. --- src/Kaleidoscope/LED-Wavepool.cpp | 17 ++++++++++++----- src/Kaleidoscope/LED-Wavepool.h | 3 +++ 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/Kaleidoscope/LED-Wavepool.cpp b/src/Kaleidoscope/LED-Wavepool.cpp index 24d90d3..73c8cc7 100644 --- a/src/Kaleidoscope/LED-Wavepool.cpp +++ b/src/Kaleidoscope/LED-Wavepool.cpp @@ -21,9 +21,10 @@ namespace kaleidoscope { -#define INTERPOLATE // smoother, slower animation +#define INTERPOLATE // smoother, slower animation #define MS_PER_FRAME 40 // 40 = 25 fps #define FRAMES_PER_DROP 120 // max time between raindrops during idle animation +#undef CONSTANT_HUE int8_t WavepoolEffect::surface[2][WP_WID*WP_HGT]; uint8_t WavepoolEffect::page = 0; @@ -90,8 +91,10 @@ void WavepoolEffect::update(void) { // rotate the colors over time // (side note: it's weird that this is a 16-bit int instead of 8-bit, // but that's what the library function wants) - static uint8_t current_hue = 0; + static uint16_t current_hue = starting_hue; + #ifndef CONSTANT_HUE current_hue ++; + #endif frames_since_event ++; @@ -197,14 +200,18 @@ void WavepoolEffect::update(void) { #endif uint8_t intensity = abs(height) * 2; + uint8_t saturation = 0xff - intensity; + uint8_t value = (intensity >= 128) ? 255 : intensity << 1; // color starts white but gets dimmer and more saturated as it fades, // with hue wobbling according to height map + #ifdef CONSTANT_HUE + int16_t hue = current_hue; + #else int16_t hue = (current_hue + height + (height>>1)) & 0xff; + #endif - cRGB color = hsvToRgb(hue, - 0xff - intensity, - ((uint16_t)intensity)*2); + cRGB color = hsvToRgb(hue, saturation, value); ::LEDControl.setCrgbAt(r, c, color); } diff --git a/src/Kaleidoscope/LED-Wavepool.h b/src/Kaleidoscope/LED-Wavepool.h index a803cdd..b289573 100644 --- a/src/Kaleidoscope/LED-Wavepool.h +++ b/src/Kaleidoscope/LED-Wavepool.h @@ -31,6 +31,9 @@ class WavepoolEffect : public LEDMode { // ms before idle animation starts after last keypress static uint16_t idle_timeout; + // initial hue at keyboard boot, or all the time if CONSTANT_HUE is + // defined. + const uint8_t starting_hue = 192; protected: void setup(void) final;