1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
#include "multi_button.h"
#include "bsp_key.h"
#include "My_button.h"
enum Button_IDs
{
btn1_id,
btn2_id,
BUTTONS_NUM,
};
struct Button btn1;
struct Button btn2;
static uint8_t read_button_GPIO(uint8_t button_id)
{
switch (button_id)
{
case btn1_id:
return HAL_GPIO_ReadPin(Key1_GPIO_PORT, Key1_GPIO_PIN);
case btn2_id:
return HAL_GPIO_ReadPin(Key2_GPIO_PORT, Key2_GPIO_PIN);
default:
return 0;
}
}
static void Buttons_Callback(void *button)
{
PressEvent btn_event_val;
btn_event_val = get_button_event((struct Button *)button);
// FAN_DW 按键 触发事件处理
if ((struct Button *)button == &btn1)
{
if (btn_event_val == SINGLE_CLICK)
{
}
}
// UV_KEY 按键 触发事件
else if ((struct Button *)button == &btn2)
{
if (btn_event_val == SINGLE_CLICK)
{
}
}
}
void My_button_init_attach_start(void)
{
button_init(&btn1, read_button_GPIO, 0, btn1_id);
button_init(&btn2, read_button_GPIO, 0, btn2_id);
button_attach(&btn1, SINGLE_CLICK, Buttons_Callback);
button_attach(&btn1, LONG_PRESS_HOLD, Buttons_Callback);
button_attach(&btn2, SINGLE_CLICK, Buttons_Callback);
button_attach(&btn2, LONG_PRESS_HOLD, Buttons_Callback);
button_start(&btn1);
button_start(&btn2);
}
|