|
|
|
@ -5,7 +5,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
#include "multi_button.h"
|
|
|
|
#include "multi_button.h"
|
|
|
|
|
|
|
|
|
|
|
|
#define EVENT_CB(ev) if(handle->cb[ev])handle->cb[ev]((Button*)handle)
|
|
|
|
#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.
|
|
|
|
//button handle list head.
|
|
|
|
static struct Button* head_handle = NULL;
|
|
|
|
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
|
|
|
|
if(handle->button_level == handle->active_level) { //press down again
|
|
|
|
handle->event = (uint8_t)PRESS_DOWN;
|
|
|
|
handle->event = (uint8_t)PRESS_DOWN;
|
|
|
|
EVENT_CB(PRESS_DOWN);
|
|
|
|
EVENT_CB(PRESS_DOWN);
|
|
|
|
|
|
|
|
if(handle->repeat != PRESS_REPEAT_MAX_NUM) {
|
|
|
|
handle->repeat++;
|
|
|
|
handle->repeat++;
|
|
|
|
|
|
|
|
}
|
|
|
|
EVENT_CB(PRESS_REPEAT); // repeat hit
|
|
|
|
EVENT_CB(PRESS_REPEAT); // repeat hit
|
|
|
|
handle->ticks = 0;
|
|
|
|
handle->ticks = 0;
|
|
|
|
handle->state = 3;
|
|
|
|
handle->state = 3;
|
|
|
|
@ -132,8 +135,8 @@ static void button_handler(struct Button* handle)
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
handle->state = 0;
|
|
|
|
handle->state = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if(handle->ticks > SHORT_TICKS) { // long press up
|
|
|
|
} else if(handle->ticks > SHORT_TICKS) { // SHORT_TICKS < press down hold time < LONG_TICKS
|
|
|
|
handle->state = 0;
|
|
|
|
handle->state = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
@ -142,7 +145,7 @@ static void button_handler(struct Button* handle)
|
|
|
|
//continue hold trigger
|
|
|
|
//continue hold trigger
|
|
|
|
handle->event = (uint8_t)LONG_PRESS_HOLD;
|
|
|
|
handle->event = (uint8_t)LONG_PRESS_HOLD;
|
|
|
|
EVENT_CB(LONG_PRESS_HOLD);
|
|
|
|
EVENT_CB(LONG_PRESS_HOLD);
|
|
|
|
} else { //releasd
|
|
|
|
} else { //released
|
|
|
|
handle->event = (uint8_t)PRESS_UP;
|
|
|
|
handle->event = (uint8_t)PRESS_UP;
|
|
|
|
EVENT_CB(PRESS_UP);
|
|
|
|
EVENT_CB(PRESS_UP);
|
|
|
|
handle->state = 0; //reset
|
|
|
|
handle->state = 0; //reset
|
|
|
|
|