Multi-Click event lost when the latest press/release time didn't fit into the time window.
/*
* Simulate click event
*/
static const btn_test_time_t test_sequence[] = {
BTN_STATE(1, LWBTN_CFG_TIME_DEBOUNCE_PRESS + LWBTN_CFG_TIME_CLICK_MIN),
BTN_STATE(0, LWBTN_CFG_TIME_DEBOUNCE_RELEASE + LWBTN_CFG_TIME_CLICK_MAX),
BTN_STATE(1, LWBTN_CFG_TIME_DEBOUNCE_PRESS + LWBTN_CFG_TIME_CLICK_MIN / 2),
BTN_STATE(0, LWBTN_CFG_TIME_DEBOUNCE_RELEASE + LWBTN_CFG_TIME_CLICK_MULTI_MAX + 1),
BTN_STATE(0, 100)
};
/* List of expected test events during different input states and their timings */
static const btn_test_evt_t test_events[] = {
BTN_EVENT_ONPRESS(),
BTN_EVENT_ONRELEASE(),
BTN_EVENT_ONPRESS(),
BTN_EVENT_ONRELEASE(),
};
#define LWBTN_CFG_TIME_CLICK_MIN 20
#define LWBTN_CFG_TIME_CLICK_MAX 300
#define LWBTN_CFG_TIME_CLICK_MULTI_MAX 400
#define LWBTN_CFG_CLICK_MAX_CONSECUTIVE 3
#define LWBTN_CFG_CLICK_MAX_CONSECUTIVE_SEND_IMMEDIATELY 1
Test running
[ 20][ 20] evt: ONPRESS, keep-alive cnt: 0, click cnt: 0
[ 42][ 22] evt: ONRELEASE, keep-alive cnt: 0, click cnt: 0
[ 361][ 319] evt: ONPRESS, keep-alive cnt: 0, click cnt: 1
[ 372][ 11] evt: ONRELEASE, keep-alive cnt: 0, click cnt: 1
No ONCLICK event is reported. Notice that the lasting time of active state in second click is LWBTN_CFG_TIME_CLICK_MIN / 2, which is smaller than LWBTN_CFG_TIME_CLICK_MIN .
/* Check time validity for click event */
if ((mstime - btn->time_change) >= LWBTN_TIME_CLICK_GET_PRESSED_MIN(btn)
&& (mstime - btn->time_change) <= LWBTN_TIME_CLICK_GET_PRESSED_MAX(btn)) {
/* ... ... */
} else {
/*
* There was an on-release event, but timing
* for click event detection is outside allowed window.
*
* Reset clicks counter -> not valid sequence for click event.
*/
btn->click.cnt = 0; /* click.cnt is cleared here so no On-Click event will be triggered in our test case. */
}