From d667d159c25b897b79a0174ce85974b526c59a29 Mon Sep 17 00:00:00 2001 From: Jesse Vincent Date: Thu, 28 Jan 2016 17:55:50 -0800 Subject: [PATCH] Turns out that HSV adaptation table is actually pretty important with the WS2812 LEDs --- KeyboardConfig.h | 1 + led_control.cpp | 50 ++++++++++++++++++++++++------------------------ led_control.h | 2 +- 3 files changed, 27 insertions(+), 26 deletions(-) diff --git a/KeyboardConfig.h b/KeyboardConfig.h index 9bc128da..3a9533ae 100644 --- a/KeyboardConfig.h +++ b/KeyboardConfig.h @@ -4,6 +4,7 @@ #include "WS2812.h" #include "KeyboardioSX1509.h" +#define USE_HSV_CURVE 1 #define EEPROM_KEYMAP_LOCATION 0 diff --git a/led_control.cpp b/led_control.cpp index f2baf153..ba347841 100644 --- a/led_control.cpp +++ b/led_control.cpp @@ -122,7 +122,7 @@ void LEDControl::led_compute_breath() { } - SetHSV(led_breathe,200, 255, breathe_brightness); + led_breathe.SetHSV(200, 255, breathe_brightness); } void LEDControl::effect_breathe_update() { @@ -154,7 +154,7 @@ void LEDControl::effect_rainbow_update() { } else { rainbow_current_ticks = 0; } - SetHSV(rainbow,rainbow_hue, rainbow_saturation, rainbow_value); + rainbow.SetHSV(rainbow_hue, rainbow_saturation, rainbow_value); rainbow_hue += rainbow_steps; if (rainbow_hue >= 360) { rainbow_hue %= 360; @@ -175,7 +175,7 @@ void LEDControl::effect_rainbow_wave_update() { if (key_hue >= 360) { key_hue %= 360; } - SetHSV(rainbow,key_hue, rainbow_saturation, rainbow_value); + rainbow.SetHSV(key_hue, rainbow_saturation, rainbow_value); implementation_led_set_crgb_at(i,rainbow); } rainbow_hue += rainbow_wave_steps; @@ -221,54 +221,54 @@ void LEDControl::type_letter(uint8_t letter) { * getRGB() function based on * dim_curve idea by Jims * */ -void LEDControl::SetHSV(cRGB crgb, int hue, byte sat, byte val) { +void LEDControl::SetHSV(cRGB *crgb, int hue, byte sat, byte val) { /* convert hue, saturation and brightness ( HSB/HSV ) to RGB */ int base; if (sat == 0) { // Acromatic color (gray). Hue doesn't mind. - crgb.r = val; - crgb.g = val; - crgb.b = val; + crgb->r = val; + crgb->g = val; + crgb->b = val; } else { base = ((255 - sat) * val) >> 8; switch (hue / 60) { case 0: - crgb.r = val; - crgb.g = (((val - base)*hue) / 60) + base; - crgb.b = base; + crgb->r = val; + crgb->g = (((val - base)*hue) / 60) + base; + crgb->b = base; break; case 1: - crgb.r = (((val - base)*(60 - (hue % 60))) / 60) + base; - crgb.g = val; - crgb.b = base; + crgb->r = (((val - base)*(60 - (hue % 60))) / 60) + base; + crgb->g = val; + crgb->b = base; break; case 2: - crgb.r = base; - crgb.g = val; - crgb.b = (((val - base)*(hue % 60)) / 60) + base; + crgb->r = base; + crgb->g = val; + crgb->b = (((val - base)*(hue % 60)) / 60) + base; break; case 3: - crgb.r = base; - crgb.g = (((val - base)*(60 - (hue % 60))) / 60) + base; - crgb.b = val; + crgb->r = base; + crgb->g = (((val - base)*(60 - (hue % 60))) / 60) + base; + crgb->b = val; break; case 4: - crgb.r = (((val - base)*(hue % 60)) / 60) + base; - crgb.g = base; - crgb.b = val; + crgb->r = (((val - base)*(hue % 60)) / 60) + base; + crgb->g = base; + crgb->b = val; break; case 5: - crgb.r = val; - crgb.g = base; - crgb.b = (((val - base)*(60 - (hue % 60))) / 60) + base; + crgb->r = val; + crgb->g = base; + crgb->b = (((val - base)*(60 - (hue % 60))) / 60) + base; break; } } diff --git a/led_control.h b/led_control.h index 63b68626..16592c6b 100644 --- a/led_control.h +++ b/led_control.h @@ -74,7 +74,7 @@ class LEDControl { void effect_heatmap_update(); void effect_numlock_update(); void set_all_leds_to(cRGB color); - void SetHSV(cRGB crgb, int hue, byte sat, byte val); + void SetHSV(cRGB *crgb, int hue, byte sat, byte val); void initialize_led_mode(uint8_t mode); };