From 2f107d7c63985f596dde52da559ef6135201a58c Mon Sep 17 00:00:00 2001 From: Jaup <270995079@qq.com> Date: Fri, 2 Sep 2016 02:25:44 +0000 Subject: [PATCH] update --- README.md | 2 +- button.c | 5 ++++- button.h | 3 ++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index ccc102b..68e7250 100644 --- a/README.md +++ b/README.md @@ -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); diff --git a/button.c b/button.c index c25b585..4b16e31 100644 --- a/button.c +++ b/button.c @@ -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; diff --git a/button.h b/button.h index 317b9c6..8e0903b 100644 --- a/button.h +++ b/button.h @@ -7,7 +7,8 @@ typedef void (*CallBackFunc)(void); typedef enum { - SINGLE_CLICK = 0, + CLICK = 0, + PRESSED, DOUBLE_CLICK, LONG_RRESS_START, LONG_PRESS_HOLD,