]> git.donarmstrong.com Git - qmk_firmware.git/blobdiff - quantum/rgblight.c
Merge pull request #662 from toneman77/iso_satan
[qmk_firmware.git] / quantum / rgblight.c
index 1b3c576d1835b7a4f8d64dfa9aaef0f580b8f2aa..f82e3ec5589a268a8ca4f410b990346c9f1e10a3 100644 (file)
@@ -55,57 +55,56 @@ uint8_t rgblight_inited = 0;
 
 
 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) {
@@ -346,7 +345,6 @@ void rgblight_set(void) {
   }
 }
 
-
 #if !defined(AUDIO_ENABLE) && defined(RGBLIGHT_TIMER)
 
 // Animation timer -- AVR Timer3
@@ -453,9 +451,9 @@ void rgblight_effect_snake(uint8_t interval) {
   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;
@@ -466,7 +464,7 @@ void rgblight_effect_snake(uint8_t interval) {
     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;
       }
@@ -476,7 +474,7 @@ void rgblight_effect_snake(uint8_t interval) {
     }
   }
   rgblight_set();
-  if (increament == 1) {
+  if (increment == 1) {
     if (pos - 1 < 0) {
       pos = RGBLED_NUM - 1;
     } else {
@@ -492,7 +490,7 @@ void rgblight_effect_knight(uint8_t interval) {
   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;
   }
@@ -502,7 +500,7 @@ void rgblight_effect_knight(uint8_t interval) {
     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;
       }
@@ -523,17 +521,17 @@ void rgblight_effect_knight(uint8_t interval) {
     }
   }
   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;
     }