firmware/src/input/UpDownInterruptBase.cpp

55 lines
1.5 KiB
C++
Raw Normal View History

#include "UpDownInterruptBase.h"
2023-01-21 13:34:29 +00:00
#include "configuration.h"
2023-01-21 13:34:29 +00:00
UpDownInterruptBase::UpDownInterruptBase(const char *name)
{
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)())
{
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);
}
void UpDownInterruptBase::intPressHandler()
{
InputEvent e;
e.source = this->_originName;
2022-12-30 02:41:37 +00:00
LOG_DEBUG("GPIO event Press\n");
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");
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");
e.inputEvent = this->_eventUp;
this->notifyObservers(&e);
}