Browse Source

修复连击17次或18次后释放按钮,会异常触发SINGLE_CLICK或DOUBLE_CLICK事件的问题

1,连击n次(n >= 3)后释放都应该看作PRESS_REPEAT事件,不可触发SINGLE_CLICK或DOUBLE_CLICK事件。
2,连击时限制repeat的最大值为(2^4 - 1)防止溢出。
Riggin 2 years ago
parent
commit
5d00b96a85
1 changed files with 5 additions and 1 deletions
  1. 5 1
      multi_button.c

+ 5 - 1
multi_button.c

@@ -19,6 +19,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 */
 
 static struct button* head_handle = NULL;
 
@@ -131,7 +132,10 @@ static void button_handler(struct button* handle)
         {
             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);
             handle->ticks = 0;
             handle->state = 3;