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,
|
||||
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),
|
||||
@ -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();
|
||||
}
|
||||
|
8
HIB.h
8
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:
|
||||
@ -25,8 +25,8 @@ public:
|
||||
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,
|
||||
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