疑似是消抖引起的问题,长按按键后,handle->button_level 执行了
handle->button_level = read_gpio_level;
handle->debounce_cnt = 0;
button_level 变成了触发的状态,会连续触发 DEBOUNCE_TICKS 次的长按调用的回调函数。
这边在下面加入了
case BTN_STATE_LONG_HOLD:
if (handle->button_level == handle->active_level) {
// Continue holding
handle->event = (uint8_t)BTN_LONG_PRESS_HOLD;
handle->button_level = !handle->active_level; // 会多次触发,原因不明
EVENT_CB(BTN_LONG_PRESS_HOLD);
不确定多次触发是特地设计成这样的还是什么原因。
疑似是消抖引起的问题,长按按键后,handle->button_level 执行了
handle->button_level = read_gpio_level;
handle->debounce_cnt = 0;
button_level 变成了触发的状态,会连续触发 DEBOUNCE_TICKS 次的长按调用的回调函数。
这边在下面加入了
case BTN_STATE_LONG_HOLD:
if (handle->button_level == handle->active_level) {
// Continue holding
handle->event = (uint8_t)BTN_LONG_PRESS_HOLD;
handle->button_level = !handle->active_level; // 会多次触发,原因不明
EVENT_CB(BTN_LONG_PRESS_HOLD);
不确定多次触发是特地设计成这样的还是什么原因。