From 0230c291b4a9af8589a74b79c2bd31946a2ccd0b Mon Sep 17 00:00:00 2001 From: Jaup <270995079@qq.com> Date: Tue, 30 Aug 2016 10:00:04 +0000 Subject: [PATCH] v0.50 --- README.md | 4 ---- button.c | 17 ++++++++++++++++- button.h | 1 + 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 52a425f..489080a 100644 --- a/README.md +++ b/README.md @@ -27,10 +27,6 @@ int main() //make the timer repeat invoking the button_ticks() interval 5ms. __timer_start(button_ticks, 0, 5); - while(ture) - { - ... - } } void BTN1_SINGLE_CLICK_Handler() diff --git a/button.c b/button.c index a6c44da..58911d8 100644 --- a/button.c +++ b/button.c @@ -1,3 +1,8 @@ +/* + * Copyright (c) 2016 Zibin Zheng + * All rights reserved + */ + #include "button.h" //MultiButton @@ -7,7 +12,7 @@ #define TICKS_INTERVAL 5 //ms //According to your need to modify the constants. -const uint8_t kDebounceTicks = 3; //MAX 3 +const uint8_t kDebounceTicks = 3; //MAX 8 const uint16_t kClickTicks = (400/TICKS_INTERVAL); const uint16_t kLongTicks = (1000/TICKS_INTERVAL); @@ -41,6 +46,16 @@ void button_attach(struct Button* handle, BtnEvent event, CallBackFunc cb) handle->cb[event] = cb; } +/** + * @brief Inquire the button is pressed. + * @param handle: the button handle strcut. + * @retval 0 not press, 1 pressed. + */ +int button_is_pressed(struct Button* handle) +{ + return ((handle->button_level == handle->active_level) ? 1:0); +} + /** * @brief Button driver core function, driver state machine. * @param handle: the button handle strcut. diff --git a/button.h b/button.h index 332faa6..2193176 100644 --- a/button.h +++ b/button.h @@ -33,6 +33,7 @@ extern "C" { void button_init(struct Button* handle, uint8_t(*pin_level)(), uint8_t active_level); void button_attach(struct Button* handle, BtnEvent event, CallBackFunc cb); +int button_is_pressed(struct Button* handle); int button_start(struct Button* btn); void button_stop(struct Button* btn); void button_ticks(void);