I wrote code for determining the push button state whether it is long pressed or not. This function is called by timer interrupt routine every 1ms.
But it seems really dumb. How can I make it shorter and more efficient according to both readability and professional rules? What should I add or change to get double Tap pressing information with this code?
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
{
/*button pressed and count*/
if(!HAL_GPIO_ReadPin(GPIOC, GPIO_PIN_13))
{
usTick++;
}
/*not pressed*/
else
{
if( usTick > 1000){
ButtonState.PressedState = LongPressed;
HAL_GPIO_TogglePin(GPIOA,GPIO_PIN_5);
usTick = 0;
}
else if( usTick >350){
ButtonState.PressedState = ShortPressed;
HAL_GPIO_TogglePin(GPIOA,GPIO_PIN_5);
usTick = 0;
}
usTick = 0;
}
}