void sethsv(uint16_t hue, uint8_t sat, uint8_t val, struct cRGB *led1) {
- /* Convert hue, saturation and brightness ( HSB/HSV ) to RGB. The DIM_CURVE is
- used only on brightness/value and on saturation (inverted). This looks the
- most natural. */
- uint8_t r = 0, g = 0, b = 0;
+ // Convert hue, saturation, and value (HSV/HSB) to RGB. DIM_CURVE is used only
+ // on value and saturation (inverted). This looks the most natural.
+ uint8_t r = 0, g = 0, b = 0, base, color;
val = pgm_read_byte(&DIM_CURVE[val]);
sat = 255 - pgm_read_byte(&DIM_CURVE[255 - sat]);
- uint8_t base;
-
if (sat == 0) { // Acromatic color (gray). Hue doesn't mind.
r = val;
g = val;
b = val;
} else {
base = ((255 - sat) * val) >> 8;
+ color = (val - base) * (hue % 60) / 60;
switch (hue / 60) {
case 0:
r = val;
- g = (((val - base) * hue) / 60) + base;
+ g = base + color;
b = base;
break;
case 1:
- r = (((val - base) * (60 - (hue % 60))) / 60) + base;
+ r = val - color;
g = val;
b = base;
break;
case 2:
r = base;
g = val;
- b = (((val - base) * (hue % 60)) / 60) + base;
+ b = base + color;
break;
case 3:
r = base;
- g = (((val - base) * (60 - (hue % 60))) / 60) + base;
+ g = val - color;
b = val;
break;
case 4:
- r = (((val - base) * (hue % 60)) / 60) + base;
+ r = base + color;
g = base;
b = val;
break;
case 5:
r = val;
g = base;
- b = (((val - base) * (60 - (hue % 60))) / 60) + base;
+ b = val - color;
break;
}
}
- setrgb(r,g,b, led1);
+
+ setrgb(r, g, b, led1);
}
void setrgb(uint8_t r, uint8_t g, uint8_t b, struct cRGB *led1) {
}
}
-
#if !defined(AUDIO_ENABLE) && defined(RGBLIGHT_TIMER)
// Animation timer -- AVR Timer3
static uint16_t last_timer = 0;
uint8_t i, j;
int8_t k;
- int8_t increament = 1;
+ int8_t increment = 1;
if (interval % 2) {
- increament = -1;
+ increment = -1;
}
if (timer_elapsed(last_timer) < pgm_read_byte(&RGBLED_SNAKE_INTERVALS[interval / 2])) {
return;
led[i].g = 0;
led[i].b = 0;
for (j = 0; j < RGBLIGHT_EFFECT_SNAKE_LENGTH; j++) {
- k = pos + j * increament;
+ k = pos + j * increment;
if (k < 0) {
k = k + RGBLED_NUM;
}
}
}
rgblight_set();
- if (increament == 1) {
+ if (increment == 1) {
if (pos - 1 < 0) {
pos = RGBLED_NUM - 1;
} else {
uint8_t i, j, cur;
int8_t k;
struct cRGB preled[RGBLED_NUM];
- static int8_t increament = -1;
+ static int8_t increment = -1;
if (timer_elapsed(last_timer) < pgm_read_byte(&RGBLED_KNIGHT_INTERVALS[interval])) {
return;
}
preled[i].g = 0;
preled[i].b = 0;
for (j = 0; j < RGBLIGHT_EFFECT_KNIGHT_LENGTH; j++) {
- k = pos + j * increament;
+ k = pos + j * increment;
if (k < 0) {
k = 0;
}
}
}
rgblight_set();
- if (increament == 1) {
+ if (increment == 1) {
if (pos - 1 < 0 - RGBLIGHT_EFFECT_KNIGHT_LENGTH) {
pos = 0 - RGBLIGHT_EFFECT_KNIGHT_LENGTH;
- increament = -1;
+ increment = -1;
} else {
pos -= 1;
}
} else {
if (pos + 1 > RGBLED_NUM + RGBLIGHT_EFFECT_KNIGHT_LENGTH) {
pos = RGBLED_NUM + RGBLIGHT_EFFECT_KNIGHT_LENGTH - 1;
- increament = 1;
+ increment = 1;
} else {
pos += 1;
}