From 1426f93ade382075fadd2d02a4cad311a51d526f Mon Sep 17 00:00:00 2001 From: Dylanliacc Date: Wed, 4 Jun 2025 14:07:21 +0800 Subject: [PATCH 1/2] update trackerball for tracker L1 menu key --- src/input/TrackballInterruptBase.cpp | 38 ++++++++++++++++++--------- src/input/TrackballInterruptBase.h | 15 +++++++---- src/input/TrackballInterruptImpl1.cpp | 33 ++++++++++++++++++++--- src/input/TrackballInterruptImpl1.h | 1 + src/modules/CannedMessageModule.h | 4 +++ 5 files changed, 71 insertions(+), 20 deletions(-) diff --git a/src/input/TrackballInterruptBase.cpp b/src/input/TrackballInterruptBase.cpp index e35da3622..a17c01360 100644 --- a/src/input/TrackballInterruptBase.cpp +++ b/src/input/TrackballInterruptBase.cpp @@ -4,35 +4,41 @@ TrackballInterruptBase::TrackballInterruptBase(const char *name) : concurrency::OSThread(name), _originName(name) {} void TrackballInterruptBase::init(uint8_t pinDown, uint8_t pinUp, uint8_t pinLeft, uint8_t pinRight, uint8_t pinPress, + uint8_t pinMenuParam, char eventDown, char eventUp, char eventLeft, char eventRight, char eventPressed, - void (*onIntDown)(), void (*onIntUp)(), void (*onIntLeft)(), void (*onIntRight)(), - void (*onIntPress)()) + char eventmenu, void (*onIntDown)(), void (*onIntUp)(), void (*onIntLeft)(), + void (*onIntRight)(), void (*onIntPress)(), void (*onMenuPress)()) { this->_pinDown = pinDown; this->_pinUp = pinUp; this->_pinLeft = pinLeft; this->_pinRight = pinRight; + this->_pinPress = pinPress; + this->_pinMenu = pinMenuParam; + this->_eventDown = eventDown; this->_eventUp = eventUp; this->_eventLeft = eventLeft; this->_eventRight = eventRight; this->_eventPressed = eventPressed; + this->_eventMenu = eventmenu; - pinMode(pinPress, INPUT_PULLUP); + pinMode(this->_pinPress, INPUT_PULLUP); pinMode(this->_pinDown, INPUT_PULLUP); pinMode(this->_pinUp, INPUT_PULLUP); pinMode(this->_pinLeft, INPUT_PULLUP); pinMode(this->_pinRight, INPUT_PULLUP); + pinMode(this->_pinMenu, INPUT_PULLUP); - attachInterrupt(pinPress, onIntPress, RISING); + attachInterrupt(this->_pinPress, onIntPress, RISING); attachInterrupt(this->_pinDown, onIntDown, RISING); attachInterrupt(this->_pinUp, onIntUp, RISING); attachInterrupt(this->_pinLeft, onIntLeft, RISING); attachInterrupt(this->_pinRight, onIntRight, RISING); + attachInterrupt(this->_pinMenu, onMenuPress, RISING); - LOG_DEBUG("Trackball GPIO initialized (%d, %d, %d, %d, %d)", this->_pinUp, this->_pinDown, this->_pinLeft, this->_pinRight, - pinPress); - + LOG_DEBUG("Trackball GPIO initialized (Up:%d, Down:%d, Left:%d, Right:%d, Press:%d, Menu:%d)", this->_pinUp, this->_pinDown, + this->_pinLeft, this->_pinRight, this->_pinPress, this->_pinMenu); this->setInterval(100); } @@ -42,20 +48,23 @@ int32_t TrackballInterruptBase::runOnce() e.inputEvent = meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_NONE; if (this->action == TB_ACTION_PRESSED) { - // LOG_DEBUG("Trackball event Press"); + LOG_DEBUG("Trackball event Press"); e.inputEvent = this->_eventPressed; } else if (this->action == TB_ACTION_UP) { - // LOG_DEBUG("Trackball event UP"); + LOG_DEBUG("Trackball event UP"); e.inputEvent = this->_eventUp; } else if (this->action == TB_ACTION_DOWN) { - // LOG_DEBUG("Trackball event DOWN"); + LOG_DEBUG("Trackball event DOWN"); e.inputEvent = this->_eventDown; } else if (this->action == TB_ACTION_LEFT) { - // LOG_DEBUG("Trackball event LEFT"); + LOG_DEBUG("Trackball event LEFT"); e.inputEvent = this->_eventLeft; } else if (this->action == TB_ACTION_RIGHT) { - // LOG_DEBUG("Trackball event RIGHT"); + LOG_DEBUG("Trackball event RIGHT"); e.inputEvent = this->_eventRight; + } else if (this->action == TB_ACTION_MENU) { + LOG_DEBUG("Trackball event Menu"); + e.inputEvent = this->_eventMenu; } if (e.inputEvent != meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_NONE) { @@ -93,3 +102,8 @@ void TrackballInterruptBase::intRightHandler() { this->action = TB_ACTION_RIGHT; } + +void TrackballInterruptBase::intMenuHandler() +{ + this->action = TB_ACTION_MENU; +} diff --git a/src/input/TrackballInterruptBase.h b/src/input/TrackballInterruptBase.h index e7fc99f54..55f901395 100644 --- a/src/input/TrackballInterruptBase.h +++ b/src/input/TrackballInterruptBase.h @@ -7,15 +7,16 @@ class TrackballInterruptBase : public Observable, public con { public: explicit TrackballInterruptBase(const char *name); - void init(uint8_t pinDown, uint8_t pinUp, uint8_t pinLeft, uint8_t pinRight, uint8_t pinPress, char eventDown, char eventUp, - char eventLeft, char eventRight, char eventPressed, void (*onIntDown)(), void (*onIntUp)(), void (*onIntLeft)(), - void (*onIntRight)(), void (*onIntPress)()); + void init(uint8_t pinDown, uint8_t pinUp, uint8_t pinLeft, uint8_t pinRight, uint8_t pinPress, uint8_t pinMenu, + char eventDown, char eventUp, char eventLeft, char eventRight, char eventPressed, char eventmenu, + void (*onIntDown)(), void (*onIntUp)(), void (*onIntLeft)(), void (*onIntRight)(), void (*onIntPress)(), + void (*onMenuPress)()); void intPressHandler(); void intDownHandler(); void intUpHandler(); void intLeftHandler(); void intRightHandler(); - + void intMenuHandler(); virtual int32_t runOnce() override; protected: @@ -25,7 +26,8 @@ class TrackballInterruptBase : public Observable, public con TB_ACTION_UP, TB_ACTION_DOWN, TB_ACTION_LEFT, - TB_ACTION_RIGHT + TB_ACTION_RIGHT, + TB_ACTION_MENU }; volatile TrackballInterruptBaseActionType action = TB_ACTION_NONE; @@ -35,10 +37,13 @@ class TrackballInterruptBase : public Observable, public con uint8_t _pinUp = 0; uint8_t _pinLeft = 0; uint8_t _pinRight = 0; + uint8_t _pinPress = 0; + uint8_t _pinMenu = 0; char _eventDown = meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_NONE; char _eventUp = meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_NONE; char _eventLeft = meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_NONE; char _eventRight = meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_NONE; char _eventPressed = meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_NONE; + char _eventMenu = meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_NONE; const char *_originName; }; diff --git a/src/input/TrackballInterruptImpl1.cpp b/src/input/TrackballInterruptImpl1.cpp index 0a73b83b6..e1986b80e 100644 --- a/src/input/TrackballInterruptImpl1.cpp +++ b/src/input/TrackballInterruptImpl1.cpp @@ -2,6 +2,8 @@ #include "InputBroker.h" #include "configuration.h" +#include "main.h" +#include "modules/CannedMessageModule.h" TrackballInterruptImpl1 *trackballInterruptImpl1; TrackballInterruptImpl1::TrackballInterruptImpl1() : TrackballInterruptBase("trackball1") {} @@ -17,17 +19,22 @@ void TrackballInterruptImpl1::init() uint8_t pinLeft = TB_LEFT; uint8_t pinRight = TB_RIGHT; uint8_t pinPress = TB_PRESS; + uint8_t pinmenu = BUTTON_PIN; char eventDown = static_cast(meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_DOWN); char eventUp = static_cast(meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_UP); char eventLeft = static_cast(meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_LEFT); char eventRight = static_cast(meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_RIGHT); char eventPressed = static_cast(meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_SELECT); + char eventcancel = + static_cast(meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_CANCEL); - TrackballInterruptBase::init(pinDown, pinUp, pinLeft, pinRight, pinPress, eventDown, eventUp, eventLeft, eventRight, - eventPressed, TrackballInterruptImpl1::handleIntDown, TrackballInterruptImpl1::handleIntUp, + TrackballInterruptBase::init(pinDown, pinUp, pinLeft, pinRight, pinPress, pinmenu, + eventDown, eventUp, eventLeft, eventRight, eventPressed, + eventcancel, + TrackballInterruptImpl1::handleIntDown, TrackballInterruptImpl1::handleIntUp, TrackballInterruptImpl1::handleIntLeft, TrackballInterruptImpl1::handleIntRight, - TrackballInterruptImpl1::handleIntPressed); + TrackballInterruptImpl1::handleIntPressed, TrackballInterruptImpl1::handleMenuPressed); inputBroker->registerSource(this); #endif } @@ -52,3 +59,23 @@ void TrackballInterruptImpl1::handleIntPressed() { trackballInterruptImpl1->intPressHandler(); } + +void TrackballInterruptImpl1::handleMenuPressed() +{ + bool activateMenuAction = false; + + + if (cannedMessageModule && cannedMessageModule->isUIVisibleAndInterceptingInput()) { + activateMenuAction = true; + } + + if (activateMenuAction) { + + if (trackballInterruptImpl1) { + LOG_DEBUG("Menu pressed; Canned Message UI is active and intercepting input. Activating CANCEL."); + trackballInterruptImpl1->intMenuHandler(); + } + } else { + LOG_DEBUG("Menu pressed, but Canned Message module is not intercepting input. No action from trackball."); + } +} \ No newline at end of file diff --git a/src/input/TrackballInterruptImpl1.h b/src/input/TrackballInterruptImpl1.h index 36efac6a6..0ccc5971e 100644 --- a/src/input/TrackballInterruptImpl1.h +++ b/src/input/TrackballInterruptImpl1.h @@ -11,6 +11,7 @@ class TrackballInterruptImpl1 : public TrackballInterruptBase static void handleIntLeft(); static void handleIntRight(); static void handleIntPressed(); + static void handleMenuPressed(); }; extern TrackballInterruptImpl1 *trackballInterruptImpl1; diff --git a/src/modules/CannedMessageModule.h b/src/modules/CannedMessageModule.h index a91933a0f..090c74492 100644 --- a/src/modules/CannedMessageModule.h +++ b/src/modules/CannedMessageModule.h @@ -92,6 +92,10 @@ class CannedMessageModule : public SinglePortModule, public ObservableinterceptingKeyboardInput(); + } protected: virtual int32_t runOnce() override; From 3eee1f3c5642595a4b71e19d49b44649f142253f Mon Sep 17 00:00:00 2001 From: dylan Date: Thu, 5 Jun 2025 01:25:25 -0700 Subject: [PATCH 2/2] trunk fmt --- src/input/TrackballInterruptBase.cpp | 5 ++--- src/input/TrackballInterruptImpl1.cpp | 17 +++++++---------- src/modules/CannedMessageModule.h | 5 +---- 3 files changed, 10 insertions(+), 17 deletions(-) diff --git a/src/input/TrackballInterruptBase.cpp b/src/input/TrackballInterruptBase.cpp index a17c01360..8b8b5b64e 100644 --- a/src/input/TrackballInterruptBase.cpp +++ b/src/input/TrackballInterruptBase.cpp @@ -4,9 +4,8 @@ TrackballInterruptBase::TrackballInterruptBase(const char *name) : concurrency::OSThread(name), _originName(name) {} void TrackballInterruptBase::init(uint8_t pinDown, uint8_t pinUp, uint8_t pinLeft, uint8_t pinRight, uint8_t pinPress, - uint8_t pinMenuParam, - char eventDown, char eventUp, char eventLeft, char eventRight, char eventPressed, - char eventmenu, void (*onIntDown)(), void (*onIntUp)(), void (*onIntLeft)(), + uint8_t pinMenuParam, char eventDown, char eventUp, char eventLeft, char eventRight, + char eventPressed, char eventmenu, void (*onIntDown)(), void (*onIntUp)(), void (*onIntLeft)(), void (*onIntRight)(), void (*onIntPress)(), void (*onMenuPress)()) { this->_pinDown = pinDown; diff --git a/src/input/TrackballInterruptImpl1.cpp b/src/input/TrackballInterruptImpl1.cpp index e1986b80e..c5b5cdc8c 100644 --- a/src/input/TrackballInterruptImpl1.cpp +++ b/src/input/TrackballInterruptImpl1.cpp @@ -26,15 +26,13 @@ void TrackballInterruptImpl1::init() char eventLeft = static_cast(meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_LEFT); char eventRight = static_cast(meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_RIGHT); char eventPressed = static_cast(meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_SELECT); - char eventcancel = - static_cast(meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_CANCEL); + char eventcancel = static_cast(meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_CANCEL); - TrackballInterruptBase::init(pinDown, pinUp, pinLeft, pinRight, pinPress, pinmenu, - eventDown, eventUp, eventLeft, eventRight, eventPressed, - eventcancel, - TrackballInterruptImpl1::handleIntDown, TrackballInterruptImpl1::handleIntUp, - TrackballInterruptImpl1::handleIntLeft, TrackballInterruptImpl1::handleIntRight, - TrackballInterruptImpl1::handleIntPressed, TrackballInterruptImpl1::handleMenuPressed); + TrackballInterruptBase::init(pinDown, pinUp, pinLeft, pinRight, pinPress, pinmenu, eventDown, eventUp, eventLeft, eventRight, + eventPressed, eventcancel, TrackballInterruptImpl1::handleIntDown, + TrackballInterruptImpl1::handleIntUp, TrackballInterruptImpl1::handleIntLeft, + TrackballInterruptImpl1::handleIntRight, TrackballInterruptImpl1::handleIntPressed, + TrackballInterruptImpl1::handleMenuPressed); inputBroker->registerSource(this); #endif } @@ -64,13 +62,12 @@ void TrackballInterruptImpl1::handleMenuPressed() { bool activateMenuAction = false; - if (cannedMessageModule && cannedMessageModule->isUIVisibleAndInterceptingInput()) { activateMenuAction = true; } if (activateMenuAction) { - + if (trackballInterruptImpl1) { LOG_DEBUG("Menu pressed; Canned Message UI is active and intercepting input. Activating CANCEL."); trackballInterruptImpl1->intMenuHandler(); diff --git a/src/modules/CannedMessageModule.h b/src/modules/CannedMessageModule.h index 090c74492..6911174f6 100644 --- a/src/modules/CannedMessageModule.h +++ b/src/modules/CannedMessageModule.h @@ -92,10 +92,7 @@ class CannedMessageModule : public SinglePortModule, public ObservableinterceptingKeyboardInput(); - } + bool isUIVisibleAndInterceptingInput() { return this->interceptingKeyboardInput(); } protected: virtual int32_t runOnce() override;