2022-03-26 16:45:42 +00:00
|
|
|
#include "UpDownInterruptBase.h"
|
2023-01-21 13:34:29 +00:00
|
|
|
#include "configuration.h"
|
2022-03-26 16:45:42 +00:00
|
|
|
|
2023-01-21 13:34:29 +00:00
|
|
|
UpDownInterruptBase::UpDownInterruptBase(const char *name)
|
2022-03-26 16:45:42 +00:00
|
|
|
{
|
|
|
|
this->_originName = name;
|
|
|
|
}
|
|
|
|
|
2023-01-21 13:34:29 +00:00
|
|
|
void UpDownInterruptBase::init(uint8_t pinDown, uint8_t pinUp, uint8_t pinPress, char eventDown, char eventUp, char eventPressed,
|
|
|
|
void (*onIntDown)(), void (*onIntUp)(), void (*onIntPress)())
|
2022-03-26 16:45:42 +00:00
|
|
|
{
|
|
|
|
this->_pinDown = pinDown;
|
|
|
|
this->_pinUp = pinUp;
|
|
|
|
this->_eventDown = eventDown;
|
|
|
|
this->_eventUp = eventUp;
|
|
|
|
this->_eventPressed = eventPressed;
|
|
|
|
|
|
|
|
pinMode(pinPress, INPUT_PULLUP);
|
|
|
|
pinMode(this->_pinDown, INPUT_PULLUP);
|
|
|
|
pinMode(this->_pinUp, INPUT_PULLUP);
|
|
|
|
|
|
|
|
attachInterrupt(pinPress, onIntPress, RISING);
|
|
|
|
attachInterrupt(this->_pinDown, onIntDown, RISING);
|
|
|
|
attachInterrupt(this->_pinUp, onIntUp, RISING);
|
|
|
|
|
2023-01-21 13:34:29 +00:00
|
|
|
LOG_DEBUG("GPIO initialized (%d, %d, %d)\n", this->_pinDown, this->_pinUp, pinPress);
|
2022-03-26 16:45:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void UpDownInterruptBase::intPressHandler()
|
|
|
|
{
|
|
|
|
InputEvent e;
|
|
|
|
e.source = this->_originName;
|
2022-12-30 02:41:37 +00:00
|
|
|
LOG_DEBUG("GPIO event Press\n");
|
2022-03-26 16:45:42 +00:00
|
|
|
e.inputEvent = this->_eventPressed;
|
|
|
|
this->notifyObservers(&e);
|
|
|
|
}
|
|
|
|
|
|
|
|
void UpDownInterruptBase::intDownHandler()
|
|
|
|
{
|
|
|
|
InputEvent e;
|
|
|
|
e.source = this->_originName;
|
2022-12-30 02:41:37 +00:00
|
|
|
LOG_DEBUG("GPIO event Down\n");
|
2022-03-26 16:45:42 +00:00
|
|
|
e.inputEvent = this->_eventDown;
|
|
|
|
this->notifyObservers(&e);
|
|
|
|
}
|
|
|
|
|
|
|
|
void UpDownInterruptBase::intUpHandler()
|
|
|
|
{
|
|
|
|
InputEvent e;
|
|
|
|
e.source = this->_originName;
|
2022-12-30 02:41:37 +00:00
|
|
|
LOG_DEBUG("GPIO event Up\n");
|
2022-03-26 16:45:42 +00:00
|
|
|
e.inputEvent = this->_eventUp;
|
|
|
|
this->notifyObservers(&e);
|
|
|
|
}
|