More flexible InputPollable paradigm

This commit is contained in:
WillyJL
2025-09-24 03:05:26 +02:00
parent a1ca553bc0
commit 060a129995
3 changed files with 13 additions and 5 deletions

View File

@@ -18,14 +18,22 @@ void InputBroker::registerSource(Observable<const InputEvent *> *source)
} }
#ifdef HAS_FREE_RTOS #ifdef HAS_FREE_RTOS
void InputBroker::pollSoonRequestFromIsr(InputPollable *pollable) void InputBroker::requestPollSoon(InputPollable *pollable)
{ {
xQueueSendFromISR(pollSoonQueue, &pollable, NULL); if (xPortInIsrContext() == pdTRUE) {
xQueueSendFromISR(pollSoonQueue, &pollable, NULL);
} else {
xQueueSend(pollSoonQueue, &pollable, 0);
}
} }
void InputBroker::queueInputEvent(const InputEvent *event) void InputBroker::queueInputEvent(const InputEvent *event)
{ {
xQueueSend(inputEventQueue, event, portMAX_DELAY); if (xPortInIsrContext() == pdTRUE) {
xQueueSendFromISR(inputEventQueue, event, NULL);
} else {
xQueueSend(inputEventQueue, event, portMAX_DELAY);
}
} }
void InputBroker::processInputEventQueue() void InputBroker::processInputEventQueue()

View File

@@ -60,7 +60,7 @@ class InputBroker : public Observable<const InputEvent *>
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 #ifdef HAS_FREE_RTOS
void pollSoonRequestFromIsr(InputPollable *pollable); void requestPollSoon(InputPollable *pollable);
void queueInputEvent(const InputEvent *event); void queueInputEvent(const InputEvent *event);
void processInputEventQueue(); void processInputEventQueue();
#endif #endif

View File

@@ -30,7 +30,7 @@ bool RotaryEncoderImpl::init()
rotary->resetButton(); rotary->resetButton();
interruptInstance = this; interruptInstance = this;
auto interruptHandler = []() { inputBroker->pollSoonRequestFromIsr(interruptInstance); }; auto interruptHandler = []() { inputBroker->requestPollSoon(interruptInstance); };
attachInterrupt(moduleConfig.canned_message.inputbroker_pin_a, interruptHandler, CHANGE); attachInterrupt(moduleConfig.canned_message.inputbroker_pin_a, interruptHandler, CHANGE);
attachInterrupt(moduleConfig.canned_message.inputbroker_pin_b, interruptHandler, CHANGE); attachInterrupt(moduleConfig.canned_message.inputbroker_pin_b, interruptHandler, CHANGE);
attachInterrupt(moduleConfig.canned_message.inputbroker_pin_press, interruptHandler, CHANGE); attachInterrupt(moduleConfig.canned_message.inputbroker_pin_press, interruptHandler, CHANGE);