pull/3600/head^2
Manuel 2024-04-14 15:11:22 +02:00 zatwierdzone przez GitHub
rodzic 0a246bfe9b
commit ec3971bce5
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: B5690EEEBB952194
2 zmienionych plików z 41 dodań i 17 usunięć

Wyświetl plik

@ -1,7 +1,7 @@
#include "UpDownInterruptBase.h"
#include "configuration.h"
UpDownInterruptBase::UpDownInterruptBase(const char *name)
UpDownInterruptBase::UpDownInterruptBase(const char *name) : concurrency::OSThread(name)
{
this->_originName = name;
}
@ -24,31 +24,48 @@ void UpDownInterruptBase::init(uint8_t pinDown, uint8_t pinUp, uint8_t pinPress,
attachInterrupt(this->_pinUp, onIntUp, RISING);
LOG_DEBUG("Up/down/press GPIO initialized (%d, %d, %d)\n", this->_pinUp, this->_pinDown, pinPress);
this->setInterval(100);
}
int32_t UpDownInterruptBase::runOnce()
{
InputEvent e;
e.inputEvent = meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_NONE;
if (this->action == UPDOWN_ACTION_PRESSED) {
LOG_DEBUG("GPIO event Press\n");
e.inputEvent = this->_eventPressed;
} else if (this->action == UPDOWN_ACTION_UP) {
LOG_DEBUG("GPIO event Up\n");
e.inputEvent = this->_eventUp;
} else if (this->action == UPDOWN_ACTION_DOWN) {
LOG_DEBUG("GPIO event Down\n");
e.inputEvent = this->_eventDown;
}
if (e.inputEvent != meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_NONE) {
e.source = this->_originName;
e.kbchar = meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_NONE;
this->notifyObservers(&e);
}
this->action = UPDOWN_ACTION_NONE;
return 100;
}
void UpDownInterruptBase::intPressHandler()
{
InputEvent e;
e.source = this->_originName;
LOG_DEBUG("GPIO event Press\n");
e.inputEvent = this->_eventPressed;
this->notifyObservers(&e);
this->action = UPDOWN_ACTION_PRESSED;
}
void UpDownInterruptBase::intDownHandler()
{
InputEvent e;
e.source = this->_originName;
LOG_DEBUG("GPIO event Down\n");
e.inputEvent = this->_eventDown;
this->notifyObservers(&e);
this->action = UPDOWN_ACTION_DOWN;
}
void UpDownInterruptBase::intUpHandler()
{
InputEvent e;
e.source = this->_originName;
LOG_DEBUG("GPIO event Up\n");
e.inputEvent = this->_eventUp;
this->notifyObservers(&e);
this->action = UPDOWN_ACTION_UP;
}

Wyświetl plik

@ -3,7 +3,7 @@
#include "InputBroker.h"
#include "mesh/NodeDB.h"
class UpDownInterruptBase : public Observable<const InputEvent *>
class UpDownInterruptBase : public Observable<const InputEvent *>, public concurrency::OSThread
{
public:
explicit UpDownInterruptBase(const char *name);
@ -13,6 +13,13 @@ class UpDownInterruptBase : public Observable<const InputEvent *>
void intDownHandler();
void intUpHandler();
int32_t runOnce() override;
protected:
enum UpDownInterruptBaseActionType { UPDOWN_ACTION_NONE, UPDOWN_ACTION_PRESSED, UPDOWN_ACTION_UP, UPDOWN_ACTION_DOWN };
volatile UpDownInterruptBaseActionType action = UPDOWN_ACTION_NONE;
private:
uint8_t _pinDown = 0;
uint8_t _pinUp = 0;