fix T-Deck trackball crashes (#2714)

* try-fix: nodenum crash during boot

* Revert "try-fix: nodenum crash during boot"

This reverts commit 632012e197.

* fix/workaround: trackball interrupt crashes

* trunk fmt

* add OSThread to trackballInterrupt
pull/2716/head v2.2.1.fb5f2e4
Manuel 2023-08-13 02:44:05 +02:00 zatwierdzone przez GitHub
rodzic d29c975e3c
commit fb5f2e48a5
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
5 zmienionych plików z 62 dodań i 31 usunięć

Wyświetl plik

@ -177,7 +177,7 @@ static void serialExit()
static void powerEnter() static void powerEnter()
{ {
LOG_DEBUG("Enter state: POWER\n"); // LOG_DEBUG("Enter state: POWER\n");
if (!isPowered()) { if (!isPowered()) {
// If we got here, we are in the wrong state - we should be in powered, let that state ahndle things // If we got here, we are in the wrong state - we should be in powered, let that state ahndle things
LOG_INFO("Loss of power in Powered\n"); LOG_INFO("Loss of power in Powered\n");

Wyświetl plik

@ -1901,7 +1901,7 @@ int Screen::handleUIFrameEvent(const UIFrameEvent *event)
int Screen::handleInputEvent(const InputEvent *event) int Screen::handleInputEvent(const InputEvent *event)
{ {
if (showingNormalScreen && moduleFrames.size() == 0) { if (showingNormalScreen && moduleFrames.size() == 0) {
LOG_DEBUG("Screen::handleInputEvent from %s\n", event->source); // LOG_DEBUG("Screen::handleInputEvent from %s\n", event->source);
if (event->inputEvent == static_cast<char>(meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_LEFT)) { if (event->inputEvent == static_cast<char>(meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_LEFT)) {
showPrevFrame(); showPrevFrame();
} else if (event->inputEvent == static_cast<char>(meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_RIGHT)) { } else if (event->inputEvent == static_cast<char>(meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_RIGHT)) {

Wyświetl plik

@ -1,10 +1,7 @@
#include "TrackballInterruptBase.h" #include "TrackballInterruptBase.h"
#include "configuration.h" #include "configuration.h"
TrackballInterruptBase::TrackballInterruptBase(const char *name) TrackballInterruptBase::TrackballInterruptBase(const char *name) : concurrency::OSThread(name), _originName(name) {}
{
this->_originName = name;
}
void TrackballInterruptBase::init(uint8_t pinDown, uint8_t pinUp, uint8_t pinLeft, uint8_t pinRight, uint8_t pinPress, void TrackballInterruptBase::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, char eventDown, char eventUp, char eventLeft, char eventRight, char eventPressed,
@ -35,44 +32,64 @@ void TrackballInterruptBase::init(uint8_t pinDown, uint8_t pinUp, uint8_t pinLef
LOG_DEBUG("Trackball GPIO initialized (%d, %d, %d, %d, %d)\n", this->_pinUp, this->_pinDown, this->_pinLeft, this->_pinRight, LOG_DEBUG("Trackball GPIO initialized (%d, %d, %d, %d, %d)\n", this->_pinUp, this->_pinDown, this->_pinLeft, this->_pinRight,
pinPress); pinPress);
this->setInterval(100);
}
int32_t TrackballInterruptBase::runOnce()
{
InputEvent e;
e.inputEvent = meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_NONE;
if (this->action == TB_ACTION_PRESSED) {
// LOG_DEBUG("Trackball event Press\n");
e.inputEvent = this->_eventPressed;
} else if (this->action == TB_ACTION_UP) {
// LOG_DEBUG("Trackball event UP\n");
e.inputEvent = this->_eventUp;
} else if (this->action == TB_ACTION_DOWN) {
// LOG_DEBUG("Trackball event DOWN\n");
e.inputEvent = this->_eventDown;
} else if (this->action == TB_ACTION_LEFT) {
// LOG_DEBUG("Trackball event LEFT\n");
e.inputEvent = this->_eventLeft;
} else if (this->action == TB_ACTION_RIGHT) {
// LOG_DEBUG("Trackball event RIGHT\n");
e.inputEvent = this->_eventRight;
}
if (e.inputEvent != meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_NONE) {
e.source = this->_originName;
e.kbchar = 0x00;
this->notifyObservers(&e);
}
this->action = TB_ACTION_NONE;
return 100;
} }
void TrackballInterruptBase::intPressHandler() void TrackballInterruptBase::intPressHandler()
{ {
InputEvent e; this->action = TB_ACTION_PRESSED;
e.source = this->_originName;
e.inputEvent = this->_eventPressed;
this->notifyObservers(&e);
} }
void TrackballInterruptBase::intDownHandler() void TrackballInterruptBase::intDownHandler()
{ {
InputEvent e; this->action = TB_ACTION_DOWN;
e.source = this->_originName;
e.inputEvent = this->_eventDown;
this->notifyObservers(&e);
} }
void TrackballInterruptBase::intUpHandler() void TrackballInterruptBase::intUpHandler()
{ {
InputEvent e; this->action = TB_ACTION_UP;
e.source = this->_originName;
e.inputEvent = this->_eventUp;
this->notifyObservers(&e);
} }
void TrackballInterruptBase::intLeftHandler() void TrackballInterruptBase::intLeftHandler()
{ {
InputEvent e; this->action = TB_ACTION_LEFT;
e.source = this->_originName;
e.inputEvent = this->_eventLeft;
this->notifyObservers(&e);
} }
void TrackballInterruptBase::intRightHandler() void TrackballInterruptBase::intRightHandler()
{ {
InputEvent e; this->action = TB_ACTION_RIGHT;
e.source = this->_originName;
e.inputEvent = this->_eventRight;
this->notifyObservers(&e);
} }

Wyświetl plik

@ -3,7 +3,7 @@
#include "InputBroker.h" #include "InputBroker.h"
#include "mesh/NodeDB.h" #include "mesh/NodeDB.h"
class TrackballInterruptBase : public Observable<const InputEvent *> class TrackballInterruptBase : public Observable<const InputEvent *>, public concurrency::OSThread
{ {
public: public:
explicit TrackballInterruptBase(const char *name); explicit TrackballInterruptBase(const char *name);
@ -16,6 +16,20 @@ class TrackballInterruptBase : public Observable<const InputEvent *>
void intLeftHandler(); void intLeftHandler();
void intRightHandler(); void intRightHandler();
virtual int32_t runOnce() override;
protected:
enum TrackballInterruptBaseActionType {
TB_ACTION_NONE,
TB_ACTION_PRESSED,
TB_ACTION_UP,
TB_ACTION_DOWN,
TB_ACTION_LEFT,
TB_ACTION_RIGHT
};
volatile TrackballInterruptBaseActionType action = TB_ACTION_NONE;
private: private:
uint8_t _pinDown = 0; uint8_t _pinDown = 0;
uint8_t _pinUp = 0; uint8_t _pinUp = 0;

Wyświetl plik

@ -141,12 +141,12 @@ int CannedMessageModule::handleInputEvent(const InputEvent *event)
bool validEvent = false; bool validEvent = false;
if (event->inputEvent == static_cast<char>(meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_UP)) { if (event->inputEvent == static_cast<char>(meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_UP)) {
LOG_DEBUG("Canned message event UP\n"); // LOG_DEBUG("Canned message event UP\n");
this->runState = CANNED_MESSAGE_RUN_STATE_ACTION_UP; this->runState = CANNED_MESSAGE_RUN_STATE_ACTION_UP;
validEvent = true; validEvent = true;
} }
if (event->inputEvent == static_cast<char>(meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_DOWN)) { if (event->inputEvent == static_cast<char>(meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_DOWN)) {
LOG_DEBUG("Canned message event DOWN\n"); // LOG_DEBUG("Canned message event DOWN\n");
this->runState = CANNED_MESSAGE_RUN_STATE_ACTION_DOWN; this->runState = CANNED_MESSAGE_RUN_STATE_ACTION_DOWN;
validEvent = true; validEvent = true;
} }
@ -170,7 +170,7 @@ int CannedMessageModule::handleInputEvent(const InputEvent *event)
if ((event->inputEvent == static_cast<char>(meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_BACK)) || if ((event->inputEvent == static_cast<char>(meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_BACK)) ||
(event->inputEvent == static_cast<char>(meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_LEFT)) || (event->inputEvent == static_cast<char>(meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_LEFT)) ||
(event->inputEvent == static_cast<char>(meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_RIGHT))) { (event->inputEvent == static_cast<char>(meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_RIGHT))) {
LOG_DEBUG("Canned message event (%x)\n", event->kbchar); // LOG_DEBUG("Canned message event (%x)\n", event->kbchar);
// tweak for left/right events generated via trackball/touch with empty kbchar // tweak for left/right events generated via trackball/touch with empty kbchar
if (!event->kbchar) { if (!event->kbchar) {
if (event->inputEvent == static_cast<char>(meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_LEFT)) { if (event->inputEvent == static_cast<char>(meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_LEFT)) {