Callback get state information
This commit is contained in:
parent
f90fa156db
commit
ed5c02f142
8
HIB.cpp
8
HIB.cpp
@ -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
8
HIB.h
@ -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();
|
||||||
|
Loading…
Reference in New Issue
Block a user