Browse Source

Test HSV2LED for 0..59 HUE value.

Vladimir N. Shilov 3 years ago
parent
commit
a147253c44
4 changed files with 12 additions and 13 deletions
  1. 1 1
      MDK-ARM/MNC-IN12x5.uvprojx
  2. 9 9
      Src/board.c
  3. 1 1
      Src/clock.c
  4. 1 2
      Src/main.c

+ 1 - 1
MDK-ARM/MNC-IN12x5.uvprojx

@@ -58,7 +58,7 @@
           <ListingPath>.\LST\</ListingPath>
           <HexFormatSelection>1</HexFormatSelection>
           <Merge32K>0</Merge32K>
-          <CreateBatchFile>0</CreateBatchFile>
+          <CreateBatchFile>1</CreateBatchFile>
           <BeforeCompile>
             <RunUserProg1>0</RunUserProg1>
             <RunUserProg2>0</RunUserProg2>

+ 9 - 9
Src/board.c

@@ -161,10 +161,10 @@ void showDigits(uint8_t * dig)
 
 /**
  * @brief  HSV to RGB convertion
- * @param  hue: 0-359, sat: 0-255, val (lightness): 0-255
+ * @param  hue: 0-59, sat: 0-255, val (lightness): 0-255
  * @return none. RGB value out direct to LED.
  */
-void HSV2LED(const int hue, const uint8_t sat, const uint8_t val) {
+void HSV2LED(const uint8_t hue, const uint8_t sat, const uint8_t val) {
   int base;
   uint8_t r=0, g=0, b=0;
 
@@ -176,36 +176,36 @@ void HSV2LED(const int hue, const uint8_t sat, const uint8_t val) {
   } else {
 
     base = ((255 - sat) * val) >> 8;
-    switch (hue / 60) {
+    switch (hue / 10) {
     case 0:
       r = val;
-      g = (((val - base) * hue) / 60) + base;
+      g = (((val - base) * hue) / 10) + base;
       b = base;
       break;
     case 1:
-      r = (((val - base) * (60 - (hue % 60))) / 60) + base;
+      r = (((val - base) * (10 - (hue % 10))) / 10) + base;
       g = val;
       b = base;
       break;
     case 2:
       r = base;
       g = val;
-      b = (((val - base) * (hue % 60)) / 60) + base;
+      b = (((val - base) * (hue % 10)) / 10) + base;
       break;
     case 3:
       r = base;
-      g = (((val - base) * (60 - (hue % 60))) / 60) + base;
+      g = (((val - base) * (10 - (hue % 10))) / 10) + base;
       b = val;
       break;
     case 4:
-      r = (((val - base) * (hue % 60)) / 60) + base;
+      r = (((val - base) * (hue % 10)) / 10) + base;
       g = base;
       b = val;
       break;
     case 5:
       r = val;
       g = base;
-      b = (((val - base) * (60 - (hue % 60))) / 60) + base;
+      b = (((val - base) * (10 - (hue % 10))) / 10) + base;
       break;
     }
   }

+ 1 - 1
Src/clock.c

@@ -158,7 +158,7 @@ void showTime(void) {
   MinusFadeIn();
   RTOS_SetTask(MinusFadeOut, 500, 0);
 
-  int16_t hue = bcd2bin(Clock.Sec) * 6;
+  uint8_t hue = bcd2bin(Clock.Sec);// * 6;
   HSV2LED(hue, 255, 255);
 
   uint8_t buf[4];

+ 1 - 2
Src/main.c

@@ -68,14 +68,13 @@ int main(void)
 
   /* Initialize Event State Machine */
   ES_Init(stShowTime);
+  showTime();
   es_event_t event = eventNull;
 
   /** Set tasks for Sheduler */
   RTOS_SetTask(btnProcess, 1, BTN_SCAN_PERIOD);
 
   /* USER CODE BEGIN WHILE */
-  showTime();
-
   /* Infinite loop */
   while (1)
   {