diff --git a/openrtx/include/event.h b/openrtx/include/event.h index e3acfcbb..598ecc15 100644 --- a/openrtx/include/event.h +++ b/openrtx/include/event.h @@ -42,8 +42,8 @@ enum eventType_t */ typedef struct { - uint32_t type : 3, - uint32_t payload : 29 + uint32_t type : 3; + uint32_t payload : 29; }event_t; #endif /* EVENT_H */ diff --git a/openrtx/include/interfaces/keyboard.h b/openrtx/include/interfaces/keyboard.h index 078ec1ef..f00ccbd0 100644 --- a/openrtx/include/interfaces/keyboard.h +++ b/openrtx/include/interfaces/keyboard.h @@ -58,8 +58,6 @@ enum keys KEY_F8 = (1 << 26), /* Function button (device specific) */ KEY_F9 = (1 << 27), /* Function button (device specific) */ KEY_F10 = (1 << 28), /* Function button (device specific) */ - KEY_F11 = (1 << 29), /* Function button (device specific) */ - KEY_F12 = (1 << 30) /* Function button (device specific) */ }; /** diff --git a/openrtx/include/ui.h b/openrtx/include/ui.h index 98a8dcfd..1d618adf 100644 --- a/openrtx/include/ui.h +++ b/openrtx/include/ui.h @@ -24,6 +24,7 @@ #include #include #include +#include /** * This function initialises the User Interface, starting the @@ -35,9 +36,9 @@ void ui_init(); * This function advances the User Interface FSM, basing on the * current radio state and the keys pressed. * @param last_state: A local copy of the previous radio state - * @param keys: A bitmap containing the currently pressed keys + * @param event: An event from other threads */ -void ui_updateFSM(state_t last_state, keyboard_t keys); +void ui_updateFSM(state_t last_state, event_t event); /** * This function redraws the GUI based on the last radio state. diff --git a/openrtx/src/threads.c b/openrtx/src/threads.c index 347011e9..4e3d417f 100644 --- a/openrtx/src/threads.c +++ b/openrtx/src/threads.c @@ -26,14 +26,14 @@ #include #include #include -#include +#include #include /* Mutex for concurrent access to state variable */ static OS_MUTEX state_mutex; -/* Queue for sending and receiving keyboard status */ +/* Queue for sending and receiving ui update requests */ static OS_Q ui_queue; /**************************** IMPORTANT NOTE *********************************** @@ -103,10 +103,9 @@ static void ui_task(void *arg) while(1) { - // Read from the keyboard queue (returns 0 if no message is present) - // Copy keyboard_t keys from received void * pointer msg - event_t event = OSQPend(&ui_queue, 0u, OS_OPT_PEND_NON_BLOCKING, - &msg_size, 0u, &os_err); + // Wait to receive an event message + event_t event = (event_t)OSQPend(&ui_queue, 0u, OS_OPT_PEND_BLOCKING, + &msg_size, 0u, &os_err); // Lock mutex, read and write state OSMutexPend(&state_mutex, 0u, OS_OPT_PEND_BLOCKING, 0u, &os_err); // React to keypresses and update FSM inside state @@ -125,8 +124,10 @@ static void ui_task(void *arg) while(gfx_renderingInProgress()); } + // We don't need a delay because we lock on incoming events + // TODO: Enable self refresh when a continuous visualization is enabled // Update UI at ~33 FPS - OSTimeDlyHMSM(0u, 0u, 0u, 30u, OS_OPT_TIME_HMSM_STRICT, &os_err); + //OSTimeDlyHMSM(0u, 0u, 0u, 30u, OS_OPT_TIME_HMSM_STRICT, &os_err); } } @@ -151,8 +152,9 @@ static void kbd_task(void *arg) event_t kbd_msg; kbd_msg.type = EVENT_KBD; kbd_msg.payload = keys; + void * msg = (void *) kbd_msg; // Send keyboard status in queue - OSQPost(&ui_queue, (void *)kbd_msg, sizeof(event_t), + OSQPost(&ui_queue, msg, sizeof(event_t), OS_OPT_POST_FIFO + OS_OPT_POST_NO_SCHED, &os_err); } // Read keyboard state at 5Hz diff --git a/openrtx/src/ui.c b/openrtx/src/ui.c index 6e6ec0e6..e14072a1 100644 --- a/openrtx/src/ui.c +++ b/openrtx/src/ui.c @@ -291,23 +291,28 @@ void ui_drawSplashScreen() #endif } -void ui_updateFSM(state_t last_state, keyboard_t keys) +void ui_updateFSM(state_t last_state, event_t event) { (void) last_state; - // Temporary VFO controls - if(keys & KEY_UP) + // Process pressed keys + if(event.type = EVENT_KBD) { - // Advance TX and RX frequency of 12.5KHz - state.channel.rx_frequency += 12500; - state.channel.tx_frequency += 12500; - } + keyboard_t keys = event.payload; + // Temporary VFO controls + if(keys & KEY_UP) + { + // Advance TX and RX frequency of 12.5KHz + state.channel.rx_frequency += 12500; + state.channel.tx_frequency += 12500; + } - if(keys & KEY_DOWN) - { - // Advance TX and RX frequency of 12.5KHz - state.channel.rx_frequency -= 12500; - state.channel.tx_frequency -= 12500; + if(keys & KEY_DOWN) + { + // Advance TX and RX frequency of 12.5KHz + state.channel.rx_frequency -= 12500; + state.channel.tx_frequency -= 12500; + } } }