kopia lustrzana https://github.com/OpenRTX/OpenRTX
UI: Implement RX/TX frequency input
rodzic
58876ec4f2
commit
ac0f906257
151
openrtx/src/ui.c
151
openrtx/src/ui.c
|
@ -126,6 +126,12 @@ const color_t color_grey = {60, 60, 60, 255};
|
||||||
const color_t color_white = {255, 255, 255, 255};
|
const color_t color_white = {255, 255, 255, 255};
|
||||||
const color_t yellow_fab413 = {250, 180, 19, 255};
|
const color_t yellow_fab413 = {250, 180, 19, 255};
|
||||||
|
|
||||||
|
enum SetRxTx
|
||||||
|
{
|
||||||
|
SET_RX = 0,
|
||||||
|
SET_TX
|
||||||
|
};
|
||||||
|
|
||||||
layout_t layout;
|
layout_t layout;
|
||||||
bool layout_ready = false;
|
bool layout_ready = false;
|
||||||
bool redraw_needed = true;
|
bool redraw_needed = true;
|
||||||
|
@ -137,9 +143,12 @@ bool redraw_needed = true;
|
||||||
uint8_t menu_selected = 0;
|
uint8_t menu_selected = 0;
|
||||||
uint8_t input_number = 0;
|
uint8_t input_number = 0;
|
||||||
uint8_t input_position = 0;
|
uint8_t input_position = 0;
|
||||||
|
uint8_t input_set = 0;
|
||||||
freq_t new_rx_frequency;
|
freq_t new_rx_frequency;
|
||||||
freq_t new_tx_frequency;
|
freq_t new_tx_frequency;
|
||||||
char new_rx_freq_buf[14] = "";
|
char new_rx_freq_buf[14] = "";
|
||||||
|
char new_tx_freq_buf[14] = "";
|
||||||
|
|
||||||
|
|
||||||
layout_t _ui_calculateLayout()
|
layout_t _ui_calculateLayout()
|
||||||
{
|
{
|
||||||
|
@ -308,12 +317,12 @@ void _ui_drawVFOMiddle(state_t* last_state)
|
||||||
freq1_pos = layout.line2_pos;
|
freq1_pos = layout.line2_pos;
|
||||||
freq2_pos = layout.line3_pos;
|
freq2_pos = layout.line3_pos;
|
||||||
}
|
}
|
||||||
snprintf(freq_buf, sizeof(freq_buf), "Rx: %03lu.%05lu",
|
snprintf(freq_buf, sizeof(freq_buf), " Rx:%03lu.%05lu",
|
||||||
last_state->channel.rx_frequency/1000000,
|
last_state->channel.rx_frequency/1000000,
|
||||||
last_state->channel.rx_frequency%1000000/10);
|
last_state->channel.rx_frequency%1000000/10);
|
||||||
gfx_print(freq1_pos, freq_buf, layout.line1_font, TEXT_ALIGN_CENTER,
|
gfx_print(freq1_pos, freq_buf, layout.line1_font, TEXT_ALIGN_CENTER,
|
||||||
color_white);
|
color_white);
|
||||||
snprintf(freq_buf, sizeof(freq_buf), "Tx: %03lu.%05lu",
|
snprintf(freq_buf, sizeof(freq_buf), " Tx:%03lu.%05lu",
|
||||||
last_state->channel.tx_frequency/1000000,
|
last_state->channel.tx_frequency/1000000,
|
||||||
last_state->channel.tx_frequency%1000000/10);
|
last_state->channel.tx_frequency%1000000/10);
|
||||||
gfx_print(freq2_pos, freq_buf, layout.line2_font, TEXT_ALIGN_CENTER,
|
gfx_print(freq2_pos, freq_buf, layout.line2_font, TEXT_ALIGN_CENTER,
|
||||||
|
@ -322,8 +331,6 @@ void _ui_drawVFOMiddle(state_t* last_state)
|
||||||
|
|
||||||
void _ui_drawVFOMiddleInput(state_t* last_state)
|
void _ui_drawVFOMiddleInput(state_t* last_state)
|
||||||
{
|
{
|
||||||
// Print VFO frequencies
|
|
||||||
char freq_buf[14] = "";
|
|
||||||
point_t freq1_pos = {0,0};
|
point_t freq1_pos = {0,0};
|
||||||
point_t freq2_pos = {0,0};
|
point_t freq2_pos = {0,0};
|
||||||
// On radios with 2 rows display use line 1 and 2
|
// On radios with 2 rows display use line 1 and 2
|
||||||
|
@ -338,21 +345,42 @@ void _ui_drawVFOMiddleInput(state_t* last_state)
|
||||||
freq1_pos = layout.line2_pos;
|
freq1_pos = layout.line2_pos;
|
||||||
freq2_pos = layout.line3_pos;
|
freq2_pos = layout.line3_pos;
|
||||||
}
|
}
|
||||||
// Replace Rx frequency with underscorses
|
// Add inserted number to string, skipping "Rx: "/"Tx: " and "."
|
||||||
if(input_position == 0)
|
uint8_t insert_pos = input_position + 3;
|
||||||
snprintf(new_rx_freq_buf, sizeof(new_rx_freq_buf), "Rx: ___._____");
|
if(input_position > 3) insert_pos += 1;
|
||||||
// Add inserted number to string, skipping "Rx: " and "."
|
|
||||||
uint8_t insert_pos = input_position + 4;
|
|
||||||
if(input_position >= 3) insert_pos += 1;
|
|
||||||
char input_char = input_number + '0';
|
char input_char = input_number + '0';
|
||||||
new_rx_freq_buf[insert_pos] = input_char;
|
char freq_buf[14] = "";
|
||||||
gfx_print(freq1_pos, new_rx_freq_buf, layout.line1_font, TEXT_ALIGN_CENTER,
|
|
||||||
color_white);
|
if(input_set == SET_RX)
|
||||||
snprintf(freq_buf, sizeof(freq_buf), "Tx: %03lu.%05lu",
|
{
|
||||||
last_state->channel.tx_frequency/1000000,
|
// Replace Rx frequency with underscorses
|
||||||
last_state->channel.tx_frequency%1000000/10);
|
if(input_position <= 1)
|
||||||
gfx_print(freq2_pos, freq_buf, layout.line2_font, TEXT_ALIGN_CENTER,
|
snprintf(new_rx_freq_buf, sizeof(new_rx_freq_buf), ">Rx:___._____");
|
||||||
color_white);
|
if(input_position >= 1)
|
||||||
|
new_rx_freq_buf[insert_pos] = input_char;
|
||||||
|
gfx_print(freq1_pos, new_rx_freq_buf, layout.line1_font, TEXT_ALIGN_CENTER,
|
||||||
|
color_white);
|
||||||
|
snprintf(freq_buf, sizeof(freq_buf), " Tx:%03lu.%05lu",
|
||||||
|
last_state->channel.tx_frequency/1000000,
|
||||||
|
last_state->channel.tx_frequency%1000000/10);
|
||||||
|
gfx_print(freq2_pos, freq_buf, layout.line2_font, TEXT_ALIGN_CENTER,
|
||||||
|
color_white);
|
||||||
|
}
|
||||||
|
else if(input_set == SET_TX)
|
||||||
|
{
|
||||||
|
// Replace Rx frequency with underscorses
|
||||||
|
if(input_position == 0)
|
||||||
|
snprintf(new_tx_freq_buf, sizeof(new_tx_freq_buf), ">Tx:___._____");
|
||||||
|
if(input_position >= 1)
|
||||||
|
new_tx_freq_buf[insert_pos] = input_char;
|
||||||
|
snprintf(freq_buf, sizeof(freq_buf), " Rx:%03lu.%05lu",
|
||||||
|
new_rx_frequency/1000000,
|
||||||
|
new_rx_frequency%1000000/10);
|
||||||
|
gfx_print(freq1_pos, freq_buf, layout.line2_font, TEXT_ALIGN_CENTER,
|
||||||
|
color_white);
|
||||||
|
gfx_print(freq2_pos, new_tx_freq_buf, layout.line1_font, TEXT_ALIGN_CENTER,
|
||||||
|
color_white);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _ui_drawVFOBottom()
|
void _ui_drawVFOBottom()
|
||||||
|
@ -544,41 +572,100 @@ void ui_updateFSM(event_t event, bool *sync_rtx)
|
||||||
{
|
{
|
||||||
// Open Frequency input screen
|
// Open Frequency input screen
|
||||||
state.ui_screen = VFO_INPUT;
|
state.ui_screen = VFO_INPUT;
|
||||||
// Reset input position
|
// Reset input position and selection
|
||||||
input_position = 0;
|
input_position = 1;
|
||||||
|
input_set = SET_RX;
|
||||||
// Save pressed number to calculare frequency and show in GUI
|
// Save pressed number to calculare frequency and show in GUI
|
||||||
input_number = input_getPressedNumber(msg);
|
input_number = input_getPressedNumber(msg);
|
||||||
// Calculate portion of the new frequency
|
// Calculate portion of the new frequency
|
||||||
new_rx_frequency = input_number * pow(10,(FREQ_DIGITS - input_position));
|
new_rx_frequency = input_number *
|
||||||
|
pow(10,(FREQ_DIGITS - input_position + 1));
|
||||||
|
new_tx_frequency = 0;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
// VFO frequency input screen
|
// VFO frequency input screen
|
||||||
case VFO_INPUT:
|
case VFO_INPUT:
|
||||||
if(msg.keys & KEY_ENTER)
|
if(msg.keys & KEY_ENTER)
|
||||||
{
|
{
|
||||||
// Save inserted frequency
|
// Switch to TX input
|
||||||
state.channel.rx_frequency = new_rx_frequency;
|
if(input_set == SET_RX)
|
||||||
state.ui_screen = VFO_MAIN;
|
{
|
||||||
|
input_set = SET_TX;
|
||||||
|
// Reset input position
|
||||||
|
input_position = 0;
|
||||||
|
}
|
||||||
|
else if(input_set == SET_TX)
|
||||||
|
{
|
||||||
|
// Save new frequency setting
|
||||||
|
// If TX frequency was not set, TX = RX
|
||||||
|
if(new_tx_frequency == 0)
|
||||||
|
{
|
||||||
|
state.channel.rx_frequency = new_rx_frequency;
|
||||||
|
state.channel.tx_frequency = new_rx_frequency;
|
||||||
|
}
|
||||||
|
// Otherwise set both frequencies
|
||||||
|
else
|
||||||
|
{
|
||||||
|
state.channel.rx_frequency = new_rx_frequency;
|
||||||
|
state.channel.tx_frequency = new_tx_frequency;
|
||||||
|
}
|
||||||
|
state.ui_screen = VFO_MAIN;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if(msg.keys & KEY_ESC)
|
else if(msg.keys & KEY_ESC)
|
||||||
{
|
{
|
||||||
state.ui_screen = VFO_MAIN;
|
state.ui_screen = VFO_MAIN;
|
||||||
}
|
}
|
||||||
|
else if(msg.keys & KEY_UP || msg.keys & KEY_DOWN)
|
||||||
|
{
|
||||||
|
if(input_set == SET_RX)
|
||||||
|
{
|
||||||
|
input_set = SET_TX;
|
||||||
|
// Reset TX frequency
|
||||||
|
new_tx_frequency = 0;
|
||||||
|
}
|
||||||
|
else if(input_set == SET_TX)
|
||||||
|
{
|
||||||
|
input_set = SET_RX;
|
||||||
|
// Reset RX frequency
|
||||||
|
new_rx_frequency = 0;
|
||||||
|
}
|
||||||
|
// Reset input position
|
||||||
|
input_position = 0;
|
||||||
|
}
|
||||||
else if(input_isNumberPressed(msg))
|
else if(input_isNumberPressed(msg))
|
||||||
{
|
{
|
||||||
// Advance input position
|
// Advance input position
|
||||||
input_position += 1;
|
input_position += 1;
|
||||||
// Save pressed number to calculare frequency and show in GUI
|
// Save pressed number to calculare frequency and show in GUI
|
||||||
input_number = input_getPressedNumber(msg);
|
input_number = input_getPressedNumber(msg);
|
||||||
// Calculate portion of the new frequency
|
if(input_set == SET_RX)
|
||||||
new_rx_frequency += input_number * pow(10,(FREQ_DIGITS - input_position));
|
|
||||||
if(input_position >= (FREQ_DIGITS - 1))
|
|
||||||
{
|
{
|
||||||
// Save inserted frequency
|
// Calculate portion of the new RX frequency
|
||||||
freq_t offset = state.channel.rx_frequency - state.channel.tx_frequency;
|
new_rx_frequency += input_number *
|
||||||
state.channel.rx_frequency = new_rx_frequency;
|
pow(10,(FREQ_DIGITS - input_position + 1));
|
||||||
state.channel.tx_frequency = new_rx_frequency + offset;
|
if(input_position >= (FREQ_DIGITS))
|
||||||
state.ui_screen = VFO_MAIN;
|
{
|
||||||
|
// Switch to TX input
|
||||||
|
input_set = SET_TX;
|
||||||
|
// Reset input position
|
||||||
|
input_position = 0;
|
||||||
|
// Reset TX frequency
|
||||||
|
new_tx_frequency = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(input_set == SET_TX)
|
||||||
|
{
|
||||||
|
// Calculate portion of the new TX frequency
|
||||||
|
new_tx_frequency += input_number *
|
||||||
|
pow(10,(FREQ_DIGITS - input_position + 1));
|
||||||
|
if(input_position >= (FREQ_DIGITS))
|
||||||
|
{
|
||||||
|
// Save both inserted frequencies
|
||||||
|
state.channel.rx_frequency = new_rx_frequency;
|
||||||
|
state.channel.tx_frequency = new_tx_frequency;
|
||||||
|
state.ui_screen = VFO_MAIN;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
Ładowanie…
Reference in New Issue