Browse Source

Small improvemens in Clock module.

Vladimir N. Shilov 2 years ago
parent
commit
4f342618e7
4 changed files with 87 additions and 45 deletions
  1. 1 1
      Inc/clock.h
  2. 1 1
      Inc/utils.h
  3. 83 41
      Src/clock.c
  4. 2 2
      Src/utils.c

+ 1 - 1
Inc/clock.h

@@ -57,7 +57,7 @@ typedef enum {
 #define BTN_TIME_REPEATED   50
 #define BTN_TIME_REPEATED   50
 
 
 /* Display timeout, sec */
 /* Display timeout, sec */
-#define DISP_WDT_TIME   10
+#define DISP_WDT_TIME   15
 
 
 /* variables */
 /* variables */
 extern rtc_t Clock;
 extern rtc_t Clock;

+ 1 - 1
Inc/utils.h

@@ -21,7 +21,7 @@ typedef enum {
 
 
 /* Defines */
 /* Defines */
 #define FLASH_PAGE_START  0x0800F800
 #define FLASH_PAGE_START  0x0800F800
-#define FLASH_PAGE_END    0x0800FFFF
+#define FLASH_PAGE_END    0x0800FFF8
 #define FLASH_PAGE_NMB    31
 #define FLASH_PAGE_NMB    31
 #define FLASH_PAGE_NUM    1
 #define FLASH_PAGE_NUM    1
 
 

+ 83 - 41
Src/clock.c

@@ -25,7 +25,9 @@ const uint8_t cie[MAX_BRIGHT_LVL + 1] = {
 };
 };
 volatile static uint8_t dispWDT = 0;
 volatile static uint8_t dispWDT = 0;
 static in15_pin_t symToFade = 0;
 static in15_pin_t symToFade = 0;
-static uint8_t BrightLevel;
+static uint8_t LightingBright;
+static light_mode_t LightingMode;
+static uint8_t LightingColour;
 static flash_data_t Lighting, setLighting;
 static flash_data_t Lighting, setLighting;
 
 
 /* function prototypes */
 /* function prototypes */
@@ -42,6 +44,7 @@ static void valIncrease(uint8_t * val, const uint8_t max);
 static void valDecrease(uint8_t * val, const uint8_t max);
 static void valDecrease(uint8_t * val, const uint8_t max);
 static void dvalIncrease(uint8_t * val, const uint8_t max);
 static void dvalIncrease(uint8_t * val, const uint8_t max);
 static void dvalDecrease(uint8_t * val, const uint8_t max);
 static void dvalDecrease(uint8_t * val, const uint8_t max);
+static void showRainbow(void);
 
 
 /* funcions */
 /* funcions */
 void Clock_Init(void) {
 void Clock_Init(void) {
@@ -49,7 +52,7 @@ void Clock_Init(void) {
   showTime();
   showTime();
 
 
   flash_result_t flash_res = Flash_Read(&Lighting.u64);
   flash_result_t flash_res = Flash_Read(&Lighting.u64);
-  if ( flash_res != Flash_Ok) {
+  if ((flash_res != Flash_Ok) || (Lighting.name.DayHour == 0xff)) {
     Lighting.name.DayHour = MORNING_HOUR;
     Lighting.name.DayHour = MORNING_HOUR;
     Lighting.name.NightHour = EVENING_HOUR;
     Lighting.name.NightHour = EVENING_HOUR;
     Lighting.name.DayBright = DAY_BR_LVL;
     Lighting.name.DayBright = DAY_BR_LVL;
@@ -57,14 +60,6 @@ void Clock_Init(void) {
     Lighting.name.DayMode = light_Rainbow;
     Lighting.name.DayMode = light_Rainbow;
     Lighting.name.NightMode = light_Colour;
     Lighting.name.NightMode = light_Colour;
     Lighting.name.NightColour = COLOUR_NIXIE;
     Lighting.name.NightColour = COLOUR_NIXIE;
-  } else {
-    if (Lighting.name.DayHour == 0xff) {
-      /* launch set parameters
-      ES_SetState(stSetDayHour);
-      setDNbegin();
-      setDayHourBegin();
-      white (ES_GetState() != ???); */
-    }
   }
   }
 
 
   check_DayNight();
   check_DayNight();
@@ -73,14 +68,18 @@ void Clock_Init(void) {
 static void check_DayNight(void) {
 static void check_DayNight(void) {
   if ((Clock.Hr >= Lighting.name.DayHour) && (Clock.Hr < Lighting.name.NightHour)) {
   if ((Clock.Hr >= Lighting.name.DayHour) && (Clock.Hr < Lighting.name.NightHour)) {
     Flag.Now_Day = 1;
     Flag.Now_Day = 1;
-    BrightLevel = cie[Lighting.name.DayBright];
+    LightingBright = cie[Lighting.name.DayBright];
+    LightingMode = Lighting.name.DayMode;
+    LightingColour = Lighting.name.DayColour;
   } else {
   } else {
     Flag.Now_Day = 0;
     Flag.Now_Day = 0;
-    BrightLevel = cie[Lighting.name.NightBright];
+    LightingBright = cie[Lighting.name.NightBright];
+    LightingMode = Lighting.name.NightMode;
+    LightingColour = Lighting.name.NightColour;
   }
   }
 
 
-  tube_BrightLevel(Tube_All, BrightLevel);
-  //TUBES_BRIGHT(BrightLevel);
+  tube_BrightLevel(Tube_All, LightingBright);
+  TUBES_BRIGHT(LightingBright);
 }
 }
 
 
 /**
 /**
@@ -381,11 +380,19 @@ void showTime(void) {
   MinusFadeIn();
   MinusFadeIn();
   RTOS_SetTask(MinusFadeOut, 500, 0);
   RTOS_SetTask(MinusFadeOut, 500, 0);
 
 
-  if (Flag.Now_Day != 0) {
+  switch (LightingMode) {
+  case light_Rainbow:
     uint8_t hue = bcd2bin(Clock.Sec);
     uint8_t hue = bcd2bin(Clock.Sec);
-    HSV2LED(hue, BrightLevel);
-  } else {
-    HSV2LED(COLOUR_NIXIE, BrightLevel);
+    HSV2LED(hue, LightingBright);
+    break;
+
+  case light_Colour:
+    HSV2LED(LightingColour, LightingBright);
+    break;
+  
+  default:
+    LEDS_OFF;
+    break;
   }
   }
 
 
   tube4_t buf;
   tube4_t buf;
@@ -401,7 +408,7 @@ void showMMSS(void) {
   IN15_Minus;
   IN15_Minus;
 
 
   uint8_t hue = bcd2bin(Clock.Sec);
   uint8_t hue = bcd2bin(Clock.Sec);
-  HSV2LED(hue, BrightLevel);
+  HSV2LED(hue, LightingBright);
 
 
   tube4_t buf;
   tube4_t buf;
   buf.s8.tA = Clock.Min >> 4;
   buf.s8.tA = Clock.Min >> 4;
@@ -448,8 +455,8 @@ void showYear(void) {
 }
 }
 
 
 void showHumidity(void) {
 void showHumidity(void) {
-  dispWDT = DISP_WDT_TIME;
-  HSV2LED(COLOUR_BLUE, BrightLevel);
+  dispWDT = DISP_WDT_TIME/2;
+  HSV2LED(COLOUR_BLUE, LightingBright);
   symToFade = sym_Percent;
   symToFade = sym_Percent;
   IN15_FadeIn();
   IN15_FadeIn();
 
 
@@ -462,8 +469,8 @@ void showHumidity(void) {
 }
 }
 
 
 void showTemperature(void) {
 void showTemperature(void) {
-  dispWDT = DISP_WDT_TIME;
-  HSV2LED(COLOUR_RED, BrightLevel);
+  dispWDT = DISP_WDT_TIME/2;
+  HSV2LED(COLOUR_RED, LightingBright);
   RTOS_DeleteTask(MinusFadeIn);
   RTOS_DeleteTask(MinusFadeIn);
   RTOS_DeleteTask(MinusFadeOut);
   RTOS_DeleteTask(MinusFadeOut);
   symToFade = sym_Plus;
   symToFade = sym_Plus;
@@ -478,8 +485,8 @@ void showTemperature(void) {
 }
 }
 
 
 void showPressure(void) {
 void showPressure(void) {
-  dispWDT = DISP_WDT_TIME;
-  HSV2LED(COLOUR_GREEN, BrightLevel);
+  dispWDT = DISP_WDT_TIME/2;
+  HSV2LED(COLOUR_GREEN, LightingBright);
   symToFade = sym_Pressure;
   symToFade = sym_Pressure;
   IN15_FadeIn();
   IN15_FadeIn();
 
 
@@ -524,7 +531,7 @@ void setTimeShow(void) {
 void setTimeBegin(void) {
 void setTimeBegin(void) {
 	RTOS_DeleteTask(MinusFadeOut);
 	RTOS_DeleteTask(MinusFadeOut);
   in15Minus();
   in15Minus();
-  HSV2LED(COLOUR_NIXIE, BrightLevel);
+  HSV2LED(COLOUR_NIXIE, LightingBright);
   RTOS_SetTask(btnProcess, BTN_TIME_HOLDED, BTN_SCAN_PERIOD);
   RTOS_SetTask(btnProcess, BTN_TIME_HOLDED, BTN_SCAN_PERIOD);
   RTC_ReadAll(&setClock);
   RTC_ReadAll(&setClock);
 }
 }
@@ -577,7 +584,7 @@ void setTimeEnd(void) {
 
 
 void setDateBegin(void) {
 void setDateBegin(void) {
   IN15_OFF;
   IN15_OFF;
-  HSV2LED(COLOUR_NIXIE, BrightLevel);
+  HSV2LED(COLOUR_NIXIE, LightingBright);
   RTOS_SetTask(btnProcess, BTN_TIME_HOLDED, BTN_SCAN_PERIOD);
   RTOS_SetTask(btnProcess, BTN_TIME_HOLDED, BTN_SCAN_PERIOD);
   RTC_ReadAll(&setClock);
   RTC_ReadAll(&setClock);
 }
 }
@@ -737,20 +744,22 @@ void showDNbright(void) {
 void showDNmode(void) {
 void showDNmode(void) {
 	dispWDT = DISP_WDT_TIME;
 	dispWDT = DISP_WDT_TIME;
 
 
+  uint8_t dm, nm; 
   tube4_t buf;
   tube4_t buf;
   es_state_t e_st = ES_GetState();
   es_state_t e_st = ES_GetState();
 
 
   if (e_st == stShowDNmode){
   if (e_st == stShowDNmode){
-    buf.s8.tA = Lighting.name.DayMode / 10;
-    buf.s8.tB = Lighting.name.DayMode % 10;
-    buf.s8.tD = Lighting.name.NightMode / 10;
-    buf.s8.tE = Lighting.name.NightMode % 10;
+    dm = Lighting.name.DayMode;
+    nm = Lighting.name.NightMode;
   } else {
   } else {
-    buf.s8.tA = setLighting.name.DayMode / 10;
-    buf.s8.tB = setLighting.name.DayMode % 10;
-    buf.s8.tD = setLighting.name.NightMode / 10;
-    buf.s8.tE = setLighting.name.NightMode % 10;
+    dm = setLighting.name.DayMode;
+    nm = setLighting.name.NightMode;
   }
   }
+
+  buf.s8.tA = 0xf;
+  buf.s8.tB = dm & 0xf;
+  buf.s8.tD = 0xf;
+  buf.s8.tE = nm & 0xf;
   showDigits(buf);
   showDigits(buf);
 }
 }
 
 
@@ -852,7 +861,7 @@ void setDayColourBegin(void) {
   Flag.Blink_4 = 0;
   Flag.Blink_4 = 0;
   Flag.Blink_5 = 0;
   Flag.Blink_5 = 0;
   Blink_Start();
   Blink_Start();
-  HSV2LED(setLighting.name.DayColour, BrightLevel);
+  HSV2LED(setLighting.name.DayColour, LightingBright);
   showDNcolour();
   showDNcolour();
 }
 }
 
 
@@ -862,7 +871,7 @@ void setNightColourBegin(void) {
   Flag.Blink_4 = 1;
   Flag.Blink_4 = 1;
   Flag.Blink_5 = 1;
   Flag.Blink_5 = 1;
   Blink_Start();
   Blink_Start();
-  HSV2LED(setLighting.name.NightColour, BrightLevel);
+  HSV2LED(setLighting.name.NightColour, LightingBright);
   showDNcolour();
   showDNcolour();
 }
 }
 
 
@@ -877,11 +886,16 @@ void setIncDayBright(void) {
 
 
 void setIncDayMode(void) {
 void setIncDayMode(void) {
   dvalIncrease(&setLighting.name.DayMode, MAX_LIGHT_MODE);
   dvalIncrease(&setLighting.name.DayMode, MAX_LIGHT_MODE);
+  if (setLighting.name.DayMode == light_Rainbow) {
+    RTOS_SetTask(showRainbow, 0, 20);
+  } else {
+    RTOS_DeleteTask(showRainbow);
+  }
 }
 }
 
 
 void setIncDayColour(void) {
 void setIncDayColour(void) {
   dvalIncrease(&setLighting.name.DayColour, MAX_COLOR_VAL);
   dvalIncrease(&setLighting.name.DayColour, MAX_COLOR_VAL);
-  HSV2LED(setLighting.name.DayColour, BrightLevel);
+  HSV2LED(setLighting.name.DayColour, LightingBright);
 }
 }
 
 
 void setDecDayHour(void) {
 void setDecDayHour(void) {
@@ -895,11 +909,16 @@ void setDecDayBright(void) {
 
 
 void setDecDayMode(void) {
 void setDecDayMode(void) {
   dvalDecrease(&setLighting.name.DayMode, MAX_LIGHT_MODE);
   dvalDecrease(&setLighting.name.DayMode, MAX_LIGHT_MODE);
+  if (setLighting.name.DayMode == light_Rainbow) {
+    RTOS_SetTask(showRainbow, 0, 20);
+  } else {
+    RTOS_DeleteTask(showRainbow);
+  }
 }
 }
 
 
 void setDecDayColour(void) {
 void setDecDayColour(void) {
   dvalDecrease(&setLighting.name.DayColour, MAX_COLOR_VAL);
   dvalDecrease(&setLighting.name.DayColour, MAX_COLOR_VAL);
-  HSV2LED(setLighting.name.DayColour, BrightLevel);
+  HSV2LED(setLighting.name.DayColour, LightingBright);
 }
 }
 
 
 void setIncNightHour(void) {
 void setIncNightHour(void) {
@@ -913,11 +932,16 @@ void setIncNightBright(void) {
 
 
 void setIncNightMode(void) {
 void setIncNightMode(void) {
   dvalIncrease(&setLighting.name.NightMode, MAX_LIGHT_MODE);
   dvalIncrease(&setLighting.name.NightMode, MAX_LIGHT_MODE);
+  if (setLighting.name.NightMode == light_Rainbow) {
+    RTOS_SetTask(showRainbow, 0, 20);
+  } else {
+    RTOS_DeleteTask(showRainbow);
+  }
 }
 }
 
 
 void setIncNightColour(void) {
 void setIncNightColour(void) {
   dvalIncrease(&setLighting.name.NightColour, MAX_COLOR_VAL);
   dvalIncrease(&setLighting.name.NightColour, MAX_COLOR_VAL);
-  HSV2LED(setLighting.name.NightColour, BrightLevel);
+  HSV2LED(setLighting.name.NightColour, LightingBright);
 }
 }
 
 
 void setDecNightHour(void) {
 void setDecNightHour(void) {
@@ -931,11 +955,16 @@ void setDecNightBright(void) {
 
 
 void setDecNightMode(void) {
 void setDecNightMode(void) {
   dvalDecrease(&setLighting.name.NightMode, MAX_LIGHT_MODE);
   dvalDecrease(&setLighting.name.NightMode, MAX_LIGHT_MODE);
+  if (setLighting.name.NightMode == light_Rainbow) {
+    RTOS_SetTask(showRainbow, 0, 20);
+  } else {
+    RTOS_DeleteTask(showRainbow);
+  }
 }
 }
 
 
 void setDecNightColour(void) {
 void setDecNightColour(void) {
   dvalDecrease(&setLighting.name.NightColour, MAX_COLOR_VAL);
   dvalDecrease(&setLighting.name.NightColour, MAX_COLOR_VAL);
-  HSV2LED(setLighting.name.NightColour, BrightLevel);
+  HSV2LED(setLighting.name.NightColour, LightingBright);
 }
 }
 
 
 void setDNbreak(void) {
 void setDNbreak(void) {
@@ -994,3 +1023,16 @@ static void dvalDecrease(uint8_t * val, uint8_t max) {
     *val = max;
     *val = max;
   }
   }
 }
 }
+
+static void showRainbow(void) {
+  static uint8_t hue = 0;
+
+  HSV2LED(hue, LightingBright);
+
+  if (hue < 59) {
+    hue ++;
+  } else {
+    hue = 0;
+    RTOS_DeleteTask(showRainbow);
+  }
+}

+ 2 - 2
Src/utils.c

@@ -13,7 +13,7 @@ flash_result_t Flash_Write(uint64_t * data) {
   val.u64 = *data;
   val.u64 = *data;
 
 
   // search first free cell
   // search first free cell
-  while ((address < FLASH_PAGE_END) || ((*(__IO uint32_t*)address) != 0xffffffff)) {
+  while ((address < FLASH_PAGE_END) && ((*(__IO uint32_t*)address) != 0xffffffff)) {
     address += 8;
     address += 8;
   }
   }
 
 
@@ -74,7 +74,7 @@ flash_result_t Flash_Read(uint64_t * data) {
   flash_result_t res = Flash_Ok;
   flash_result_t res = Flash_Ok;
   uint32_t address = FLASH_PAGE_START;
   uint32_t address = FLASH_PAGE_START;
 
 
-  while ((address < FLASH_PAGE_END) || ((*(__IO uint32_t*)address) != 0xffffffff)) {
+  while ((address < FLASH_PAGE_END) && ((*(__IO uint32_t*)address) != 0xffffffff)) {
     val.u32[0] = (*(__IO uint32_t*)address);
     val.u32[0] = (*(__IO uint32_t*)address);
     address += 4;
     address += 4;
     val.u32[1] = (*(__IO uint32_t*)address);
     val.u32[1] = (*(__IO uint32_t*)address);