diff --git a/openrtx/include/core/ui.h b/openrtx/include/core/ui.h index 20980ae5..283ba7ed 100644 --- a/openrtx/include/core/ui.h +++ b/openrtx/include/core/ui.h @@ -249,10 +249,11 @@ void ui_updateGUI(); /** * Push an event to the UI event queue. * - * @param event: event to be pushed. + * @param type: event type. + * @param data: event data. * @return true on success false on failure. */ -bool ui_pushEvent(const event_t event); +bool ui_pushEvent(const uint8_t type, const uint32_t data); /** * This function terminates the User Interface. diff --git a/openrtx/src/core/threads.c b/openrtx/src/core/threads.c index 69e08006..bdf3771e 100644 --- a/openrtx/src/core/threads.c +++ b/openrtx/src/core/threads.c @@ -49,7 +49,6 @@ void *ui_task(void *arg) { (void) arg; - event_t kbd_event = {{EVENT_KBD, 0}}; kbd_msg_t kbd_msg; rtxStatus_t rtx_cfg; bool sync_rtx = true; @@ -66,8 +65,7 @@ void *ui_task(void *arg) if(input_scanKeyboard(&kbd_msg)) { - kbd_event.payload = kbd_msg.value; - ui_pushEvent(kbd_event); + ui_pushEvent(EVENT_KBD, kbd_msg.value); } pthread_mutex_lock(&state_mutex); // Lock r/w access to radio state @@ -172,11 +170,7 @@ void *dev_task(void *arg) if((tick_5ms % 20) == 0) { state_update(); - - event_t dev_msg; - dev_msg.type = EVENT_STATUS; - dev_msg.payload = 0; - ui_pushEvent(dev_msg); + ui_pushEvent(EVENT_STATUS, 0); } // Run this loop once every 5ms diff --git a/openrtx/src/ui/ui.c b/openrtx/src/ui/ui.c index bf40e955..7905a69e 100644 --- a/openrtx/src/ui/ui.c +++ b/openrtx/src/ui/ui.c @@ -1784,13 +1784,18 @@ void ui_updateGUI() } } -bool ui_pushEvent(const event_t event) +bool ui_pushEvent(const uint8_t type, const uint32_t data) { uint8_t newHead = (evQueue_wrPos + 1) % MAX_NUM_EVENTS; // Queue is full if(newHead == evQueue_rdPos) return false; + // Preserve atomicity when writing the new element into the queue. + event_t event; + event.type = type; + event.payload = data; + evQueue[evQueue_wrPos] = event; evQueue_wrPos = newHead;