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 <datatypes.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <rtc.h>
|
#include <rtc.h>
|
||||||
|
#include <cps.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Part of this structure has been commented because the corresponding
|
* Part of this structure has been commented because the corresponding
|
||||||
* functionality is not yet implemented.
|
* functionality is not yet implemented.
|
||||||
* Uncomment once the related feature is ready
|
* Uncomment once the related feature is ready
|
||||||
*/
|
*/
|
||||||
typedef struct state_t {
|
typedef struct
|
||||||
|
{
|
||||||
|
bool radioStateUpdated;
|
||||||
curTime_t time;
|
curTime_t time;
|
||||||
float v_bat;
|
float v_bat;
|
||||||
|
|
||||||
//enum ui_screen;
|
//enum ui_screen;
|
||||||
//enum tuner_mode;
|
//enum tuner_mode;
|
||||||
//enum radio_mode;
|
//enum radio_mode;
|
||||||
|
@ -43,41 +47,22 @@ typedef struct state_t {
|
||||||
//time_t tx_status_tv;
|
//time_t tx_status_tv;
|
||||||
//bool tx_status;
|
//bool tx_status;
|
||||||
|
|
||||||
freq_t rx_freq;
|
bool channelInfoUpdated;
|
||||||
freq_t tx_freq;
|
channel_t channel;
|
||||||
|
uint8_t rtxStatus;
|
||||||
|
uint8_t sqlLevel;
|
||||||
|
uint8_t voxLevel;
|
||||||
|
}
|
||||||
|
state_t;
|
||||||
|
|
||||||
//float tx_power;
|
enum RtxStatus
|
||||||
|
{
|
||||||
//uint8_t squelch;
|
RTX_OFF = 0,
|
||||||
|
RTX_RX,
|
||||||
//tone_t rx_tone;
|
RTX_TX
|
||||||
//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;
|
|
||||||
|
|
||||||
extern state_t state;
|
extern state_t state;
|
||||||
extern modified_t state_flags;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This function initializes the Radio state, acquiring the information
|
* This function initializes the Radio state, acquiring the information
|
||||||
|
|
|
@ -22,29 +22,26 @@
|
||||||
#include <state.h>
|
#include <state.h>
|
||||||
#include <platform.h>
|
#include <platform.h>
|
||||||
|
|
||||||
const curTime_t epoch = {0, 0, 0, 1, 1, 1, 70};
|
state_t state;
|
||||||
|
|
||||||
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
|
|
||||||
};
|
|
||||||
|
|
||||||
void state_init()
|
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.time = rtc_getTime();
|
||||||
state.v_bat = platform_getVbat();
|
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)
|
while(1)
|
||||||
{
|
{
|
||||||
uint32_t keys = kbd_getKeys();
|
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
|
// React to keypresses and redraw GUI
|
||||||
bool renderNeeded = ui_update(last_state, keys);
|
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
|
// Update state local copy
|
||||||
last_state = state;
|
last_state = state;
|
||||||
// Unlock the mutex
|
// Unlock the mutex
|
||||||
|
@ -162,12 +162,8 @@ void create_threads()
|
||||||
(CPU_CHAR *) "State Mutex",
|
(CPU_CHAR *) "State Mutex",
|
||||||
(OS_ERR *) &os_err);
|
(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 initialization, execute before starting all tasks
|
||||||
state_init();
|
state_init();
|
||||||
// Unlock the mutex
|
|
||||||
OSMutexPost(&state_mutex, OS_OPT_POST_NONE, &os_err);
|
|
||||||
|
|
||||||
// Create UI thread
|
// Create UI thread
|
||||||
OSTaskCreate((OS_TCB *) &ui_tcb,
|
OSTaskCreate((OS_TCB *) &ui_tcb,
|
||||||
|
|
|
@ -200,31 +200,31 @@ void _ui_drawBackground()
|
||||||
gfx_drawHLine(SCREEN_HEIGHT - layout.bottom_h - 1, 1, color_grey);
|
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
|
// Print clock on top bar
|
||||||
char clock_buf[6] = "";
|
char clock_buf[6] = "";
|
||||||
snprintf(clock_buf, sizeof(clock_buf), "%02d:%02d", state.time.hour,
|
snprintf(clock_buf, sizeof(clock_buf), "%02d:%02d", state->time.hour,
|
||||||
state.time.minute);
|
state->time.minute);
|
||||||
gfx_print(layout.top_pos, clock_buf, layout.top_font, TEXT_ALIGN_CENTER,
|
gfx_print(layout.top_pos, clock_buf, layout.top_font, TEXT_ALIGN_CENTER,
|
||||||
color_white);
|
color_white);
|
||||||
|
|
||||||
// Print battery voltage on top bar, use 4 px padding
|
// Print battery voltage on top bar, use 4 px padding
|
||||||
// TODO: Replace with battery icon
|
// TODO: Replace with battery icon
|
||||||
char bat_buf[6] = "";
|
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,
|
gfx_print(layout.top_pos, bat_buf, layout.top_font, TEXT_ALIGN_RIGHT,
|
||||||
color_white);
|
color_white);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _ui_drawVFO()
|
void _ui_drawVFO(state_t* state)
|
||||||
{
|
{
|
||||||
// Print VFO frequencies
|
// Print VFO frequencies
|
||||||
char freq_buf[20] = "";
|
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,
|
gfx_print(layout.line2_pos, freq_buf, layout.line1_font, TEXT_ALIGN_CENTER,
|
||||||
color_white);
|
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,
|
gfx_print(layout.line3_pos, freq_buf, layout.line2_font, TEXT_ALIGN_CENTER,
|
||||||
color_white);
|
color_white);
|
||||||
}
|
}
|
||||||
|
@ -239,16 +239,14 @@ void _ui_drawBottomBar()
|
||||||
|
|
||||||
bool ui_drawMainScreen(state_t last_state)
|
bool ui_drawMainScreen(state_t last_state)
|
||||||
{
|
{
|
||||||
(void) last_state;
|
|
||||||
|
|
||||||
bool screen_update = false;
|
bool screen_update = false;
|
||||||
// Total GUI redraw
|
// Total GUI redraw
|
||||||
if(redraw_needed)
|
if(redraw_needed)
|
||||||
{
|
{
|
||||||
gfx_clearScreen();
|
gfx_clearScreen();
|
||||||
_ui_drawBackground();
|
_ui_drawBackground();
|
||||||
_ui_drawTopBar();
|
_ui_drawTopBar(&last_state);
|
||||||
_ui_drawVFO();
|
_ui_drawVFO(&last_state);
|
||||||
_ui_drawBottomBar();
|
_ui_drawBottomBar();
|
||||||
screen_update = true;
|
screen_update = true;
|
||||||
}
|
}
|
||||||
|
@ -258,8 +256,8 @@ bool ui_drawMainScreen(state_t last_state)
|
||||||
{
|
{
|
||||||
gfx_clearScreen();
|
gfx_clearScreen();
|
||||||
_ui_drawBackground();
|
_ui_drawBackground();
|
||||||
_ui_drawTopBar();
|
_ui_drawTopBar(&last_state);
|
||||||
_ui_drawVFO();
|
_ui_drawVFO(&last_state);
|
||||||
_ui_drawBottomBar();
|
_ui_drawBottomBar();
|
||||||
screen_update = true;
|
screen_update = true;
|
||||||
}
|
}
|
||||||
|
|
Ładowanie…
Reference in New Issue