Commit ed5c02f1 authored by Mathieu Maret's avatar Mathieu Maret

Callback get state information

parent f90fa156
......@@ -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();
}
......
......@@ -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();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment