12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061 |
- #include "clock.h"
- #include "utils.h"
- /* type defs */
- typedef struct t_btn {
- 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}
- };
- //convert linear bright level to logariphmic
- const uint8_t cie[MAX_BRIGHT_LVL + 1] = {
- 0, 2, 4, 8, 13, 20, 29, 40, 54, 72, 92, 116, 145, 177, 214, 255
- };
- volatile static uint8_t dispWDT = 0;
- volatile in15_pin_t SymbolIN15 = sym_None;
- static in15_pin_t symToFade = 0;
- static uint8_t LightingBright;
- static light_mode_t LightingMode;
- static uint8_t LightingColour;
- static flash_data_t Lighting, setLighting;
- /* function prototypes */
- static void check_DayNight(void);
- static void HSV2LED(const uint8_t hue, const uint8_t val);
- 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, 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 dvalDecrease(uint8_t * val, const uint8_t max);
- static void showRainbow(void);
- /* funcions */
- void Clock_Init(void) {
- RTC_ReadAll(&Clock);
- showTime();
- flash_result_t flash_res = Flash_Read(&Lighting.u64);
- if ((flash_res != Flash_Ok) || (Lighting.name.DayHour == 0xff)) {
- Lighting.name.DayHour = MORNING_HOUR;
- Lighting.name.NightHour = EVENING_HOUR;
- Lighting.name.DayBright = DAY_BR_LVL;
- Lighting.name.NightBright = NIGHT_BR_LVL;
- Lighting.name.DayMode = light_Rainbow;
- Lighting.name.NightMode = light_Colour;
- Lighting.name.NightColour = COLOUR_NIXIE;
- }
- check_DayNight();
- }
- static void check_DayNight(void) {
- if ((Clock.Hr >= Lighting.name.DayHour) && (Clock.Hr < Lighting.name.NightHour)) {
- Flag.Now_Day = 1;
- LightingBright = cie[Lighting.name.DayBright];
- LightingMode = Lighting.name.DayMode;
- LightingColour = Lighting.name.DayColour;
- } else {
- Flag.Now_Day = 0;
- LightingBright = cie[Lighting.name.NightBright];
- LightingMode = Lighting.name.NightMode;
- LightingColour = Lighting.name.NightColour;
- }
- //tube_BrightLevel(Tube_All, LightingBright);
- TUBES_BRIGHT(LightingBright);
- }
- /**
- * @brief Обработка кнопок.
- * @param : None
- * @retval : None
- */
- void btnProcess(void) {
- /* get pin state */
- uint32_t pins = BTNS_STATE;
- int i;
- for (i=0; i<BTN_NUM; i++) {
- if ((pins & Button[i].pin) == 0) {
- /* button pressed */
- Button[i].time ++;
- if (Button[i].time >= (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) {
- 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) {
- Blink_Stop();
- ES_PlaceEvent(evDisplayWDT);
- }
- }
- }
- /**
- * On/off symbols on IN-15 tube.
- */
- void in15Off(void) {
- IN15_OFF;
- //TUBE_C_OFF;
- //while (SymbolIN15 != sym_None) {}
- //SymbolIN15 = sym_Off;
- }
- void in15Minus(void) {
- //IN15_OFF;
- //IN15_Minus;
- //TUBE_C_ON;
- while (SymbolIN15 != sym_None) {}
- SymbolIN15 = sym_Minus;
- }
- void in15Plus(void) {
- IN15_OFF;
- //IN15_Plus;
- //TUBE_C_ON;
- SymbolIN15 = sym_Plus;
- }
- void in15Percent(void) {
- IN15_OFF;
- //IN15_Percent;
- //TUBE_C_ON;
- SymbolIN15 = sym_Percent;
- }
- void in15P(void) {
- IN15_OFF;
- //IN15_P;
- //TUBE_C_ON;
- SymbolIN15 = sym_Pressure;
- }
- /** '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 (symToFade != 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 (symToFade != 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);
- }
- }
- }
- /**
- * @brief HSV to RGB convertion
- * @param hue: 0-59, sat: allways max, val (lightness): 0-255
- * @return none. RGB value output direct to LED.
- */
- static void HSV2LED(const uint8_t hue, const uint8_t val) {
- uint32_t r=0, g=0, b=0;
- switch (hue / 10) {
- case 0:
- r = val;
- g = (val * hue) / 10;
- b = 0;
- break;
- case 1:
- r = (val * (10 - (hue % 10))) / 10;
- g = val;
- b = 0;
- break;
- case 2:
- r = 0;
- g = val;
- b = (val * (hue % 10)) / 10;
- break;
- case 3:
- r = 0;
- g = (val * (10 - (hue % 10))) / 10;
- b = val;
- break;
- case 4:
- r = (val * (hue % 10)) / 10;
- g = 0;
- b = val;
- break;
- case 5:
- r = val;
- g = 0;
- b = (val * (10 - (hue % 10))) / 10;
- break;
- }
- COLOR_R((uint8_t)r);
- COLOR_G((uint8_t)g);
- COLOR_B((uint8_t)b);
- }
- /**
- * Show info on tubes.
- */
- void showTime(void) {
- uint8_t hue;
- //MinusFadeIn();
- in15Minus();
- RTOS_SetTask(in15Off, 500, 0);
- switch (LightingMode) {
- case light_Rainbow:
- hue = bcd2bin(Clock.Sec);
- HSV2LED(hue, LightingBright);
- break;
- case light_Colour:
- HSV2LED(LightingColour, LightingBright);
- break;
-
- default:
- LEDS_OFF;
- break;
- }
- if (Clock.Sec != 0) {
- tube4_t buf;
- uint8_t hour = Clock.Hr >> 4;
- if (hour == 0) {
- buf.s8.tA = TUBE_BLANK;
- } else {
- buf.s8.tA = hour;
- }
- buf.s8.tB = Clock.Hr & 0xf;
- buf.s8.tD = Clock.Min >> 4;
- buf.s8.tE = Clock.Min & 0xf;
- showDigits(buf);
- } else {
- tube_Refresh();
- }
- }
- void showMMSS(void) {
- RTOS_DeleteTask(MinusFadeOut);
- IN15_Minus;
- uint8_t hue = bcd2bin(Clock.Sec);
- HSV2LED(hue, LightingBright);
- 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 = TUBE_BLANK;
- buf.s8.tB = Clock.WD & 0xf;
- buf.s8.tD = TUBE_BLANK;
- buf.s8.tE = TUBE_BLANK;
- 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/2;
- HSV2LED(COLOUR_BLUE, LightingBright);
- symToFade = sym_Percent;
- IN15_FadeIn();
- tube4_t buf;
- buf.s8.tA = Humidity / 10;
- buf.s8.tB = Humidity % 10;
- buf.s8.tD = TUBE_BLANK;
- buf.s8.tE = TUBE_BLANK;
- showDigits(buf);
- }
- void showTemperature(void) {
- dispWDT = DISP_WDT_TIME/2;
- HSV2LED(COLOUR_RED, LightingBright);
- RTOS_DeleteTask(MinusFadeIn);
- RTOS_DeleteTask(MinusFadeOut);
- symToFade = sym_Plus;
- IN15_FadeIn();
- tube4_t buf;
- buf.s8.tA = TUBE_BLANK;
- buf.s8.tB = TUBE_BLANK;
- buf.s8.tD = Temperature / 10;
- buf.s8.tE = Temperature % 10;
- showDigits(buf);
- }
- void showPressure(void) {
- dispWDT = DISP_WDT_TIME/2;
- HSV2LED(COLOUR_GREEN, LightingBright);
- symToFade = sym_Pressure;
- IN15_FadeIn();
- tube4_t buf;
- int tmp;
- buf.s8.tA = TUBE_BLANK;
- 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);
- showTemperature();
- tdelay_ms(3000);
- showHumidity();
- tdelay_ms(3000);
- showPressure();
- tdelay_ms(2700);
- ES_SetState(stShowTime);
- // showTime();
- }
- void setTimeShow(void) {
- dispWDT = DISP_WDT_TIME;
- 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) {
- RTOS_DeleteTask(MinusFadeOut);
- in15Minus();
- HSV2LED(COLOUR_NIXIE, LightingBright);
- RTOS_SetTask(btnProcess, BTN_TIME_HOLDED, BTN_SCAN_PERIOD);
- RTC_ReadAll(&setClock);
- }
- void setHHBegin(void) {
- Flag.Blink_1 = 1;
- Flag.Blink_2 = 1;
- Flag.Blink_4 = 0;
- Flag.Blink_5 = 0;
- Blink_Start();
- setTimeShow();
- }
- void setHHInc(void) {
- valIncrease(&setClock.Hr, 23);
- }
- void setHHDec(void) {
- valDecrease(&setClock.Hr, 23);
- }
- void setMMBegin(void) {
- Flag.Blink_1 = 0;
- Flag.Blink_2 = 0;
- Flag.Blink_4 = 1;
- Flag.Blink_5 = 1;
- Blink_Start();
- setTimeShow();
- }
- void setMMInc(void) {
- valIncrease(&setClock.Min, 59);
- }
- void setMMDec(void) {
- valDecrease(&setClock.Min, 59);
- }
- void setTimeEnd(void) {
- dispWDT = 0;
- RTOS_SetTask(btnProcess, BTN_TIME_HOLDED, BTN_SCAN_PERIOD);
- setClock.Sec = 0;
- RTC_WriteTime(&setClock);
- Blink_Stop();
- RTC_ReadAll(&Clock);
- }
- void setDateBegin(void) {
- IN15_OFF;
- HSV2LED(COLOUR_NIXIE, LightingBright);
- RTOS_SetTask(btnProcess, BTN_TIME_HOLDED, BTN_SCAN_PERIOD);
- RTC_ReadAll(&setClock);
- }
- void setDateEnd(void) {
- dispWDT = 0;
- RTOS_SetTask(btnProcess, BTN_TIME_HOLDED, BTN_SCAN_PERIOD);
-
- RTC_WriteCalendar(&setClock);
- Blink_Stop();
- RTC_ReadAll(&Clock);
- }
- void setWDBegin(void) {
- Flag.Blink_1 = 0;
- Flag.Blink_2 = 1;
- Flag.Blink_4 = 0;
- Flag.Blink_5 = 0;
- Blink_Start();
- setWDShow();
- }
- void setWDShow(void) {
- dispWDT = DISP_WDT_TIME;
- tube4_t buf;
- buf.s8.tA = TUBE_BLANK;
- buf.s8.tB = setClock.WD & 0xf;
- buf.s8.tD = TUBE_BLANK;
- buf.s8.tE = TUBE_BLANK;
- showDigits(buf);
- }
- void setDMShow(void) {
- dispWDT = DISP_WDT_TIME;
- tube4_t buf;
- buf.s8.tA = setClock.Day >> 4;
- buf.s8.tB = setClock.Day & 0xf;
- buf.s8.tD = setClock.Mon >> 4;
- buf.s8.tE = setClock.Mon & 0xf;
- showDigits(buf);
- }
- void setYearShow(void) {
- dispWDT = DISP_WDT_TIME;
- tube4_t buf;
- buf.s8.tA = 2;
- buf.s8.tB = 0;
- buf.s8.tD = setClock.Year >> 4;
- buf.s8.tE = setClock.Year & 0xf;
- showDigits(buf);
- }
- void setMDBegin(void) {
- Flag.Blink_1 = 1;
- Flag.Blink_2 = 1;
- Flag.Blink_4 = 0;
- Flag.Blink_5 = 0;
- Blink_Start();
- setDMShow();
- }
- void setMonthBegin(void) {
- Flag.Blink_1 = 0;
- Flag.Blink_2 = 0;
- Flag.Blink_4 = 1;
- Flag.Blink_5 = 1;
- Blink_Start();
- setDMShow();
- }
- void setYearBegin(void) {
- Flag.Blink_1 = 0;
- Flag.Blink_2 = 0;
- Flag.Blink_4 = 1;
- Flag.Blink_5 = 1;
- Blink_Start();
- setYearShow();
- }
- void setIncWDay(void) {
- valIncrease(&setClock.WD, 7);
- }
- void setIncMDay(void) {
- valIncrease(&setClock.Day, 31);
- }
- void setIncMonth(void) {
- valIncrease(&setClock.Mon, 12);
- }
- void setIncYear(void) {
- valIncrease(&setClock.Year, 99);
- }
- void setDecWDay(void) {
- valDecrease(&setClock.WD, 7);
- }
- void setDecMDay(void) {
- valDecrease(&setClock.Day, 31);
- }
- void setDecMonth(void) {
- valDecrease(&setClock.Mon, 12);
- }
- void setDecYear(void) {
- valDecrease(&setClock.Year, 99);
- }
- void showDNhour(void) {
- dispWDT = DISP_WDT_TIME;
- tube4_t buf;
- es_state_t e_st = ES_GetState();
- if (e_st == stShowDNhours){
- buf.s8.tA = Lighting.name.DayHour >> 4;
- buf.s8.tB = Lighting.name.DayHour & 0xf;
- buf.s8.tD = Lighting.name.NightHour >> 4;
- buf.s8.tE = Lighting.name.NightHour & 0xf;
- } else {
- buf.s8.tA = setLighting.name.DayHour >> 4;
- buf.s8.tB = setLighting.name.DayHour & 0xf;
- buf.s8.tD = setLighting.name.NightHour >> 4;
- buf.s8.tE = setLighting.name.NightHour & 0xf;
- }
- showDigits(buf);
- }
- void showDNbright(void) {
- dispWDT = DISP_WDT_TIME;
- tube4_t buf;
- es_state_t e_st = ES_GetState();
- if (e_st == stShowDNbright){
- buf.s8.tA = Lighting.name.DayBright / 10;
- buf.s8.tB = Lighting.name.DayBright % 10;
- buf.s8.tD = Lighting.name.NightBright / 10;
- buf.s8.tE = Lighting.name.NightBright % 10;
- } else {
- buf.s8.tA = setLighting.name.DayBright / 10;
- buf.s8.tB = setLighting.name.DayBright % 10;
- buf.s8.tD = setLighting.name.NightBright / 10;
- buf.s8.tE = setLighting.name.NightBright % 10;
- }
- showDigits(buf);
- }
- void showDNmode(void) {
- dispWDT = DISP_WDT_TIME;
- uint8_t dm, nm;
- tube4_t buf;
- es_state_t e_st = ES_GetState();
- if (e_st == stShowDNmode){
- dm = Lighting.name.DayMode;
- nm = Lighting.name.NightMode;
- } else {
- dm = setLighting.name.DayMode;
- nm = setLighting.name.NightMode;
- }
- buf.s8.tA = TUBE_BLANK;
- buf.s8.tB = dm & 0xf;
- buf.s8.tD = TUBE_BLANK;
- buf.s8.tE = nm & 0xf;
- showDigits(buf);
- }
- void showDNcolour(void) {
- dispWDT = DISP_WDT_TIME;
- tube4_t buf;
- es_state_t e_st = ES_GetState();
- if (e_st == stShowDNcolour){
- buf.s8.tA = Lighting.name.DayColour / 10;
- buf.s8.tB = Lighting.name.DayColour % 10;
- buf.s8.tD = Lighting.name.NightColour / 10;
- buf.s8.tE = Lighting.name.NightColour % 10;
- } else {
- buf.s8.tA = setLighting.name.DayColour / 10;
- buf.s8.tB = setLighting.name.DayColour % 10;
- buf.s8.tD = setLighting.name.NightColour / 10;
- buf.s8.tE = setLighting.name.NightColour % 10;
- }
- showDigits(buf);
- }
- void setDNbegin(void) {
- IN15_OFF;
- RTOS_SetTask(btnProcess, BTN_TIME_HOLDED, BTN_SCAN_PERIOD);
- setLighting.u64 = Lighting.u64;
- //Flash_Read(&setLighting.u64);
- }
- void setDNend(void) {
- dispWDT = 0;
- RTOS_SetTask(btnProcess, BTN_TIME_HOLDED, BTN_SCAN_PERIOD);
- Blink_Stop();
- LEDS_OFF;
- Flash_Write(&setLighting.u64);
- Lighting.u64 = setLighting.u64;
- check_DayNight();
- }
- void setDayHourBegin(void) {
- LEDS_OFF;
- Flag.Blink_1 = 1;
- Flag.Blink_2 = 1;
- Flag.Blink_4 = 0;
- Flag.Blink_5 = 0;
- Blink_Start();
- showDNhour();
- }
- void setNightHourBegin(void) {
- Flag.Blink_1 = 0;
- Flag.Blink_2 = 0;
- Flag.Blink_4 = 1;
- Flag.Blink_5 = 1;
- Blink_Start();
- showDNhour();
- }
- void setDayBrightBegin(void) {
- Flag.Blink_1 = 1;
- Flag.Blink_2 = 1;
- Flag.Blink_4 = 0;
- Flag.Blink_5 = 0;
- Blink_Start();
- showDNbright();
- }
- void setNightBrightBegin(void) {
- Flag.Blink_1 = 0;
- Flag.Blink_2 = 0;
- Flag.Blink_4 = 1;
- Flag.Blink_5 = 1;
- Blink_Start();
- showDNbright();
- }
- void setDayModeBegin(void) {
- Flag.Blink_1 = 0;
- Flag.Blink_2 = 1;
- Flag.Blink_4 = 0;
- Flag.Blink_5 = 0;
- Blink_Start();
- showDNmode();
- }
- void setNightModeBegin(void) {
- Flag.Blink_1 = 0;
- Flag.Blink_2 = 0;
- Flag.Blink_4 = 0;
- Flag.Blink_5 = 1;
- Blink_Start();
- showDNmode();
- }
- void setDayColourBegin(void) {
- Flag.Blink_1 = 1;
- Flag.Blink_2 = 1;
- Flag.Blink_4 = 0;
- Flag.Blink_5 = 0;
- Blink_Start();
- HSV2LED(setLighting.name.DayColour, LightingBright);
- showDNcolour();
- }
- void setNightColourBegin(void) {
- Flag.Blink_1 = 0;
- Flag.Blink_2 = 0;
- Flag.Blink_4 = 1;
- Flag.Blink_5 = 1;
- Blink_Start();
- HSV2LED(setLighting.name.NightColour, LightingBright);
- showDNcolour();
- }
- void setIncDayHour(void) {
- valIncrease(&setLighting.name.DayHour, 23);
- }
- void setIncDayBright(void) {
- dvalIncrease(&setLighting.name.DayBright, MAX_BRIGHT_LVL);
- //tube_BrightLevel(Tube_All, setLighting.name.DayBright);
- TUBES_BRIGHT(setLighting.name.DayBright);
- }
- void setIncDayMode(void) {
- 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) {
- dvalIncrease(&setLighting.name.DayColour, MAX_COLOR_VAL);
- HSV2LED(setLighting.name.DayColour, LightingBright);
- }
- void setDecDayHour(void) {
- valDecrease(&setLighting.name.DayHour, 23);
- }
- void setDecDayBright(void) {
- dvalDecrease(&setLighting.name.DayBright, MAX_BRIGHT_LVL);
- //tube_BrightLevel(Tube_All, setLighting.name.DayBright);
- TUBES_BRIGHT(setLighting.name.DayBright);
- }
- void setDecDayMode(void) {
- 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) {
- dvalDecrease(&setLighting.name.DayColour, MAX_COLOR_VAL);
- HSV2LED(setLighting.name.DayColour, LightingBright);
- }
- void setIncNightHour(void) {
- valIncrease(&setLighting.name.NightHour, 23);
- }
- void setIncNightBright(void) {
- dvalIncrease(&setLighting.name.NightBright, MAX_BRIGHT_LVL);
- //tube_BrightLevel(Tube_All, setLighting.name.NightBright);
- TUBES_BRIGHT(setLighting.name.NightBright);
- }
- void setIncNightMode(void) {
- 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) {
- dvalIncrease(&setLighting.name.NightColour, MAX_COLOR_VAL);
- HSV2LED(setLighting.name.NightColour, LightingBright);
- }
- void setDecNightHour(void) {
- valDecrease(&setLighting.name.NightHour, 23);
- }
- void setDecNightBright(void) {
- dvalDecrease(&setLighting.name.NightBright, MAX_BRIGHT_LVL);
- //tube_BrightLevel(Tube_All, setLighting.name.NightBright);
- TUBES_BRIGHT(setLighting.name.NightBright);
- }
- void setDecNightMode(void) {
- 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) {
- dvalDecrease(&setLighting.name.NightColour, MAX_COLOR_VAL);
- HSV2LED(setLighting.name.NightColour, LightingBright);
- }
- void setDNbreak(void) {
- // restore led and tube bright level
- check_DayNight();
- }
- /**
- * @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);
- }
- /**
- * @brief Increase/Decrease decimal value.
- * @param val
- * @param max
- * @retval : None, change value
- */
- static void dvalIncrease(uint8_t * val, uint8_t max) {
- if (*val < max) {
- *val += 1;
- } else {
- *val = 0;
- }
- }
- static void dvalDecrease(uint8_t * val, uint8_t max) {
- if (*val > 0) {
- *val -= 1;
- } else {
- *val = max;
- }
- }
- static void showRainbow(void) {
- static uint8_t hue = 0;
- HSV2LED(hue, LightingBright);
- if (hue < 59) {
- hue ++;
- } else {
- hue = 0;
- RTOS_DeleteTask(showRainbow);
- }
- }
|