From cf3a197ecd5fb4fa8d9dd31d143c828121e06736 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Sun, 20 Aug 2023 19:13:22 -0400 Subject: [PATCH 1/4] multi_button.c: add the default keyword for the switch case https://github.com/0x1abin/MultiButton/commit/98d1643e5b919d267a2b40955a309be410bef2c6 --- multi_button.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/multi_button.c b/multi_button.c index 411f016..6988e4f 100644 --- a/multi_button.c +++ b/multi_button.c @@ -192,6 +192,10 @@ void button_handler(struct button* handle) handle->state = 0; } break; + + default: + handle->state = 0; /* reset */ + break; } } From 8a74076d1c3df0fded631bf91065a391ada7772a Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Sun, 20 Aug 2023 19:21:21 -0400 Subject: [PATCH 2/4] =?UTF-8?q?=E5=B0=86button=5Fhandler=E5=87=BD=E6=95=B0?= =?UTF-8?q?=E8=AE=BE=E4=B8=BA=E5=86=85=E9=83=A8=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit from: https://github.com/0x1abin/MultiButton/pull/38/commits/41514fed4b99263f0e41efce658934d6c4a27062 --- multi_button.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/multi_button.c b/multi_button.c index 6988e4f..e9aed5c 100644 --- a/multi_button.c +++ b/multi_button.c @@ -65,7 +65,7 @@ PressEvent get_button_event(struct button* handle) * @param handle: the button handle strcut. * @retval None */ -void button_handler(struct button* handle) +static void button_handler(struct button* handle) { uint8_t read_gpio_level = handle->hal_button_Level(); From 69fd2d759729f4bcf3f18505e2785e55bfee4725 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Sun, 20 Aug 2023 19:24:37 -0400 Subject: [PATCH 3/4] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E6=8B=BC=E5=86=99?= =?UTF-8?q?=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit from: https://github.com/0x1abin/MultiButton/commit/3ec5425cdf7556dd80420cca24ad5656d62f81db https://github.com/0x1abin/MultiButton/commit/3e5fb48a6b775bcff750433f7a9e1291d5965422 --- README.md | 7 ++----- multi_button.c | 16 ++++++++-------- multi_button.h | 6 +++--- 3 files changed, 13 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 761b4f0..44ea367 100644 --- a/README.md +++ b/README.md @@ -105,7 +105,7 @@ int main() button_attach(&btn1, SINGLE_CLICK, BTN1_SINGLE_Click_Handler); button_attach(&btn1, DOUBLE_CLICK, BTN1_DOUBLE_Click_Handler); button_attach(&btn1, LONG_PRESS_START, BTN1_LONG_PRESS_START_Handler); - button_attach(&btn2, LONG_PRESS_HOLD, BTN1_LONG_PRESS_HOLD_Handler); + button_attach(&btn1, LONG_PRESS_HOLD, BTN1_LONG_PRESS_HOLD_Handler); button_start(&btn1); //make the timer invoking the button_ticks() interval 5ms. @@ -116,11 +116,8 @@ int main() {} } -... ``` - - ## 状态图 -![states.png](states.png) \ No newline at end of file +![states.png](states.png) diff --git a/multi_button.c b/multi_button.c index e9aed5c..9039028 100644 --- a/multi_button.c +++ b/multi_button.c @@ -24,8 +24,8 @@ static struct button* head_handle = NULL; /** * @brief Initializes the button struct handle. - * @param handle: the button handle strcut. - * @param pin_level: read the pin of the connet button level. + * @param handle: the button handle struct. + * @param pin_level: read the pin of the connected button level. * @param active_level: pin pressed level. * @retval None */ @@ -40,7 +40,7 @@ void button_init(struct button* handle, uint8_t(*pin_level)(void), uint8_t activ /** * @brief Attach the button event callback function. - * @param handle: the button handle strcut. + * @param handle: the button handle struct. * @param event: trigger event type. * @param cb: callback function. * @retval None @@ -52,7 +52,7 @@ void button_attach(struct button* handle, PressEvent event, BtnCallback cb) /** * @brief Inquire the button event happen. - * @param handle: the button handle strcut. + * @param handle: the button handle struct. * @retval button event. */ PressEvent get_button_event(struct button* handle) @@ -62,7 +62,7 @@ PressEvent get_button_event(struct button* handle) /** * @brief button driver core function, driver state machine. - * @param handle: the button handle strcut. + * @param handle: the button handle struct. * @retval None */ static void button_handler(struct button* handle) @@ -88,7 +88,7 @@ static void button_handler(struct button* handle) } else { - // leved not change ,counter reset. + // level not change ,counter reset. handle->debounce_cnt = 0; } @@ -201,7 +201,7 @@ static void button_handler(struct button* handle) /** * @brief Start the button work, add the handle into work list. - * @param handle: target handle strcut. + * @param handle: target handle struct. * @retval 0: succeed. -1: already exist. */ int button_start(struct button* handle) @@ -226,7 +226,7 @@ int button_start(struct button* handle) /** * @brief Stop the button work, remove the handle off work list. - * @param handle: target handle strcut. + * @param handle: target handle struct. * @retval None */ void button_stop(struct button* handle) diff --git a/multi_button.h b/multi_button.h index e4248b8..02aa33d 100644 --- a/multi_button.h +++ b/multi_button.h @@ -1,12 +1,12 @@ #ifndef __MULTI_BUTTON_H_ #define __MULTI_BUTTON_H_ -#include "stdint.h" -#include "string.h" +#include +#include //According to your need to modify the constants. #define TICKS_INTERVAL 5 //ms -#define DEBOUNCE_TICKS 3 //MAX 8 +#define DEBOUNCE_TICKS 3 //MAX 7 (0 ~ 7) #define SHORT_TICKS (300 / TICKS_INTERVAL) #define LONG_TICKS (1000 / TICKS_INTERVAL) #define LONG_HOLD_CYC (500 / TICKS_INTERVAL) From 235c9e602d34fb5db6a68faa047102741cb08d3b Mon Sep 17 00:00:00 2001 From: jaffer Date: Tue, 28 Feb 2023 21:55:50 +0800 Subject: [PATCH 4/4] =?UTF-8?q?[fix]=E4=BF=AE=E5=A4=8D=E7=9F=AD=E6=8C=89->?= =?UTF-8?q?=E9=95=BF=E6=8C=89=E6=8C=89=E9=94=AE=E8=AF=AF=E8=A7=A6=E5=8F=91?= =?UTF-8?q?=E6=8C=89=E4=B8=8B=E4=BA=8B=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: jaffer 涉及到PR/Issues: https://github.com/0x1abin/MultiButton/pull/39 https://github.com/0x1abin/MultiButton/pull/36 https://github.com/0x1abin/MultiButton/issues/24 Signed-off-by: Meco Man <920369182@qq.com> --- multi_button.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/multi_button.c b/multi_button.c index 9039028..9d47afd 100644 --- a/multi_button.c +++ b/multi_button.c @@ -169,9 +169,9 @@ static void button_handler(struct button* handle) handle->state = 0; } } - else if(handle->ticks > SHORT_TICKS) + else if(handle->ticks > SHORT_TICKS) // SHORT_TICKS < press down hold time < LONG_TICKS { - handle->state = 0; + handle->state = 1; } break;