From b5e193f55d038999fd1bbf95c4891bff5bb0ce98 Mon Sep 17 00:00:00 2001 From: Riggin Date: Wed, 16 Aug 2023 18:59:33 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=BF=9E=E5=87=BB17=E6=AC=A1?= =?UTF-8?q?=E6=88=9618=E6=AC=A1=E5=90=8E=E9=87=8A=E6=94=BE=E6=8C=89?= =?UTF-8?q?=E9=92=AE=EF=BC=8C=E4=BC=9A=E5=BC=82=E5=B8=B8=E8=A7=A6=E5=8F=91?= =?UTF-8?q?SINGLE=5FCLICK=E6=88=96DOUBLE=5FCLICK=E4=BA=8B=E4=BB=B6?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1,连击n次(n >= 3)后释放都应该看作PRESS_REPEAT事件,不可触发SINGLE_CLICK或DOUBLE_CLICK事件。 2,连击时限制repeat的最大值为(2^4 - 1)防止溢出。 --- multi_button.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/multi_button.c b/multi_button.c index bf4037d..ca366f7 100644 --- a/multi_button.c +++ b/multi_button.c @@ -6,6 +6,7 @@ #include "multi_button.h" #define EVENT_CB(ev) if(handle->cb[ev])handle->cb[ev]((void*)handle) +#define PRESS_REPEAT_MAX_NUM 15 /*!< The maximum value of the repeat counter */ //button handle list head. static struct Button* head_handle = NULL; @@ -106,7 +107,9 @@ static void button_handler(struct Button* handle) if(handle->button_level == handle->active_level) { //press down again handle->event = (uint8_t)PRESS_DOWN; EVENT_CB(PRESS_DOWN); - handle->repeat++; + if(handle->repeat != PRESS_REPEAT_MAX_NUM) { + handle->repeat++; + } EVENT_CB(PRESS_REPEAT); // repeat hit handle->ticks = 0; handle->state = 3;