Merge branch 'master' into 2.7-MiscFixes-Week1

This commit is contained in:
Jason P 2025-06-21 23:02:54 -05:00 committed by GitHub
commit f11b49863d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 25 additions and 10 deletions

View File

@ -8,7 +8,7 @@ UpDownInterruptBase::UpDownInterruptBase(const char *name) : concurrency::OSThre
void UpDownInterruptBase::init(uint8_t pinDown, uint8_t pinUp, uint8_t pinPress, input_broker_event eventDown, void UpDownInterruptBase::init(uint8_t pinDown, uint8_t pinUp, uint8_t pinPress, input_broker_event eventDown,
input_broker_event eventUp, input_broker_event eventPressed, void (*onIntDown)(), input_broker_event eventUp, input_broker_event eventPressed, void (*onIntDown)(),
void (*onIntUp)(), void (*onIntPress)()) void (*onIntUp)(), void (*onIntPress)(), unsigned long updownDebounceMs)
{ {
this->_pinDown = pinDown; this->_pinDown = pinDown;
this->_pinUp = pinUp; this->_pinUp = pinUp;
@ -33,16 +33,25 @@ int32_t UpDownInterruptBase::runOnce()
{ {
InputEvent e; InputEvent e;
e.inputEvent = INPUT_BROKER_NONE; e.inputEvent = INPUT_BROKER_NONE;
unsigned long now = millis();
if (this->action == UPDOWN_ACTION_PRESSED) { if (this->action == UPDOWN_ACTION_PRESSED) {
LOG_DEBUG("GPIO event Press"); if (now - lastPressKeyTime >= pressDebounceMs) {
e.inputEvent = this->_eventPressed; lastPressKeyTime = now;
LOG_DEBUG("GPIO event Press");
e.inputEvent = this->_eventPressed;
}
} else if (this->action == UPDOWN_ACTION_UP) { } else if (this->action == UPDOWN_ACTION_UP) {
LOG_DEBUG("GPIO event Up"); if (now - lastUpKeyTime >= updownDebounceMs) {
e.inputEvent = this->_eventUp; lastUpKeyTime = now;
LOG_DEBUG("GPIO event Up");
e.inputEvent = this->_eventUp;
}
} else if (this->action == UPDOWN_ACTION_DOWN) { } else if (this->action == UPDOWN_ACTION_DOWN) {
LOG_DEBUG("GPIO event Down"); if (now - lastDownKeyTime >= updownDebounceMs) {
e.inputEvent = this->_eventDown; lastDownKeyTime = now;
LOG_DEBUG("GPIO event Down");
e.inputEvent = this->_eventDown;
}
} }
if (e.inputEvent != INPUT_BROKER_NONE) { if (e.inputEvent != INPUT_BROKER_NONE) {
@ -52,7 +61,6 @@ int32_t UpDownInterruptBase::runOnce()
} }
this->action = UPDOWN_ACTION_NONE; this->action = UPDOWN_ACTION_NONE;
return 100; return 100;
} }

View File

@ -8,7 +8,8 @@ class UpDownInterruptBase : public Observable<const InputEvent *>, public concur
public: public:
explicit UpDownInterruptBase(const char *name); explicit UpDownInterruptBase(const char *name);
void init(uint8_t pinDown, uint8_t pinUp, uint8_t pinPress, input_broker_event eventDown, input_broker_event eventUp, void init(uint8_t pinDown, uint8_t pinUp, uint8_t pinPress, input_broker_event eventDown, input_broker_event eventUp,
input_broker_event eventPressed, void (*onIntDown)(), void (*onIntUp)(), void (*onIntPress)()); input_broker_event eventPressed, void (*onIntDown)(), void (*onIntUp)(), void (*onIntPress)(),
unsigned long updownDebounceMs = 50);
void intPressHandler(); void intPressHandler();
void intDownHandler(); void intDownHandler();
void intUpHandler(); void intUpHandler();
@ -27,4 +28,10 @@ class UpDownInterruptBase : public Observable<const InputEvent *>, public concur
input_broker_event _eventUp = INPUT_BROKER_NONE; input_broker_event _eventUp = INPUT_BROKER_NONE;
input_broker_event _eventPressed = INPUT_BROKER_NONE; input_broker_event _eventPressed = INPUT_BROKER_NONE;
const char *_originName; const char *_originName;
unsigned long lastUpKeyTime = 0;
unsigned long lastDownKeyTime = 0;
unsigned long lastPressKeyTime = 0;
unsigned long updownDebounceMs;
const unsigned long pressDebounceMs = 200;
}; };