Skip to content

Commit 67b5eac

Browse files
updated README.md
1 parent be69415 commit 67b5eac

1 file changed

Lines changed: 21 additions & 22 deletions

File tree

README.md

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
# ESP-IDF Button Component
33

44
## Features
5-
- Each button can have three different callback functions depending on the time the button is pressed (short, medium and long)
5+
- Each button can have up to four different callback functions depending on the way the button is pressed (single, medium, long and double).
66
- Debounce algorithm is based on FSM (Finite State Machine), FreeRTOS software timers, FreeRTOS event groups and GPIO interrupts.
7-
- Multiple instances
7+
- Multiple instances.
88

99
## How to use
1010
To use this component follow the next steps:
@@ -28,39 +28,38 @@ button_t button2;
2828
4. Define button callback functions
2929
```c
3030
/* Callback function to handle press of button 1 without argument*/
31-
void button1_cb(void * arg) {
32-
printf("Button 1 short press");
31+
void button1_cb(void *arg) {
32+
printf("Button 1 single click");
3333
}
3434

3535
/* Callback function to handle press of button 2 with argument*/
36-
void button2_cb(void * arg) {
37-
char * string = (char *)arg;
38-
printf("%s\n", string);
36+
void button2_cb(void *arg) {
37+
printf("%s\n", (char *)arg);
3938
}
4039
```
4140
4241
5. Initialize the component instances
4342
```c
4443
/* Initialize button instances */
45-
ESP_ERROR_CHECK(button_init(&button1, /* button 1 instance */
46-
GPIO_NUM_0, /* GPIO number */
47-
tskIDLE_PRIORITY + 10, /* button FreeRTOS task priority */
48-
configMINIMAL_STACK_SIZE * 4)); /* button FreeRTOS task stack size */
49-
50-
ESP_ERROR_CHECK(button_init(&button2, /* button 2 instance */
51-
GPIO_NUM_21, /* GPIO number */
52-
tskIDLE_PRIORITY + 11, /* button FreeRTOS task priority */
53-
configMINIMAL_STACK_SIZE * 4)); /* button FreeRTOS task stack size */
44+
ESP_ERROR_CHECK(button_init(&button1, /* Button instance */
45+
GPIO_NUM_0, /* Button GPIO number */
46+
tskIDLE_PRIORITY + 10, /* Button FreeRTOS task priority */
47+
configMINIMAL_STACK_SIZE * 4)); /* Button FreeRTOS task stack size */
48+
49+
ESP_ERROR_CHECK(button_init(&button2, /* Button instance */
50+
GPIO_NUM_21, /* Button GPIO number */
51+
tskIDLE_PRIORITY + 11, /* Button FreeRTOS task priority */
52+
configMINIMAL_STACK_SIZE * 4)); /* Button FreeRTOS task stack size */
5453
```
5554

56-
6. Register the callback functions defined in 3
55+
6. Add the callback functions defined in 3
5756
```c
58-
/* Register button1 callback for short press without argument */
59-
button_register_cb(&button1, SHORT_TIME, button1_cb, NULL);
57+
/* Register button1 callback for single click without argument */
58+
button_add_cb(&button1, BUTTON_CLICK_SINGLE, button1_cb, NULL);
6059

61-
/* Register button2 callbacks for medium and long press with different arguments */
62-
button_register_cb(&button2, MEDIUM_TIME, button2_cb, "Button 2 medium press");
63-
button_register_cb(&button2, LONG_TIME, button2_cb, "Button 2 long press");
60+
/* Register button2 callbacks for medium and double click with different arguments */
61+
button_add_cb(&button2, BUTTON_CLICK_MEDIUM, button2_cb, "Button 2 medium click");
62+
button_add_cb(&button2, BUTTON_CLICK_DOUBLE, button2_cb, "Button 2 double click");
6463
```
6564
6665
## License

0 commit comments

Comments
 (0)