#include "clock.h" /* type defs */ typedef struct { uint8_t time; es_event_t pressed; es_event_t holded; uint32_t pin; //(GPIO_TypeDef *) GPIOA; // ?->IDR } btn_t; /* variables */ rtc_t Clock; static rtc_t setClock; static btn_t Button[BTN_NUM] = { {0, evBTN1Pressed, evBTN1Holded, BTN1_PIN}, {0, evBTN2Pressed, evBTN2Pressed, BTN2_PIN}, {0, evBTN3Pressed, evBTN3Pressed, BTN3_PIN}, {0, evBTN4Pressed, evBTN4Holded, BTN4_PIN} }; volatile static uint8_t dispWDT = 0; static in15_pin_t symToFade = 0; /* function prototypes */ //static void Color_RGB(const uint8_t r, const uint8_t g, const uint8_t b); static void MinusFadeIn(void); static void MinusFadeOut(void); static void PlusFadeIn(void); static void PercentFadeIn(void); static void PressureFadeIn(void); 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); /* 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); } /** * @brief Обработка кнопок. * @param : None * @retval : None */ void btnProcess(void) { /* get pin state */ uint32_t pins = BTNS_STATE; int i; for (i=0; i= (BTN_TIME_HOLDED/BTN_SCAN_PERIOD)) { Button[i].time -= (BTN_TIME_REPEATED/BTN_SCAN_PERIOD); if (Button[i].holded == Button[i].pressed) { /* if pressed and holded - same function, then button pressed auto repeat */ ES_PlaceEvent(Button[i].pressed); } } } else if (Button[i].time != 0) { /* button released */ if (Button[i].time >= ((BTN_TIME_HOLDED - BTN_TIME_REPEATED)/BTN_SCAN_PERIOD)) { /* process long press */ ES_PlaceEvent(Button[i].holded); } else if (Button[i].time >= (BTN_TIME_PRESSED/BTN_SCAN_PERIOD)) { /* process short press */ ES_PlaceEvent(Button[i].pressed); } Button[i].time = 0; RTOS_SetTask(btnProcess, BTN_SCAN_PAUSE, BTN_SCAN_PERIOD); } } /* end FOR */ } void new_Second(void) { // Blink_Start(); // !!! TODO RTC_ReadAll(&Clock); if (dispWDT != 0) { dispWDT--; if (dispWDT == 0) { ES_PlaceEvent(evDisplayWDT); } } } /** * On/off symbols on IN-15 tube. */ void in15Off(void) { IN15_OFF; TUBE_C_OFF; } void in15Minus(void) { IN15_OFF; IN15_Minus; TUBE_C_ON; } void in15Plus(void) { IN15_OFF; IN15_Plus; TUBE_C_ON; } void in15Percent(void) { IN15_OFF; IN15_Percent; TUBE_C_ON; } void in15P(void) { IN15_OFF; IN15_P; TUBE_C_ON; } /** 'Faded' funcions */ static void MinusFadeIn(void) { static uint8_t on = FADE_START; static uint8_t off = FADE_STOP; static uint8_t st = 0; if (st == 0) { st = 1; IN15_Minus; on += FADE_STEP; if (on < FADE_STOP) { RTOS_SetTask(MinusFadeIn, on, 0); } else { on = FADE_START; off = FADE_STOP; st = 0; } } else { st = 0; IN15_OFF; off -= FADE_STEP; RTOS_SetTask(MinusFadeIn, off, 0); } } static void MinusFadeOut(void) { static uint8_t off = FADE_START; static uint8_t on = FADE_STOP; static uint8_t st = 0; if (st == 0) { st = 1; IN15_OFF; off += FADE_STEP; if (off < FADE_STOP) { RTOS_SetTask(MinusFadeOut, off, 0); } else { off = FADE_START; on = FADE_STOP; st = 0; } } else { st = 0; IN15_Minus; on -= FADE_STEP; RTOS_SetTask(MinusFadeOut, on, 0); } } static void PlusFadeIn(void) { static uint8_t on = FADE_START; static uint8_t off = FADE_STOP; static uint8_t st = 0; if (st == 0) { st = 1; IN15_Plus; on += FADE_STEP; if (on < FADE_STOP) { RTOS_SetTask(PlusFadeIn, on, 0); } else { on = FADE_START; off = FADE_STOP; st = 0; } } else { st = 0; IN15_OFF; off -= FADE_STEP; RTOS_SetTask(PlusFadeIn, off, 0); } } static void PercentFadeIn(void) { static uint8_t on = FADE_START; static uint8_t off = FADE_STOP; static uint8_t st = 0; if (st == 0) { st = 1; IN15_Percent; on += FADE_STEP; if (on < FADE_STOP) { RTOS_SetTask(PercentFadeIn, on, 0); } else { on = FADE_START; off = FADE_STOP; st = 0; } } else { st = 0; IN15_OFF; off -= FADE_STEP; RTOS_SetTask(PercentFadeIn, off, 0); } } static void PressureFadeIn(void) { static uint8_t on = FADE_START; static uint8_t off = FADE_STOP; static uint8_t st = 0; if (st == 0) { st = 1; IN15_P; on += FADE_STEP; if (on < FADE_STOP) { RTOS_SetTask(PressureFadeIn, on, 0); } else { on = FADE_START; off = FADE_STOP; st = 0; } } else { st = 0; IN15_OFF; off -= FADE_STEP; RTOS_SetTask(PressureFadeIn, off, 0); } } static void IN15_FadeIn(void) { static uint8_t on = FADE_START; static uint8_t off = FADE_STOP; static uint8_t st = 0; if (st == 0) { st = 1; GPIOA->BSRR = symToFade; on += FADE_STEP; if (on < FADE_STOP) { RTOS_SetTask(IN15_FadeIn, on, 0); } else { on = FADE_START; off = FADE_STOP; st = 0; symToFade = 0; } } else { st = 0; IN15_OFF; off -= FADE_STEP; RTOS_SetTask(IN15_FadeIn, off, 0); } } static void IN15_FadeOut(void) { static uint8_t off = FADE_START; static uint8_t on = FADE_STOP; static uint8_t st = 0; if (st == 0) { st = 1; IN15_OFF; off += FADE_STEP; if (off < FADE_STOP) { RTOS_SetTask(IN15_FadeOut, off, 0); } else { off = FADE_START; on = FADE_STOP; st = 0; symToFade = 0; } } else { st = 0; GPIOA->BSRR = symToFade; on -= FADE_STEP; RTOS_SetTask(IN15_FadeOut, on, 0); } } /** * Show info on tubes. */ void showTime(void) { MinusFadeIn(); RTOS_SetTask(MinusFadeOut, 500, 0); uint8_t hue = bcd2bin(Clock.Sec); HSV2LED(hue, 255, cie[Lvl_Mdl]); tube4_t buf; buf.s8.tA = Clock.Hr >> 4; buf.s8.tB = Clock.Hr & 0xf; buf.s8.tD = Clock.Min >> 4; buf.s8.tE = Clock.Min & 0xf; showDigits(buf); } void showMMSS(void) { RTOS_DeleteTask(MinusFadeOut); IN15_Minus; uint8_t hue = bcd2bin(Clock.Sec); HSV2LED(hue, 255, cie[Lvl_Mdl]); tube4_t buf; buf.s8.tA = Clock.Min >> 4; buf.s8.tB = Clock.Min & 0xf; buf.s8.tD = Clock.Sec >> 4; buf.s8.tE = Clock.Sec & 0xf; showDigits(buf); } void showWD(void) { dispWDT = DISP_WDT_TIME; IN15_OFF; tube4_t buf; buf.s8.tA = 0xf; buf.s8.tB = Clock.WD & 0xf; buf.s8.tD = 0xf; buf.s8.tE = 0xf; showDigits(buf); } void showDay(void) { dispWDT = DISP_WDT_TIME; IN15_OFF; tube4_t buf; buf.s8.tA = Clock.Day >> 4; buf.s8.tB = Clock.Day & 0xf; buf.s8.tD = 0xf; buf.s8.tE = 0xf; showDigits(buf); } void showMonth(void) { dispWDT = DISP_WDT_TIME; IN15_OFF; tube4_t buf; buf.s8.tA = 0xf; buf.s8.tB = 0xf; buf.s8.tD = Clock.Mon >> 4; buf.s8.tE = Clock.Mon & 0xf; showDigits(buf); } void showDayMon(void) { dispWDT = DISP_WDT_TIME; IN15_OFF; tube4_t buf; buf.s8.tA = Clock.Day >> 4; buf.s8.tB = Clock.Day & 0xf; buf.s8.tD = Clock.Mon >> 4; buf.s8.tE = Clock.Mon & 0xf; showDigits(buf); } void showYear(void) { dispWDT = DISP_WDT_TIME; IN15_OFF; tube4_t buf; buf.s8.tA = 2; buf.s8.tB = 0; buf.s8.tD = Clock.Year >> 4; buf.s8.tE = Clock.Year & 0xf; showDigits(buf); } void showHumidity(void) { dispWDT = DISP_WDT_TIME; //in15Percent(); symToFade = sym_Percent; IN15_FadeIn(); //PercentFadeIn(); tube4_t buf; buf.s8.tA = Humidity / 10; buf.s8.tB = Humidity % 10; buf.s8.tD = 0xf; buf.s8.tE = 0xf; showDigits(buf); } void showTemperature(void) { dispWDT = DISP_WDT_TIME; //in15Plus(); symToFade = sym_Plus; IN15_FadeIn(); //PlusFadeIn(); tube4_t buf; buf.s8.tA = 0xf; buf.s8.tB = 0xf; buf.s8.tD = Temperature / 10; buf.s8.tE = Temperature % 10; showDigits(buf); } void showPressure(void) { dispWDT = DISP_WDT_TIME; //in15P(); symToFade = sym_Pressure; IN15_FadeIn(); //PressureFadeIn(); tube4_t buf; int tmp; buf.s8.tA = 0xf; buf.s8.tB = Pressure / 100; tmp = Pressure % 100; buf.s8.tD = tmp / 10; buf.s8.tE = tmp % 10; showDigits(buf); } /* 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); HSV2LED(20, 255, cie[Lvl_Mdl]); // GREEN showPressure(); tdelay_ms(2700); ES_SetState(stShowTime); // showTime(); } void setTimeShow(void) { dispWDT = DISP_WDT_TIME; in15Minus(); HSV2LED(1, 255, cie[Lvl_2]); tube4_t buf; buf.s8.tA = setClock.Hr >> 4; buf.s8.tB = setClock.Hr & 0xf; buf.s8.tD = setClock.Min >> 4; buf.s8.tE = setClock.Min & 0xf; showDigits(buf); } void setTimeBegin(void) { dispWDT = DISP_WDT_TIME; RTOS_SetTask(btnProcess, BTN_TIME_HOLDED, BTN_SCAN_PERIOD); RTC_ReadAll(&setClock); } void setHHBegin(void) { dispWDT = DISP_WDT_TIME; Flag.Blink_1 = 1; Flag.Blink_2 = 1; Flag.Blink_4 = 0; Flag.Blink_5 = 0; Blink_Start(); setTimeShow(); } void setHHInc(void) { dispWDT = DISP_WDT_TIME; valIncrease(&setClock.Hr, 23); } void setHHDec(void) { dispWDT = DISP_WDT_TIME; valDecrease(&setClock.Hr, 23); } void setMMBegin(void) { dispWDT = DISP_WDT_TIME; Flag.Blink_1 = 0; Flag.Blink_2 = 0; Flag.Blink_4 = 1; Flag.Blink_5 = 1; Blink_Start(); setTimeShow(); } void setMMInc(void) { dispWDT = DISP_WDT_TIME; valIncrease(&setClock.Min, 59); } void setMMDec(void) { dispWDT = DISP_WDT_TIME; valDecrease(&setClock.Min, 59); } void setTimeEnd(void) { RTOS_SetTask(btnProcess, BTN_TIME_HOLDED, BTN_SCAN_PERIOD); setClock.Sec = 0; RTC_WriteTime(&setClock); Flag.Blink_1 = 0; Flag.Blink_2 = 0; Flag.Blink_4 = 0; Flag.Blink_5 = 0; Blink_Stop(); RTC_ReadAll(&Clock); } void setDateBegin(void) { } void setDateEnd(void) { } void setWShow(void) { } void setDMShow(void) { } void setYearShow(void) { } void setWDayBegin(void) { } void setMDayBegin(void) { } void setMonthBegin(void) { } void setYearBegin(void) { } void setIncWDay(void) { } void setIncMDay(void) { } void setIncMonth(void) { } void setIncYear(void) { } void setDecWDay(void) { } void setDecMDay(void) { } void setDecMonth(void) { } void setDecYear(void) { } /** * @brief Increase BCD value. * @param : val, max * @retval : None */ static void valIncrease(uint8_t * val, uint8_t max) { uint8_t bin = 10 * (*val >> 4) + (*val & 0x0f); if (bin < max) { bin ++; } else { bin = 0; } *val = ((bin / 10 ) << 4) | (bin % 10); } /** * @brief Decrease BCD value. * @param : value, max * @retval : None */ static void valDecrease(uint8_t * val, uint8_t max) { uint8_t bin = 10 * (*val >> 4) + (*val & 0x0f); if (bin > 0) { bin --; } else { bin = max; } *val = ((bin / 10 ) << 4) | (bin % 10); }