kopia lustrzana https://github.com/OpenRTX/OpenRTX
Reorganised radio state data structure, bringing in new channel_t variable.
rodzic
71d00362fb
commit
5d964f3358
|
@ -24,15 +24,19 @@
|
|||
#include <datatypes.h>
|
||||
#include <stdbool.h>
|
||||
#include <rtc.h>
|
||||
#include <cps.h>
|
||||
|
||||
/**
|
||||
* Part of this structure has been commented because the corresponding
|
||||
* functionality is not yet implemented.
|
||||
* Uncomment once the related feature is ready
|
||||
*/
|
||||
typedef struct state_t {
|
||||
typedef struct
|
||||
{
|
||||
bool radioStateUpdated;
|
||||
curTime_t time;
|
||||
float v_bat;
|
||||
|
||||
//enum ui_screen;
|
||||
//enum tuner_mode;
|
||||
//enum radio_mode;
|
||||
|
@ -42,42 +46,23 @@ typedef struct state_t {
|
|||
|
||||
//time_t tx_status_tv;
|
||||
//bool tx_status;
|
||||
|
||||
freq_t rx_freq;
|
||||
freq_t tx_freq;
|
||||
|
||||
//float tx_power;
|
||||
|
||||
//uint8_t squelch;
|
||||
|
||||
//tone_t rx_tone;
|
||||
//tone_t tx_tone;
|
||||
|
||||
//ch_t *channel;
|
||||
|
||||
//#ifdef DMR_ENABLED
|
||||
//uint8_t dmr_color;
|
||||
//uint8_t dmr_timeslot;
|
||||
//dmr_contact_t *dmr_contact;
|
||||
//#endif
|
||||
} state_t;
|
||||
|
||||
/**
|
||||
* This structure is used to mark if the state has been modified
|
||||
* and by which thread.
|
||||
* The threads that are watching for state updates
|
||||
* check the variables of other threads, if they are set,
|
||||
* they know that the state have been modified
|
||||
*/
|
||||
typedef struct modified_t {
|
||||
bool ui_modified;
|
||||
bool rtx_modified;
|
||||
bool self_modified;
|
||||
} modified_t;
|
||||
bool channelInfoUpdated;
|
||||
channel_t channel;
|
||||
uint8_t rtxStatus;
|
||||
uint8_t sqlLevel;
|
||||
uint8_t voxLevel;
|
||||
}
|
||||
state_t;
|
||||
|
||||
enum RtxStatus
|
||||
{
|
||||
RTX_OFF = 0,
|
||||
RTX_RX,
|
||||
RTX_TX
|
||||
};
|
||||
|
||||
extern state_t state;
|
||||
extern modified_t state_flags;
|
||||
|
||||
|
||||
/**
|
||||
* This function initializes the Radio state, acquiring the information
|
||||
|
|
|
@ -22,29 +22,26 @@
|
|||
#include <state.h>
|
||||
#include <platform.h>
|
||||
|
||||
const curTime_t epoch = {0, 0, 0, 1, 1, 1, 70};
|
||||
|
||||
state_t state =
|
||||
{
|
||||
epoch, //time
|
||||
0.0, //v_bat
|
||||
0.0, //rx_freq
|
||||
0.0 //tx_freq
|
||||
};
|
||||
|
||||
modified_t state_flags =
|
||||
{
|
||||
false, //ui_modified
|
||||
false, //rtx_modified
|
||||
false //self_modified
|
||||
};
|
||||
state_t state;
|
||||
|
||||
void state_init()
|
||||
{
|
||||
/*TODO: Read current state parameters from hardware,
|
||||
* or initialize them to sane defaults */
|
||||
/*
|
||||
* TODO: Read current state parameters from hardware,
|
||||
* or initialize them to sane defaults
|
||||
*/
|
||||
state.radioStateUpdated = true;
|
||||
state.time = rtc_getTime();
|
||||
state.v_bat = platform_getVbat();
|
||||
state.rx_freq = 0.0;
|
||||
state.tx_freq = 0.0;
|
||||
|
||||
state.channelInfoUpdated = true;
|
||||
state.channel.mode = 0;
|
||||
state.channel.bandwidth = 0;
|
||||
state.channel.power = 0;
|
||||
state.channel.rx_frequency = 430000000;
|
||||
state.channel.tx_frequency = 430000000;
|
||||
|
||||
state.rtxStatus = RTX_OFF;
|
||||
state.sqlLevel = 0;
|
||||
state.voxLevel = 0;
|
||||
}
|
||||
|
|
|
@ -80,10 +80,10 @@ static void ui_task(void *arg)
|
|||
while(1)
|
||||
{
|
||||
uint32_t keys = kbd_getKeys();
|
||||
// Wait for unlocked mutex and lock it
|
||||
OSMutexPend(&state_mutex, 0u, OS_OPT_PEND_BLOCKING, 0u, &os_err);
|
||||
// React to keypresses and redraw GUI
|
||||
bool renderNeeded = ui_update(last_state, keys);
|
||||
// Wait for unlocked mutex and lock it
|
||||
OSMutexPend(&state_mutex, 0u, OS_OPT_PEND_BLOCKING, 0u, &os_err);
|
||||
// Update state local copy
|
||||
last_state = state;
|
||||
// Unlock the mutex
|
||||
|
@ -158,16 +158,12 @@ void create_threads()
|
|||
OS_ERR os_err;
|
||||
|
||||
// Create state mutex
|
||||
OSMutexCreate((OS_MUTEX *) &state_mutex,
|
||||
(CPU_CHAR *) "State Mutex",
|
||||
(OS_ERR *) &os_err);
|
||||
OSMutexCreate((OS_MUTEX *) &state_mutex,
|
||||
(CPU_CHAR *) "State Mutex",
|
||||
(OS_ERR *) &os_err);
|
||||
|
||||
// Wait for unlocked mutex and lock it
|
||||
OSMutexPend(&state_mutex, 0u, OS_OPT_PEND_BLOCKING, 0u, &os_err);
|
||||
// State initialization, execute before starting all tasks
|
||||
state_init();
|
||||
// Unlock the mutex
|
||||
OSMutexPost(&state_mutex, OS_OPT_POST_NONE, &os_err);
|
||||
|
||||
// Create UI thread
|
||||
OSTaskCreate((OS_TCB *) &ui_tcb,
|
||||
|
|
|
@ -200,31 +200,31 @@ void _ui_drawBackground()
|
|||
gfx_drawHLine(SCREEN_HEIGHT - layout.bottom_h - 1, 1, color_grey);
|
||||
}
|
||||
|
||||
void _ui_drawTopBar()
|
||||
void _ui_drawTopBar(state_t* state)
|
||||
{
|
||||
// Print clock on top bar
|
||||
char clock_buf[6] = "";
|
||||
snprintf(clock_buf, sizeof(clock_buf), "%02d:%02d", state.time.hour,
|
||||
state.time.minute);
|
||||
snprintf(clock_buf, sizeof(clock_buf), "%02d:%02d", state->time.hour,
|
||||
state->time.minute);
|
||||
gfx_print(layout.top_pos, clock_buf, layout.top_font, TEXT_ALIGN_CENTER,
|
||||
color_white);
|
||||
|
||||
// Print battery voltage on top bar, use 4 px padding
|
||||
// TODO: Replace with battery icon
|
||||
char bat_buf[6] = "";
|
||||
snprintf(bat_buf, sizeof(bat_buf), "%02.1fV ", state.v_bat);
|
||||
snprintf(bat_buf, sizeof(bat_buf), "%02.1fV ", state->v_bat);
|
||||
gfx_print(layout.top_pos, bat_buf, layout.top_font, TEXT_ALIGN_RIGHT,
|
||||
color_white);
|
||||
}
|
||||
|
||||
void _ui_drawVFO()
|
||||
void _ui_drawVFO(state_t* state)
|
||||
{
|
||||
// Print VFO frequencies
|
||||
char freq_buf[20] = "";
|
||||
snprintf(freq_buf, sizeof(freq_buf), "Rx: %09.5f", ((float) state.rx_freq));
|
||||
snprintf(freq_buf, sizeof(freq_buf), "Rx: %09.5f", ((float) state->channel.rx_frequency));
|
||||
gfx_print(layout.line2_pos, freq_buf, layout.line1_font, TEXT_ALIGN_CENTER,
|
||||
color_white);
|
||||
snprintf(freq_buf, sizeof(freq_buf), "Tx: %09.5f", ((float) state.tx_freq));
|
||||
snprintf(freq_buf, sizeof(freq_buf), "Tx: %09.5f", ((float) state->channel.tx_frequency));
|
||||
gfx_print(layout.line3_pos, freq_buf, layout.line2_font, TEXT_ALIGN_CENTER,
|
||||
color_white);
|
||||
}
|
||||
|
@ -239,16 +239,14 @@ void _ui_drawBottomBar()
|
|||
|
||||
bool ui_drawMainScreen(state_t last_state)
|
||||
{
|
||||
(void) last_state;
|
||||
|
||||
bool screen_update = false;
|
||||
// Total GUI redraw
|
||||
if(redraw_needed)
|
||||
{
|
||||
gfx_clearScreen();
|
||||
_ui_drawBackground();
|
||||
_ui_drawTopBar();
|
||||
_ui_drawVFO();
|
||||
_ui_drawTopBar(&last_state);
|
||||
_ui_drawVFO(&last_state);
|
||||
_ui_drawBottomBar();
|
||||
screen_update = true;
|
||||
}
|
||||
|
@ -258,8 +256,8 @@ bool ui_drawMainScreen(state_t last_state)
|
|||
{
|
||||
gfx_clearScreen();
|
||||
_ui_drawBackground();
|
||||
_ui_drawTopBar();
|
||||
_ui_drawVFO();
|
||||
_ui_drawTopBar(&last_state);
|
||||
_ui_drawVFO(&last_state);
|
||||
_ui_drawBottomBar();
|
||||
screen_update = true;
|
||||
}
|
||||
|
|
Ładowanie…
Reference in New Issue