From afe2d5317892052d20c3a7ab7b35dba7029d273d Mon Sep 17 00:00:00 2001 From: Charlez Kwan Date: Tue, 21 Jan 2020 15:21:05 +0100 Subject: [PATCH] main.c: added buttons --- Src/main.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/Src/main.c b/Src/main.c index 8ace522..d7853fd 100644 --- a/Src/main.c +++ b/Src/main.c @@ -107,6 +107,9 @@ void Paint_DrawWeekday(void); void Paint_DrawCurrent(uint8_t weekday); void Paint_DrawLoad(bool draw_yes); bool System_SecondHeartbeat(void); +void ButtonLeft_Pressed(void); +void ButtonPress_Pressed(void); +void ButtonRight_Pressed(void); /* USER CODE END PFP */ /* Private user code ---------------------------------------------------------*/ @@ -469,6 +472,46 @@ static void MX_GPIO_Init(void) /* USER CODE BEGIN 4 */ +//keep it short, executed in ISR +void ButtonLeft_Pressed(void){ + if(system_mode==Choose){ + Change_selectorpos(true); + } + if(system_mode==Set){ + Change_time(selector_pos,true); + } +}; +//keep it short, executed in ISR +void ButtonPress_Pressed(void){ + if(selector_pos==28 || selector_pos == 29 || selector_pos == 30){ + if(system_mode == Choose){ //read time to sTimeSet + Read_intosettime(); + } + if(system_mode == Set){ //write time back to RTC + Write_intostime(); + if (HAL_RTC_SetTime(&hrtc, &sTime, RTC_FORMAT_BIN) != HAL_OK) + { + Error_Handler(); + } + if (HAL_RTC_SetDate(&hrtc, &sDate, RTC_FORMAT_BCD) != HAL_OK) + { + Error_Handler(); + } + } + } + + Change_systemmode(); +}; +//keep it short, executed in ISR +void ButtonRight_Pressed(void){ + if(system_mode==Choose){ + Change_selectorpos(false); + } + if(system_mode==Set){ + Change_time(selector_pos,false); + } +}; + int __io_putchar(int ch){ uint8_t c[1]; c[0] = ch & 0x00FF;