typedef enum {
ButtonsStateUp = 0,
ButtonsStateDownJitter ,
ButtonsStateDown ,
ButtonsStateUpJitter
} EnumButtonsState;
typedef unsigned char uint8;
typedef unsigned long uint32;
#define BUTTONS_UP 0
#defien BUTTONS_DOWN 1
#define BUTTONS_EVENT_NONE 0x00
#define BUTTONS_EVENT_SINGLE_DOWN 0x01
#define BUTTONS_EVENT_SERIES_DOWN 0x02
#define BUTTONS_EVENT_CONTINUE_DOWN 0x03
#define BUTTONS_EVENT_UP 0x04
EnumButtonsState ButtonsState;
void ButtonsScanSM(uint8 *event_type)
{
uint8 buttons_status;
static uint32 time_point = 0;
static uint8 series_down_flg = 0;
buttons_status = GetButtonsStatus();
switch(ButtonsState)
{
case ButtonsStateUp:
{
if(GetSysTicks() - time_point > 1000u)
{
series_down_flg = 0;
}
if(buttons_status == BUTTONS_UP)
{
;
}
else
{
ButtonsState = ButtonsStateDownJitter;
基于状态机思想的按键扫描程序支持单按,连续按,长按模式。
最新推荐文章于 2024-08-19 19:17:55 发布