UP 优化key库
parent
8bf40f0d9c
commit
58afcd9d81
|
@ -77,21 +77,14 @@ void Get_Key(void *pVoid) {
|
|||
key_init(&k6, SIM_Key_SET, 1, SIM_KEY_SET);
|
||||
key_init(&k7, SIM_Key_RESET, 1, SIM_KEY_RESET);
|
||||
|
||||
key_attach(&k1, KEY_ALL_EVENT, Key_Call_E);
|
||||
key_attach(&k2, KEY_ALL_EVENT, Key_Call_E);
|
||||
key_attach(&k3, KEY_ALL_EVENT, Key_Call_E);
|
||||
key_attach(&k4, KEY_ALL_EVENT, Key_Call_E);
|
||||
key_attach(&k5, KEY_ALL_EVENT, Key_Call_E);
|
||||
key_attach(&k6, KEY_ALL_EVENT, Key_Call_E);
|
||||
key_attach(&k7, KEY_ALL_EVENT, Key_Call_E);
|
||||
key_attach(&k1, KEY_ALL_EVENT, Key_Call_E, true);
|
||||
key_attach(&k2, KEY_ALL_EVENT, Key_Call_E, true);
|
||||
key_attach(&k3, KEY_ALL_EVENT, Key_Call_E, true);
|
||||
key_attach(&k4, KEY_ALL_EVENT, Key_Call_E, true);
|
||||
key_attach(&k5, KEY_ALL_EVENT, Key_Call_E, true);
|
||||
key_attach(&k6, KEY_ALL_EVENT, Key_Call_E, true);
|
||||
key_attach(&k7, KEY_ALL_EVENT, Key_Call_E, true);
|
||||
|
||||
key_start(&k1);
|
||||
key_start(&k2);
|
||||
key_start(&k3);
|
||||
key_start(&k4);
|
||||
key_start(&k5);
|
||||
key_start(&k6);
|
||||
key_start(&k7);
|
||||
while (1) {
|
||||
// 每5ms调用一次key_ticks函数
|
||||
key_ticks();
|
||||
|
|
|
@ -56,14 +56,15 @@ struct Key_List {
|
|||
void key_init(Key_t *key, uint8_t(*pin_level)(uint8_t), uint8_t active_level, uint8_t key_id);
|
||||
|
||||
/**
|
||||
* @brief 绑定按键事件回调函数
|
||||
* @param key: [输入] 指向按键结构体的指针
|
||||
* @brief 为按键设置回调函数
|
||||
* @param key: [输入] 按键结构体指针
|
||||
* @param event: [输入] 按键事件类型
|
||||
* @param cb: [输入] 按键事件回调函数
|
||||
* @param cb: [输入] 回调函数指针
|
||||
* @param start: [输入] 是否立即启用
|
||||
* @return void
|
||||
* @example key_attach(&my_key, PRESS_DOWN, key_press_callback);
|
||||
*/
|
||||
void key_attach(Key_t *key, PressEvent event, Key_Callback_t cb);
|
||||
* @example key_attach(&my_key, PRESS_EVENT_LONG_PRESS, key_callback_func, true);
|
||||
**/
|
||||
void key_attach(Key_t *key, PressEvent event, Key_Callback_t cb, bool start);
|
||||
|
||||
/**
|
||||
* @brief 获取按键当前事件
|
||||
|
|
|
@ -21,7 +21,7 @@ void key_init(Key_t *key, uint8_t(*pin_level)(uint8_t), uint8_t active_level, ui
|
|||
}
|
||||
|
||||
|
||||
void key_attach(Key_t *key, PressEvent event, Key_Callback_t cb) {
|
||||
void key_attach(Key_t *key, PressEvent event, Key_Callback_t cb, bool start) {
|
||||
// 如果事件类型为ALL_EVENT,则将回调函数cb分别赋值给所有事件类型
|
||||
if (event == KEY_ALL_EVENT) {
|
||||
for (uint8_t i = KEY_PRESS_UP; i < number_of_event; i++) {
|
||||
|
@ -31,6 +31,7 @@ void key_attach(Key_t *key, PressEvent event, Key_Callback_t cb) {
|
|||
// 否则,将回调函数cb赋值给指定的事件类型
|
||||
key->cb[event] = cb;
|
||||
}
|
||||
if (start)key_start(key);
|
||||
}
|
||||
|
||||
PressEvent get_key_event(Key_t *key) {
|
||||
|
|
Loading…
Reference in New Issue