Callback get state information

This commit is contained in:
Mathieu Maret 2016-12-07 21:36:29 +01:00
parent f90fa156db
commit ed5c02f142
2 changed files with 10 additions and 10 deletions

View File

@ -49,8 +49,8 @@ void __timerCallback(void *data) {
HIB::HIB(uint8_t p, uint8_t initState, HIB::HIB(uint8_t p, uint8_t initState,
void (* userOnButtonPressed)(uint8_t pin), void (* userOnButtonPressed)(uint8_t pin, int state),
void (* userOnButtonReleased)(uint8_t pin), void (* userOnButtonReleased)(uint8_t pin, int state),
void (* userOnLongButtonPressed)(uint8_t pin), void (* userOnLongButtonPressed)(uint8_t pin),
unsigned long longPress, unsigned long shortPress): unsigned long longPress, unsigned long shortPress):
previousMillis(0), previousMillis(0),
@ -78,7 +78,7 @@ void HIB::IRQ_handler(){
void HIB::onInternalButtonPressed(){ void HIB::onInternalButtonPressed(){
previousMillis = millis(); previousMillis = millis();
if(onButtonPressed) if(onButtonPressed)
onButtonPressed(pin); onButtonPressed(pin, state);
} }
void HIB::onInternalLongButtonPressed(){ void HIB::onInternalLongButtonPressed(){
@ -88,7 +88,7 @@ void HIB::onInternalLongButtonPressed(){
void HIB::onInternalButtonReleased(){ void HIB::onInternalButtonReleased(){
if(onButtonReleased) if(onButtonReleased)
onButtonReleased(pin); onButtonReleased(pin, state);
if(millis() - previousMillis >= longPressMsec){ if(millis() - previousMillis >= longPressMsec){
onInternalLongButtonPressed(); onInternalLongButtonPressed();
} }

8
HIB.h
View File

@ -15,8 +15,8 @@ private:
void onInternalButtonReleased(); void onInternalButtonReleased();
void onInternalLongButtonPressed(); void onInternalLongButtonPressed();
void invertState(); void invertState();
void (* onButtonPressed)(uint8_t pin); void (* onButtonPressed)(uint8_t pin, int state);
void (* onButtonReleased)(uint8_t pin); void (* onButtonReleased)(uint8_t pin, int state);
void (* onLongButtonPressed)(uint8_t pin); void (* onLongButtonPressed)(uint8_t pin);
friend void __timerCallback(void *data); friend void __timerCallback(void *data);
public: public:
@ -25,8 +25,8 @@ public:
uint8_t state; uint8_t state;
uint8_t debouncing; uint8_t debouncing;
HIB(uint8_t pin, uint8_t initialState, HIB(uint8_t pin, uint8_t initialState,
void (* onButtonPressed)(uint8_t pin) = NULL, void (* onButtonPressed)(uint8_t pin, int state) = NULL,
void (* onButtonReleased)(uint8_t pin) = NULL, void (* onButtonReleased)(uint8_t pin, int state) = NULL,
void (* onLongButtonPressed)(uint8_t pin) = NULL, void (* onLongButtonPressed)(uint8_t pin) = NULL,
unsigned long longPressMsec = 5000, unsigned long shortPressMsec = 50); unsigned long longPressMsec = 5000, unsigned long shortPressMsec = 50);
void IRQ_handler(); void IRQ_handler();