b_mod_button

此功能模块是对第三方代码FlexibleButton的封装。支持独立按键和矩阵按键。

数据结构

typedef void (*pBtnEventHandler_t)(uint32_t dev_no, uint8_t sub_id, uint16_t event, uint8_t param);

typedef struct bButtonInstance
{
    uint32_t                dev_no;
    uint16_t                event;
    pBtnEventHandler_t      handler;
    struct bButtonInstance *next;
} bButtonInstance_t;

//按键事件,1个按键可以同时注册多个事件
#define BTN_EVENT_DOWN (0x001)
#define BTN_EVENT_CLICK (0x002)
#define BTN_EVENT_DOUBLE_CLICK (0x004)
#define BTN_EVENT_REPEAT_CLICK (0x008)
#define BTN_EVENT_SHORT (0x010)
#define BTN_EVENT_SHORT_UP (0x020)
#define BTN_EVENT_LONG (0x040)
#define BTN_EVENT_LONG_UP (0x080)
#define BTN_EVENT_LONGLONG (0x100)
#define BTN_EVENT_LONGLONG_UP (0x200)

接口介绍

#define bBUTTON_ADD_KEY(dev, e, e_handler)           
#define bBUTTON_ADD_MATRIXKEYS(dev, e, e_handler)     
// 请不要直接调用下面这两个函数。使用bBUTTON_ADD_KEY和bBUTTON_ADD_MATRIXKEYS代替
int bButtonAddKey(bButtonInstance_t *pbutton, flex_button_t *pflex);
int bButtonAddMatrixKeys(bButtonInstance_t *pbutton, flex_button_t *pflex);

使用例子

b_hal_if定义按键的硬件接口,b_dev_list.h注册按键设备。

#define HAL_KEY_IF                                                                       
#define HAL_MATRIXKEYS_IF    

void BtnEventHandler(uint32_t dev_no, uint8_t sub_id, uint16_t event, uint8_t param)
{
    b_log("dev:%d id:%d event:%x param:%d\n", dev_no, sub_id, event, param);
}

int main()
{
    ...
    bInit();
    bBUTTON_ADD_KEY(bKEY1, BTN_EVENT_CLICK | BTN_EVENT_LONG, BtnEventHandler);
    bBUTTON_ADD_KEY(bKEY2, BTN_EVENT_CLICK | BTN_EVENT_LONG, BtnEventHandler);
    bBUTTON_ADD_KEY(bKEY3, BTN_EVENT_CLICK | BTN_EVENT_LONG, BtnEventHandler);
    bBUTTON_ADD_KEY(bKEY4, BTN_EVENT_CLICK | BTN_EVENT_LONG, BtnEventHandler);
    bBUTTON_ADD_MATRIXKEYS(bMATRIXKEYS, BTN_EVENT_CLICK | BTN_EVENT_LONG,       BtnEventHandler);    
    ...
}