update trackerball for tracker L1 menu key

This commit is contained in:
Dylanliacc 2025-06-04 14:07:21 +08:00
parent b6cb0b148c
commit 1426f93ade
5 changed files with 71 additions and 20 deletions

View File

@ -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;
}

View File

@ -7,15 +7,16 @@ class TrackballInterruptBase : public Observable<const InputEvent *>, 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<const InputEvent *>, 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<const InputEvent *>, 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;
};

View File

@ -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<char>(meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_DOWN);
char eventUp = static_cast<char>(meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_UP);
char eventLeft = static_cast<char>(meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_LEFT);
char eventRight = static_cast<char>(meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_RIGHT);
char eventPressed = static_cast<char>(meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_SELECT);
char eventcancel =
static_cast<char>(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.");
}
}

View File

@ -11,6 +11,7 @@ class TrackballInterruptImpl1 : public TrackballInterruptBase
static void handleIntLeft();
static void handleIntRight();
static void handleIntPressed();
static void handleMenuPressed();
};
extern TrackballInterruptImpl1 *trackballInterruptImpl1;

View File

@ -92,6 +92,10 @@ class CannedMessageModule : public SinglePortModule, public Observable<const UIF
return false;
}
}
bool isUIVisibleAndInterceptingInput()
{
return this->interceptingKeyboardInput();
}
protected:
virtual int32_t runOnce() override;