pull/18/head
Jesse Vincent 9 years ago
parent 13c3678e9b
commit b96c06338f

@ -139,10 +139,10 @@ void LEDControl_::effect_rainbow_update() {
} else {
rainbow_current_ticks = 0;
}
rainbow.SetHSV(rainbow_hue, rainbow_saturation, rainbow_value);
hsv_to_rgb( &rainbow, rainbow_hue, rainbow_saturation, rainbow_value);
rainbow_hue += rainbow_steps;
if (rainbow_hue >= 360) {
rainbow_hue %= 360;
if (rainbow_hue >= 255) {
rainbow_hue %= 255;
}
set_all_leds_to(rainbow);
led_sync();
@ -157,15 +157,15 @@ void LEDControl_::effect_rainbow_wave_update() {
for (uint8_t i = 0; i < LED_COUNT; i++) {
uint16_t key_hue = rainbow_hue +16*(i/4);
if (key_hue >= 360) {
key_hue %= 360;
if (key_hue >= 255) {
key_hue %= 255;
}
rainbow.SetHSV(key_hue, rainbow_saturation, rainbow_value);
hsv_to_rgb(&rainbow, key_hue, rainbow_saturation, rainbow_value);
led_set_crgb_at(i,rainbow);
}
rainbow_hue += rainbow_wave_steps;
if (rainbow_hue >= 360) {
rainbow_hue %= 360;
if (rainbow_hue >= 255) {
rainbow_hue %= 255;
}
led_sync();
}
@ -203,4 +203,47 @@ void LEDControl_::type_letter(uint8_t letter) {
}
// From http://web.mit.edu/storborg/Public/hsvtorgb.c - talk to Scott about licensing
void LEDControl_::hsv_to_rgb(cRGB *cRGB, uint16_t h, uint16_t s, uint16_t v) {
/* HSV to RGB conversion function with only integer
* math */
uint16_t region, fpart, p, q, t;
if(s == 0) {
/* color is grayscale */
cRGB->r = cRGB->g = cRGB->b = v;
return;
}
/* make hue 0-5 */
region = h / 43;
/* find remainder part, make it from 0-255 */
fpart = (h - (region * 43)) * 6;
/* calculate temp vars, doing integer multiplication */
p = (v * (255 - s)) >> 8;
q = (v * (255 - ((s * fpart) >> 8))) >> 8;
t = (v * (255 - ((s * (255 - fpart)) >> 8))) >> 8;
/* assign temp vars based on color cone region */
switch(region) {
case 0:
cRGB->r = v; cRGB->g = t; cRGB->b = p; break;
case 1:
cRGB->r = q; cRGB->g = v; cRGB->b = p; break;
case 2:
cRGB->r = p; cRGB->g = v; cRGB->b = t; break;
case 3:
cRGB->r = p; cRGB->g = q; cRGB->b = v; break;
case 4:
cRGB->r = t; cRGB->g = p; cRGB->b = v; break;
default:
cRGB->r = v; cRGB->g = p; cRGB->b = q; break;
}
return;
}
LEDControl_ LEDControl;

@ -30,7 +30,7 @@ class LEDControl_ {
uint8_t last_led_mode = 0;
uint8_t stored_led_mode = 0;
uint8_t pos = 0;
void hsv_to_rgb(cRGB *cRGB, uint16_t h, uint16_t s, uint16_t v);

@ -8,6 +8,7 @@
#include "../key_events.h"
#define RIGHT_COLS 8
#define RIGHT_ROWS 4
#define LEFT_COLS 8

Loading…
Cancel
Save