forked from SZV10X_Software/SZV103_FM33A0xxEV_SiZhu

jinlicong
2024-06-07 fa6053f85287163f6e2d5dba690bec05cbc95f4a
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
#include "multi_button.h"
 
struct Button btn1;
 
uint8_t read_button1_GPIO() 
{
    return HAL_GPIO_ReadPin(B1_GPIO_Port, B1_Pin);
}
 
 
int main()
{
    static uint8_t btn1_event_val;
    
    button_init(&btn1, read_button1_GPIO, 0);
    button_start(&btn1);
    
    //make the timer invoking the button_ticks() interval 5ms.
    //This function is implemented by yourself.
    __timer_start(button_ticks, 0, 5); 
    
    while(1) 
    {
        if(btn1_event_val != get_button_event(&btn1)) 
        {
            btn1_event_val = get_button_event(&btn1);
            
            if(btn1_event_val == PRESS_DOWN) {
                //do something
            } else if(btn1_event_val == PRESS_UP) {
                //do something
            } else if(btn1_event_val == LONG_PRESS_HOLD) {
                //do something
            }
        }
    }
}