diff --git a/src/input/ButtonThread.cpp b/src/input/ButtonThread.cpp index d22dec33e..dba262e31 100644 --- a/src/input/ButtonThread.cpp +++ b/src/input/ButtonThread.cpp @@ -31,6 +31,8 @@ bool ButtonThread::initButton(uint8_t pinNumber, bool activeLow, bool activePull input_broker_event singlePress, input_broker_event longPress, input_broker_event doublePress, input_broker_event triplePress, input_broker_event shortLong, bool touchQuirk) { + if (inputBroker) + inputBroker->registerSource(this); _pinNum = pinNumber; _activeLow = activeLow; _touchQuirk = touchQuirk; diff --git a/src/input/ButtonThreadImpl.cpp b/src/input/ButtonThreadImpl.cpp deleted file mode 100644 index 913a516e1..000000000 --- a/src/input/ButtonThreadImpl.cpp +++ /dev/null @@ -1,15 +0,0 @@ -#include "ButtonThreadImpl.h" -#include "InputBroker.h" -#include "configuration.h" - -ButtonThreadImpl::ButtonThreadImpl(char *_name) : ButtonThread(_name) {} - -void ButtonThreadImpl::init(uint8_t pinNumber, bool activeLow, bool activePullup, uint32_t pullupSense, voidFuncPtr intRoutine, - input_broker_event singlePress, input_broker_event longPress, input_broker_event doublePress, - input_broker_event triplePress, input_broker_event shortLong, bool touchQuirk) -{ - if (inputBroker) - inputBroker->registerSource(this); - initButton(pinNumber, activeLow, activePullup, pullupSense, intRoutine, singlePress, longPress, doublePress, triplePress, - shortLong, touchQuirk); -} diff --git a/src/input/ButtonThreadImpl.h b/src/input/ButtonThreadImpl.h deleted file mode 100644 index a12f2ddf1..000000000 --- a/src/input/ButtonThreadImpl.h +++ /dev/null @@ -1,20 +0,0 @@ -#pragma once -#include "ButtonThread.h" -#include "main.h" - -/** - * @brief The idea behind this class to have static methods for the event handlers. - * Check attachInterrupt() at RotaryEncoderInteruptBase.cpp - * Technically you can have as many rotary encoders hardver attached - * to your device as you wish, but you always need to have separate event - * handlers, thus you need to have a RotaryEncoderInterrupt implementation. - */ -class ButtonThreadImpl : public ButtonThread -{ - public: - ButtonThreadImpl(char *); - void init(uint8_t pinNumber, bool activeLow, bool activePullup, uint32_t pullupSense, voidFuncPtr intRoutine, - input_broker_event singlePress, input_broker_event longPress = INPUT_BROKER_NONE, - input_broker_event doublePress = INPUT_BROKER_NONE, input_broker_event triplePress = INPUT_BROKER_NONE, - input_broker_event shortLong = INPUT_BROKER_NONE, bool touchQuirk = false); -}; \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 1f9ee53bd..164cd9751 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -99,18 +99,18 @@ NRF52Bluetooth *nrf52Bluetooth = nullptr; #endif #if HAS_BUTTON || defined(ARCH_PORTDUINO) -#include "input/ButtonThreadImpl.h" +#include "input/ButtonThread.h" #if defined(BUTTON_PIN_TOUCH) -ButtonThreadImpl *TouchButtonThread = nullptr; +ButtonThread *TouchButtonThread = nullptr; #endif #if defined(BUTTON_PIN) -ButtonThreadImpl *UserButtonThread = nullptr; +ButtonThread *UserButtonThread = nullptr; #endif #if defined(BACK_BUTTON_PIN) -ButtonThreadImpl *BackButtonThread = nullptr; +ButtonThread *BackButtonThread = nullptr; #endif #endif @@ -901,8 +901,8 @@ void setup() #endif #ifdef BUTTON_PIN_TOUCH - TouchButtonThread = new ButtonThreadImpl("BackButton"); - TouchButtonThread->init( + TouchButtonThread = new ButtonThread("BackButton"); + TouchButtonThread->initButton( BUTTON_PIN_TOUCH, true, true, pullup_sense, []() { TouchButtonThread->userButton.tick(); @@ -915,8 +915,8 @@ void setup() #if defined(BACK_BUTTON_PIN) // Buttons. Moved here cause we need NodeDB to be initialized - BackButtonThread = new ButtonThreadImpl("BackButton"); - BackButtonThread->init( + BackButtonThread = new ButtonThread("BackButton"); + BackButtonThread->initButton( BACK_BUTTON_PIN, BACK_BUTTON_ACTIVE_LOW, BACK_BUTTON_ACTIVE_PULLUP, pullup_sense, []() { BackButtonThread->userButton.tick(); @@ -942,9 +942,9 @@ void setup() // Buttons. Moved here cause we need NodeDB to be initialized // If your variant.h has a BUTTON_PIN defined, go ahead and define BUTTON_ACTIVE_LOW and BUTTON_ACTIVE_PULLUP - UserButtonThread = new ButtonThreadImpl("UserButton"); + UserButtonThread = new ButtonThread("UserButton"); if (screen) - UserButtonThread->init( + UserButtonThread->initButton( _pinNum, BUTTON_ACTIVE_LOW, BUTTON_ACTIVE_PULLUP, pullup_sense, []() { UserButtonThread->userButton.tick(); @@ -954,7 +954,7 @@ void setup() }, INPUT_BROKER_USER_PRESS, INPUT_BROKER_SELECT); else - UserButtonThread->init( + UserButtonThread->initButton( _pinNum, BUTTON_ACTIVE_LOW, BUTTON_ACTIVE_PULLUP, pullup_sense, []() { UserButtonThread->userButton.tick();