stm32軟體觸發的按鍵長按與短按區分
/* ------------------------------------------------------------------------------------------------ * @fn KeyCoolPressTimeHandle * * @brief 按鍵的檢測 * * @param none * * @return none ************************************************************************************************** */ uint8_t KeyCoolPressTimeHandle(void) { static uint32_t KEY_Cool_PressTime = 0; uint8_t KeyState = KEY_PRESS_NULL; if(KEY_Cool == (uint8_t)Bit_RESET) { if(KEY_Cool_PressTime == 0) { KEY_Cool_PressTime = TcomGetTimerCount(); } if(TcomGetTimerCount() - KEY_Cool_PressTime > LONG_PRESS_TIME) { KeyState = KEY_PRESS_LONG; //KEY_Cool_PressTime = 0; } } else { if(KEY_Cool_PressTime != 0 && TcomGetTimerCount() - KEY_Cool_PressTime > SHORT_PRESS_TIME) { KeyState = KEY_PRESS_SHORT; } KEY_Cool_PressTime = 0; }
return KeyState; } void KeyCoolHandle(void) { uint8_t KeyState = KeyCoolPressTimeHandle(); if(KeyStateStruct.Cool == KEY_PRESS_NULL && KeyState != KEY_PRESS_NULL) { if(KeyState == KEY_PRESS_SHORT) { //執行操作 // ToggleKeyCoolState(); // KeyStateSend(ADDR_COOL);
} else if(KeyState == KEY_PRESS_LONG) { // KEY_LOG("Key Cool Long Press\n"); }
} KeyStateStruct.Cool = KeyState; }