Turns out that HSV adaptation table is actually pretty important with the WS2812 LEDs

pull/18/head
Jesse Vincent 9 years ago
parent 5545283db1
commit d667d159c2

@ -4,6 +4,7 @@
#include "WS2812.h"
#include "KeyboardioSX1509.h"
#define USE_HSV_CURVE 1
#define EEPROM_KEYMAP_LOCATION 0

@ -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 <http://www.codeproject.com/miscctrl/CPicker.asp>
* 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;
}
}

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

Loading…
Cancel
Save