mirror of
https://github.com/meshtastic/firmware.git
synced 2025-12-21 02:02:23 +00:00
InputPollable: System for polling after interrupts
This commit is contained in:
@@ -3,16 +3,58 @@
|
|||||||
|
|
||||||
InputBroker *inputBroker = nullptr;
|
InputBroker *inputBroker = nullptr;
|
||||||
|
|
||||||
InputBroker::InputBroker(){};
|
InputBroker::InputBroker()
|
||||||
|
{
|
||||||
|
#ifdef HAS_FREE_RTOS
|
||||||
|
inputEventQueue = xQueueCreate(5, sizeof(InputEvent));
|
||||||
|
pollSoonQueue = xQueueCreate(5, sizeof(InputPollable *));
|
||||||
|
xTaskCreate(pollSoonWorker, "input-pollSoon", 2 * 1024, this, 10, &pollSoonTask);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
void InputBroker::registerSource(Observable<const InputEvent *> *source)
|
void InputBroker::registerSource(Observable<const InputEvent *> *source)
|
||||||
{
|
{
|
||||||
this->inputEventObserver.observe(source);
|
this->inputEventObserver.observe(source);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef HAS_FREE_RTOS
|
||||||
|
void InputBroker::pollSoonRequestFromIsr(InputPollable *pollable)
|
||||||
|
{
|
||||||
|
xQueueSendFromISR(pollSoonQueue, &pollable, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
void InputBroker::queueInputEvent(const InputEvent *event)
|
||||||
|
{
|
||||||
|
xQueueSend(inputEventQueue, event, portMAX_DELAY);
|
||||||
|
}
|
||||||
|
|
||||||
|
void InputBroker::processInputEventQueue()
|
||||||
|
{
|
||||||
|
InputEvent event;
|
||||||
|
while (xQueueReceive(inputEventQueue, &event, 0)) {
|
||||||
|
handleInputEvent(&event);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
int InputBroker::handleInputEvent(const InputEvent *event)
|
int InputBroker::handleInputEvent(const InputEvent *event)
|
||||||
{
|
{
|
||||||
powerFSM.trigger(EVENT_INPUT); // todo: not every input should wake, like long hold release
|
powerFSM.trigger(EVENT_INPUT); // todo: not every input should wake, like long hold release
|
||||||
this->notifyObservers(event);
|
this->notifyObservers(event);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef HAS_FREE_RTOS
|
||||||
|
void InputBroker::pollSoonWorker(void *p)
|
||||||
|
{
|
||||||
|
InputBroker *instance = (InputBroker *)p;
|
||||||
|
while (true) {
|
||||||
|
InputPollable *pollable = NULL;
|
||||||
|
xQueueReceive(instance->pollSoonQueue, &pollable, portMAX_DELAY);
|
||||||
|
if (pollable) {
|
||||||
|
pollable->pollOnce();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
vTaskDelete(NULL);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "Observer.h"
|
#include "Observer.h"
|
||||||
|
#include "freertosinc.h"
|
||||||
|
|
||||||
enum input_broker_event {
|
enum input_broker_event {
|
||||||
INPUT_BROKER_NONE = 0,
|
INPUT_BROKER_NONE = 0,
|
||||||
@@ -41,6 +43,13 @@ typedef struct _InputEvent {
|
|||||||
uint16_t touchX;
|
uint16_t touchX;
|
||||||
uint16_t touchY;
|
uint16_t touchY;
|
||||||
} InputEvent;
|
} InputEvent;
|
||||||
|
|
||||||
|
class InputPollable
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual void pollOnce() = 0;
|
||||||
|
};
|
||||||
|
|
||||||
class InputBroker : public Observable<const InputEvent *>
|
class InputBroker : public Observable<const InputEvent *>
|
||||||
{
|
{
|
||||||
CallbackObserver<InputBroker, const InputEvent *> inputEventObserver =
|
CallbackObserver<InputBroker, const InputEvent *> inputEventObserver =
|
||||||
@@ -50,9 +59,22 @@ class InputBroker : public Observable<const InputEvent *>
|
|||||||
InputBroker();
|
InputBroker();
|
||||||
void registerSource(Observable<const InputEvent *> *source);
|
void registerSource(Observable<const InputEvent *> *source);
|
||||||
void injectInputEvent(const InputEvent *event) { handleInputEvent(event); }
|
void injectInputEvent(const InputEvent *event) { handleInputEvent(event); }
|
||||||
|
#ifdef HAS_FREE_RTOS
|
||||||
|
void pollSoonRequestFromIsr(InputPollable *pollable);
|
||||||
|
void queueInputEvent(const InputEvent *event);
|
||||||
|
void processInputEventQueue();
|
||||||
|
#endif
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
int handleInputEvent(const InputEvent *event);
|
int handleInputEvent(const InputEvent *event);
|
||||||
|
|
||||||
|
private:
|
||||||
|
#ifdef HAS_FREE_RTOS
|
||||||
|
QueueHandle_t inputEventQueue;
|
||||||
|
QueueHandle_t pollSoonQueue;
|
||||||
|
TaskHandle_t pollSoonTask;
|
||||||
|
static void pollSoonWorker(void *p);
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
extern InputBroker *inputBroker;
|
extern InputBroker *inputBroker;
|
||||||
@@ -1602,6 +1602,9 @@ void loop()
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
service->loop();
|
service->loop();
|
||||||
|
#if !MESHTASTIC_EXCLUDE_INPUTBROKER
|
||||||
|
inputBroker->processInputEventQueue();
|
||||||
|
#endif
|
||||||
#if defined(LGFX_SDL)
|
#if defined(LGFX_SDL)
|
||||||
if (screen) {
|
if (screen) {
|
||||||
auto dispdev = screen->getDisplayDevice();
|
auto dispdev = screen->getDisplayDevice();
|
||||||
|
|||||||
Reference in New Issue
Block a user