|
@@ -18,11 +18,14 @@ static btn_t Button[BTN_NUM] = {
|
|
|
{0, evBTN3Pressed, evBTN3Pressed, BTN3_PIN},
|
|
|
{0, evBTN4Pressed, evBTN4Holded, BTN4_PIN}
|
|
|
};
|
|
|
+//convert linear bright level to logariphmic
|
|
|
+const uint8_t cie[8] = { 0, 5, 14, 33, 64, 109, 172, 255 };
|
|
|
volatile static uint8_t dispWDT = 0;
|
|
|
static in15_pin_t symToFade = 0;
|
|
|
+static brigh_level_t BrightLevel;
|
|
|
|
|
|
/* function prototypes */
|
|
|
-//static void Color_RGB(const uint8_t r, const uint8_t g, const uint8_t b);
|
|
|
+static void check_DayNight(void);
|
|
|
static void MinusFadeIn(void);
|
|
|
static void MinusFadeOut(void);
|
|
|
static void PlusFadeIn(void);
|
|
@@ -32,17 +35,27 @@ static void IN15_FadeIn(void);
|
|
|
static void IN15_FadeOut(void);
|
|
|
static void valIncrease(uint8_t * val, uint8_t max);
|
|
|
static void valDecrease(uint8_t * val, uint8_t max);
|
|
|
+static void HSV2LED(const uint8_t hue, const uint8_t sat, const uint8_t val);
|
|
|
|
|
|
/* funcions */
|
|
|
-/**
|
|
|
- * @brief Вывод HEX значений цвета в таймер.
|
|
|
- * @param : RGB value in range 0x00-0xFF
|
|
|
- * @retval : None
|
|
|
- */
|
|
|
-static void Color_RGB(uint8_t r, uint8_t g, uint8_t b) {
|
|
|
- COLOR_R(r);
|
|
|
- COLOR_G(g);
|
|
|
- COLOR_B(b);
|
|
|
+void Clock_Init(void) {
|
|
|
+ RTC_ReadAll(&Clock);
|
|
|
+ showTime();
|
|
|
+
|
|
|
+ check_DayNight();
|
|
|
+}
|
|
|
+
|
|
|
+static void check_DayNight(void) {
|
|
|
+ if ((Clock.Hr >= MORNING_HOUR) && (Clock.Hr < EVENING_HOUR)) {
|
|
|
+ Flag.Now_Day = 1;
|
|
|
+ BrightLevel = cie[DAY_BR_LVL];
|
|
|
+ } else {
|
|
|
+ Flag.Now_Day = 0;
|
|
|
+ BrightLevel = cie[NIGHT_BR_LVL];
|
|
|
+ }
|
|
|
+
|
|
|
+ tube_BrightLevel(Tube_All, BrightLevel);
|
|
|
+ //TUBES_BRIGHT(BrightLevel);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -82,9 +95,14 @@ void btnProcess(void) {
|
|
|
}
|
|
|
|
|
|
void new_Second(void) {
|
|
|
-// Blink_Start(); // !!! TODO
|
|
|
RTC_ReadAll(&Clock);
|
|
|
|
|
|
+ // new hour
|
|
|
+ if (Clock.Min == 0 && Clock.Sec == 0) {
|
|
|
+ check_DayNight();
|
|
|
+ }
|
|
|
+
|
|
|
+ // check display watch dog timer
|
|
|
if (dispWDT != 0) {
|
|
|
dispWDT--;
|
|
|
if (dispWDT == 0) {
|
|
@@ -92,6 +110,7 @@ void new_Second(void) {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
/**
|
|
|
* On/off symbols on IN-15 tube.
|
|
|
*/
|
|
@@ -279,6 +298,62 @@ static void IN15_FadeOut(void) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+ * @brief HSV to RGB convertion
|
|
|
+ * @param hue: 0-59, sat: 0-255, val (lightness): 0-255
|
|
|
+ * @return none. RGB value out direct to LED.
|
|
|
+ */
|
|
|
+static void HSV2LED(const uint8_t hue, const uint8_t sat, const uint8_t val) {
|
|
|
+ int base;
|
|
|
+ uint32_t r=0, g=0, b=0;
|
|
|
+
|
|
|
+ if (sat == 0)
|
|
|
+ { // Achromatic color (gray).
|
|
|
+ r = val;
|
|
|
+ g = val;
|
|
|
+ b = val;
|
|
|
+ } else {
|
|
|
+
|
|
|
+ base = ((255 - sat) * val) >> 8;
|
|
|
+ switch (hue / 10) {
|
|
|
+ case 0:
|
|
|
+ r = val;
|
|
|
+ g = (((val - base) * hue) / 10) + base;
|
|
|
+ b = base;
|
|
|
+ break;
|
|
|
+ case 1:
|
|
|
+ r = (((val - base) * (10 - (hue % 10))) / 10) + base;
|
|
|
+ g = val;
|
|
|
+ b = base;
|
|
|
+ break;
|
|
|
+ case 2:
|
|
|
+ r = base;
|
|
|
+ g = val;
|
|
|
+ b = (((val - base) * (hue % 10)) / 10) + base;
|
|
|
+ break;
|
|
|
+ case 3:
|
|
|
+ r = base;
|
|
|
+ g = (((val - base) * (10 - (hue % 10))) / 10) + base;
|
|
|
+ b = val;
|
|
|
+ break;
|
|
|
+ case 4:
|
|
|
+ r = (((val - base) * (hue % 10)) / 10) + base;
|
|
|
+ g = base;
|
|
|
+ b = val;
|
|
|
+ break;
|
|
|
+ case 5:
|
|
|
+ r = val;
|
|
|
+ g = base;
|
|
|
+ b = (((val - base) * (10 - (hue % 10))) / 10) + base;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ COLOR_R((uint8_t)r);
|
|
|
+ COLOR_G((uint8_t)g);
|
|
|
+ COLOR_B((uint8_t)b);
|
|
|
+}
|
|
|
+
|
|
|
/**
|
|
|
* Show info on tubes.
|
|
|
*/
|
|
@@ -287,7 +362,7 @@ void showTime(void) {
|
|
|
RTOS_SetTask(MinusFadeOut, 500, 0);
|
|
|
|
|
|
uint8_t hue = bcd2bin(Clock.Sec);
|
|
|
- HSV2LED(hue, 255, cie[Lvl_Mdl]);
|
|
|
+ HSV2LED(hue, 255, BrightLevel);
|
|
|
|
|
|
tube4_t buf;
|
|
|
buf.s8.tA = Clock.Hr >> 4;
|
|
@@ -302,7 +377,7 @@ void showMMSS(void) {
|
|
|
IN15_Minus;
|
|
|
|
|
|
uint8_t hue = bcd2bin(Clock.Sec);
|
|
|
- HSV2LED(hue, 255, cie[Lvl_Mdl]);
|
|
|
+ HSV2LED(hue, 255, BrightLevel);
|
|
|
|
|
|
tube4_t buf;
|
|
|
buf.s8.tA = Clock.Min >> 4;
|
|
@@ -350,6 +425,7 @@ void showYear(void) {
|
|
|
|
|
|
void showHumidity(void) {
|
|
|
dispWDT = DISP_WDT_TIME;
|
|
|
+ HSV2LED(COLOUR_BLUE, 255, BrightLevel);
|
|
|
//in15Percent();
|
|
|
symToFade = sym_Percent;
|
|
|
IN15_FadeIn();
|
|
@@ -365,6 +441,7 @@ void showHumidity(void) {
|
|
|
|
|
|
void showTemperature(void) {
|
|
|
dispWDT = DISP_WDT_TIME;
|
|
|
+ HSV2LED(COLOUR_RED, 255, BrightLevel);
|
|
|
//in15Plus();
|
|
|
symToFade = sym_Plus;
|
|
|
IN15_FadeIn();
|
|
@@ -380,7 +457,7 @@ void showTemperature(void) {
|
|
|
|
|
|
void showPressure(void) {
|
|
|
dispWDT = DISP_WDT_TIME;
|
|
|
- HSV2LED(20, 255, cie[Lvl_Mdl]); // GREEN
|
|
|
+ HSV2LED(COLOUR_GREEN, 255, cie[Lvl_Mdl]); // GREEN
|
|
|
//in15P();
|
|
|
symToFade = sym_Pressure;
|
|
|
IN15_FadeIn();
|
|
@@ -399,13 +476,10 @@ void showPressure(void) {
|
|
|
/* Simple function for cyclic show all sensor data */
|
|
|
void showSensorData(void) {
|
|
|
RTOS_DeleteTask(MinusFadeOut);
|
|
|
- //HSV2LED(1, 255, cie[Lvl_Mdl]); // Nixie color
|
|
|
|
|
|
- HSV2LED(0, 255, cie[Lvl_Mdl]); // RED
|
|
|
showTemperature();
|
|
|
tdelay_ms(3000);
|
|
|
|
|
|
- HSV2LED(40, 255, cie[Lvl_Mdl]); // BLUE
|
|
|
showHumidity();
|
|
|
tdelay_ms(3000);
|
|
|
|
|
@@ -430,7 +504,7 @@ void setTimeShow(void) {
|
|
|
void setTimeBegin(void) {
|
|
|
dispWDT = DISP_WDT_TIME;
|
|
|
in15Minus();
|
|
|
- HSV2LED(1, 255, cie[Lvl_2]);
|
|
|
+ HSV2LED(COLOUR_NIXIE, 255, BrightLevel);
|
|
|
RTOS_SetTask(btnProcess, BTN_TIME_HOLDED, BTN_SCAN_PERIOD);
|
|
|
RTC_ReadAll(&setClock);
|
|
|
}
|