Callback get state information
This commit is contained in:
parent
f90fa156db
commit
ed5c02f142
10
HIB.cpp
10
HIB.cpp
@ -49,11 +49,11 @@ void __timerCallback(void *data) {
|
||||
|
||||
|
||||
HIB::HIB(uint8_t p, uint8_t initState,
|
||||
void (* userOnButtonPressed)(uint8_t pin),
|
||||
void (* userOnButtonReleased)(uint8_t pin),
|
||||
void (* userOnButtonPressed)(uint8_t pin, int state),
|
||||
void (* userOnButtonReleased)(uint8_t pin, int state),
|
||||
void (* userOnLongButtonPressed)(uint8_t pin),
|
||||
unsigned long longPress, unsigned long shortPress):
|
||||
previousMillis(0),
|
||||
previousMillis(0),
|
||||
longPressMsec(longPress),
|
||||
shortPressMsec(shortPress),
|
||||
onButtonPressed(userOnButtonPressed),
|
||||
@ -78,7 +78,7 @@ void HIB::IRQ_handler(){
|
||||
void HIB::onInternalButtonPressed(){
|
||||
previousMillis = millis();
|
||||
if(onButtonPressed)
|
||||
onButtonPressed(pin);
|
||||
onButtonPressed(pin, state);
|
||||
}
|
||||
|
||||
void HIB::onInternalLongButtonPressed(){
|
||||
@ -88,7 +88,7 @@ void HIB::onInternalLongButtonPressed(){
|
||||
|
||||
void HIB::onInternalButtonReleased(){
|
||||
if(onButtonReleased)
|
||||
onButtonReleased(pin);
|
||||
onButtonReleased(pin, state);
|
||||
if(millis() - previousMillis >= longPressMsec){
|
||||
onInternalLongButtonPressed();
|
||||
}
|
||||
|
10
HIB.h
10
HIB.h
@ -15,8 +15,8 @@ private:
|
||||
void onInternalButtonReleased();
|
||||
void onInternalLongButtonPressed();
|
||||
void invertState();
|
||||
void (* onButtonPressed)(uint8_t pin);
|
||||
void (* onButtonReleased)(uint8_t pin);
|
||||
void (* onButtonPressed)(uint8_t pin, int state);
|
||||
void (* onButtonReleased)(uint8_t pin, int state);
|
||||
void (* onLongButtonPressed)(uint8_t pin);
|
||||
friend void __timerCallback(void *data);
|
||||
public:
|
||||
@ -24,9 +24,9 @@ public:
|
||||
uint8_t initialState;
|
||||
uint8_t state;
|
||||
uint8_t debouncing;
|
||||
HIB(uint8_t pin, uint8_t initialState,
|
||||
void (* onButtonPressed)(uint8_t pin) = NULL,
|
||||
void (* onButtonReleased)(uint8_t pin) = NULL,
|
||||
HIB(uint8_t pin, uint8_t initialState,
|
||||
void (* onButtonPressed)(uint8_t pin, int state) = NULL,
|
||||
void (* onButtonReleased)(uint8_t pin, int state) = NULL,
|
||||
void (* onLongButtonPressed)(uint8_t pin) = NULL,
|
||||
unsigned long longPressMsec = 5000, unsigned long shortPressMsec = 50);
|
||||
void IRQ_handler();
|
||||
|
Loading…
Reference in New Issue
Block a user