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;    
}

猜你喜欢

转载自blog.csdn.net/guiwukejiBGG/article/details/83956746
今日推荐