/* * @Description: * @Date: 2021-03-10 10:49:52 * @LastEditors: CK.Zh * @LastEditTime: 2021-03-10 11:57:47 * @FilePath: \NaviKit_EC_stm32\App\Src\th_button.c */ #define LOG_TAG "TH-Button" #include #include "main.h" #include "navikit.h" //Thread const osThreadAttr_t ButtonDetect_attributes = { .name = "ButtonDetect", .priority = (osPriority_t) osPriorityLow, .stack_size = 128 * 4 }; //Timer const osTimerAttr_t PwrBtnLongPressTimer_attributes = { .name = "PwrBtnLongPressTimer" }; const osTimerAttr_t CustBtnLongPressTimer_attributes = { .name = "CustBtnLongPressTimer" }; const osTimerAttr_t PwrBtnShortPressTimer_attributes = { .name = "PwrBtnShortPressTimer" }; const osTimerAttr_t CustBtnShortPressTimer_attributes = { .name = "CustBtnShortPressTimer" }; /* USER CODE BEGIN Header_StartButtonDetect */ /** * @brief Function implementing the ButtonDetect thread. * @param argument: Not used * @retval None */ /* USER CODE END Header_StartButtonDetect */ void StartButtonDetect(void *argument) { /* USER CODE BEGIN StartButtonDetect */ /* Infinite loop */ log_v("Start Button Detect Task"); for(;;) { //power button if(NaviKit.sys.power_btn && !osTimerIsRunning(PwrBtnLongPressTimerHandle)){ osTimerStart(PwrBtnLongPressTimerHandle,1500); osTimerStart(PwrBtnShortPressTimerHandle,100); } osDelay(2); if(!NaviKit.sys.power_btn && osTimerIsRunning(PwrBtnLongPressTimerHandle)){ osTimerStop(PwrBtnLongPressTimerHandle); osTimerStop(PwrBtnShortPressTimerHandle); } osDelay(2); //custom button if(!NaviKit.sys.custom_btn && osTimerIsRunning(CustBtnLongPressTimerHandle)){ osTimerStop(CustBtnLongPressTimerHandle); osTimerStop(CustBtnShortPressTimerHandle); } osDelay(2); if(NaviKit.sys.custom_btn && !osTimerIsRunning(CustBtnLongPressTimerHandle)){ osTimerStart(CustBtnLongPressTimerHandle,1500); osTimerStart(CustBtnShortPressTimerHandle,100); } osDelay(2); } /* USER CODE END StartButtonDetect */ } void PwrBtnLongPressTimerCallback(void *argument) { log_v("power btn long pressed."); switch(NaviKit.sys.sta){ case run: {NaviKit.sys.next_sta = idle;log_v("change to idle"); }break;//system is run now, user request to idle case idle: {NaviKit.sys.next_sta = run;log_v("change to run"); }break;//system is idle now , user request to power on case dfu: {NaviKit.sys.next_sta = idle;log_v("change to idle"); }break; case sleep:{NaviKit.sys.next_sta = run;log_v("change to run"); }break; case isp: {NaviKit.sys.next_sta = idle;log_v("change to idle"); }break; default : break; } } void CustBtnLongPressTimerCallback(void *argument) { log_v("custom btn long pressed."); switch(NaviKit.sys.sta){ case run:{//system is run now, user request to reboot SOM som_reboot(100); }break; case idle:{ }break; case dfu:{ som_reboot(100); }break; case sleep:{ }break; default : break; } } void PwrBtnShortPressTimerCallback(void *argument) { log_v("power btn short pressed."); switch(NaviKit.sys.sta){ case run: {//som is running, send sleep requeset to operate system log_v("Request operate system pop up the shutdown dialog."); PWR_Enable(SOM_SLEEP,true,100); PWR_Enable(SOM_SLEEP,false,0); }break; case idle: { }break;//system is idle now , user request to power on case dfu: { }break; case sleep:{ }break; case isp: { }break; default : break; } } void CustBtnShortPressTimerCallback(void *argument) { log_v("custom btn short pressed."); switch(NaviKit.sys.sta){ case run:{ }break; case idle:{ }break; case dfu:{ }break; case sleep:{ }break; default : break; } }