pull/8/head
Jaup 9 years ago
parent e7fd5bc6cb
commit 0230c291b4

@ -27,10 +27,6 @@ int main()
//make the timer repeat invoking the button_ticks() interval 5ms. //make the timer repeat invoking the button_ticks() interval 5ms.
__timer_start(button_ticks, 0, 5); __timer_start(button_ticks, 0, 5);
while(ture)
{
...
}
} }
void BTN1_SINGLE_CLICK_Handler() void BTN1_SINGLE_CLICK_Handler()

@ -1,3 +1,8 @@
/*
* Copyright (c) 2016 Zibin Zheng <znbin@qq.com>
* All rights reserved
*/
#include "button.h" #include "button.h"
//MultiButton //MultiButton
@ -7,7 +12,7 @@
#define TICKS_INTERVAL 5 //ms #define TICKS_INTERVAL 5 //ms
//According to your need to modify the constants. //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 kClickTicks = (400/TICKS_INTERVAL);
const uint16_t kLongTicks = (1000/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; 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. * @brief Button driver core function, driver state machine.
* @param handle: the button handle strcut. * @param handle: the button handle strcut.

@ -33,6 +33,7 @@ extern "C" {
void button_init(struct Button* handle, uint8_t(*pin_level)(), uint8_t active_level); void button_init(struct Button* handle, uint8_t(*pin_level)(), uint8_t active_level);
void button_attach(struct Button* handle, BtnEvent event, CallBackFunc cb); void button_attach(struct Button* handle, BtnEvent event, CallBackFunc cb);
int button_is_pressed(struct Button* handle);
int button_start(struct Button* btn); int button_start(struct Button* btn);
void button_stop(struct Button* btn); void button_stop(struct Button* btn);
void button_ticks(void); void button_ticks(void);

Loading…
Cancel
Save