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

1,连击n次(n >= 3)后释放都应该看作PRESS_REPEAT事件,不可触发SINGLE_CLICK或DOUBLE_CLICK事件。
2,连击时限制repeat的最大值为(2^4 - 1)防止溢出。
pull/39/head
Riggin 2 years ago
parent 2e68340382
commit b5e193f55d

@ -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;

Loading…
Cancel
Save