You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
928 B
Markdown
44 lines
928 B
Markdown
# MultiButton
|
|
Embedded event-driven button driver.
|
|
|
|
|
|
## Examples
|
|
|
|
```
|
|
#include "button.h"
|
|
|
|
struct Button button1;
|
|
|
|
int read_button_pin()
|
|
{
|
|
return HAL_GPIO_ReadPin(B1_GPIO_Port, B1_Pin); //HAL GPIO read.
|
|
}
|
|
|
|
int main()
|
|
{
|
|
button_init(&button1, read_button_pin, 0);
|
|
button_attach(&button1, SINGLE_CLICK, BTN1_SINGLE_CLICK_Handler);
|
|
button_attach(&button1, DOUBLE_CLICK, BTN1_DOUBLE_Click_Handler);
|
|
button_attach(&button1, LONG_RRESS_START, BTN1_LONG_RRESS_START_Handler);
|
|
button_attach(&button1, LONG_PRESS_HOLD, BTN1_LONG_PRESS_HOLD_Handler);
|
|
button_attach(&button1, LONG_PRESS_STOP, BTN1_LONG_PRESS_STOP_Handler);
|
|
button_start(&button1);
|
|
|
|
//make the timer repeat invoking the button_ticks() interval 5ms.
|
|
__timer_start(button_ticks, 0, 5);
|
|
|
|
}
|
|
|
|
void BTN1_SINGLE_CLICK_Handler()
|
|
{
|
|
//do something..
|
|
}
|
|
|
|
void BTN1_DOUBLE_Click_Handler()
|
|
{
|
|
//do something..
|
|
}
|
|
...
|
|
```
|
|
|