Browse Source

Test Fast HSV2RGB.

Vladimir N. Shilov 2 years ago
parent
commit
1ea80486b6
1 changed files with 74 additions and 2 deletions
  1. 74 2
      Src/clock.c

+ 74 - 2
Src/clock.c

@@ -314,6 +314,7 @@ static void IN15_FadeOut(void) {
  * @return none. RGB value out direct to LED.
  */
 static void HSV2LED(const uint8_t hue, const uint8_t sat, const uint8_t val) {
+#ifdef TEST-TEST-TEST
   int base;
   uint32_t r=0, g=0, b=0;
 
@@ -363,6 +364,72 @@ static void HSV2LED(const uint8_t hue, const uint8_t sat, const uint8_t val) {
   COLOR_G((uint8_t)g);
   COLOR_B((uint8_t)b);
 }
+#endif
+
+  uint8_t r, g, b;
+
+  if (sat == 0) {
+    r = val;
+    g = val;
+    b = val;
+  } else {
+
+    uint8_t sextant = hue >> 8;
+    uint8_t tmp;
+
+    // Swap pointers depending which sextant we are in
+		if((sextant) & 2) {
+      tmp = r; r = b; b = tmp;
+		}
+		if((sextant) & 4) {
+      tmp = g; g = b; b = tmp;
+		}
+		if(!((sextant) & 6)) {
+			if(!((sextant) & 1)) {
+        tmp = r; r = g; g = tmp;
+			}
+		} else {
+			if((sextant) & 1) {
+        tmp = r; r = g; g = tmp;
+			}
+		}
+
+    g = val; // Top level
+
+    // Perform actual calculations
+
+    /*
+    * Bottom level: v * (1.0 - s)
+    * --> (v * (255 - s) + error_corr + 1) / 256
+    */
+    uint16_t ww;        // Intermediate result
+    ww = val * (255 - sat); // We don't use ~s to prevent size-promotion side effects
+    ww += 1;            // Error correction
+    ww += ww >> 8;      // Error correction
+    b = ww >> 8;
+
+    uint8_t h_fraction = hue & 0xff; // 0...255
+    uint32_t d;                    // Intermediate result
+
+    if (!(sextant & 1))
+    {
+      // r = ...slope_up...;
+      d = val * (uint32_t)((255 << 8) - (uint16_t)(sat * (256 - h_fraction)));
+      d += d >> 8; // Error correction
+      d += val;      // Error correction
+      r = d >> 16;
+    } else {
+      // r = ...slope_down...;
+      d = val * (uint32_t)((255 << 8) - (uint16_t)(sat * h_fraction));
+      d += d >> 8; // Error correction
+      d += val;      // Error correction
+      r = d >> 16;
+    }
+  }
+  COLOR_R(r);
+  COLOR_G(g);
+  COLOR_B(b);
+}
 
 /**
   * Show info on tubes.
@@ -371,8 +438,13 @@ void showTime(void) {
   MinusFadeIn();
   RTOS_SetTask(MinusFadeOut, 500, 0);
 
-  uint8_t hue = bcd2bin(Clock.Sec);
-  HSV2LED(hue, 255, BrightLevel);
+  if (Flag.Now_Day != 0) {
+    // new hsv2led
+    uint16_t hue = bcd2bin(Clock.Sec) * 256 / 10;
+    HSV2LED(hue, 255, BrightLevel);
+  } else {
+    HSV2LED(COLOUR_NIXIE, 255, BrightLevel);
+  }
 
   tube4_t buf;
   buf.s8.tA = Clock.Hr >> 4;