pull/8/head
Jaup 9 years ago
parent ff524281b8
commit 2f107d7c63

@ -16,7 +16,7 @@ int read_button_pin()
int main()
{
button_init(&button1, read_K1_pin, 0);
button_init(&button1, read_button_pin, 0);
button_attach(&button1, SINGLE_CLICK, BTN1_SINGLE_CLICK_Handler);
button_attach(&button1, DOUBLE_CLICK, BTN1_DOUBLE_Click_Handler);
button_attach(&button1, LONG_RRESS_START, BTN1_LONG_RRESS_START_Handler);

@ -82,6 +82,8 @@ void button_handler(struct Button* handle)
switch (handle->state) {
case 0:
if(handle->button_level == handle->active_level) { //start press
if(handle->cb[CLICK]) handle->cb[CLICK]();
handle->ticks = 0;
handle->state = 1;
}
@ -101,11 +103,12 @@ void button_handler(struct Button* handle)
case 2:
if(handle->ticks > kClickTicks) { //released
//press event
if(handle->cb[SINGLE_CLICK]) handle->cb[SINGLE_CLICK](); //signal click
if(handle->cb[PRESSED]) handle->cb[PRESSED](); //press event
handle->state = 0; //reset
} else if(handle->button_level == handle->active_level) { //press again
if(handle->cb[CLICK]) handle->cb[CLICK]();
handle->state = 3;
}
break;

@ -7,7 +7,8 @@
typedef void (*CallBackFunc)(void);
typedef enum {
SINGLE_CLICK = 0,
CLICK = 0,
PRESSED,
DOUBLE_CLICK,
LONG_RRESS_START,
LONG_PRESS_HOLD,

Loading…
Cancel
Save