kopia lustrzana https://github.com/OpenRTX/OpenRTX
UI: removed use of floats when displaying VFO frequency, offset and step
rodzic
49c99acf85
commit
c0115c14b3
|
@ -190,11 +190,16 @@ void _ui_drawModeInfo(ui_state_t* ui_state)
|
||||||
|
|
||||||
void _ui_drawFrequency()
|
void _ui_drawFrequency()
|
||||||
{
|
{
|
||||||
unsigned long frequency = platform_getPttStatus() ? last_state.channel.tx_frequency
|
freq_t freq = platform_getPttStatus() ? last_state.channel.tx_frequency
|
||||||
: last_state.channel.rx_frequency;
|
: last_state.channel.rx_frequency;
|
||||||
|
|
||||||
// Print big numbers frequency
|
// Print big numbers frequency
|
||||||
|
char freq_str[16] = {0};
|
||||||
|
snprintf(freq_str, sizeof(freq_str), "%lu.%lu", (freq / 1000000), (freq % 1000000));
|
||||||
|
stripTrailingZeroes(freq_str);
|
||||||
|
|
||||||
gfx_print(layout.line3_large_pos, layout.line3_large_font, TEXT_ALIGN_CENTER,
|
gfx_print(layout.line3_large_pos, layout.line3_large_font, TEXT_ALIGN_CENTER,
|
||||||
color_white, "%.7g", (float) frequency / 1000000.0f);
|
color_white, "%s", freq_str);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _ui_drawVFOMiddleInput(ui_state_t* ui_state)
|
void _ui_drawVFOMiddleInput(ui_state_t* ui_state)
|
||||||
|
|
|
@ -349,29 +349,61 @@ int _ui_getRadioValueName(char *buf, uint8_t max_len, uint8_t index)
|
||||||
if(index >= settings_radio_num)
|
if(index >= settings_radio_num)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
int32_t offset = 0;
|
// Only returning the sign
|
||||||
|
if(index == R_DIRECTION)
|
||||||
|
{
|
||||||
|
buf[0] = (last_state.channel.tx_frequency >= last_state.channel.rx_frequency) ? '+' : '-';
|
||||||
|
buf[1] = '\0';
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return an x.y string
|
||||||
|
uint32_t value = 0;
|
||||||
switch(index)
|
switch(index)
|
||||||
{
|
{
|
||||||
case R_OFFSET:
|
case R_OFFSET:
|
||||||
offset = abs((int32_t)last_state.channel.tx_frequency -
|
{
|
||||||
(int32_t)last_state.channel.rx_frequency);
|
uint32_t txFreq = last_state.channel.tx_frequency;
|
||||||
snprintf(buf, max_len, "%gMHz", (float) offset / 1000000.0f);
|
uint32_t rxFreq = last_state.channel.rx_frequency;
|
||||||
break;
|
|
||||||
|
|
||||||
case R_DIRECTION:
|
// Yes, we're basically reinventing the abs() here. The problem is
|
||||||
buf[0] = (last_state.channel.tx_frequency >= last_state.channel.rx_frequency) ? '+' : '-';
|
// that abs() works on signed integers and using it would mean
|
||||||
buf[1] = '\0';
|
// casting values back and forth between signed and unsigned.
|
||||||
|
if(txFreq > rxFreq)
|
||||||
|
value = txFreq - rxFreq;
|
||||||
|
else
|
||||||
|
value = rxFreq - txFreq;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case R_STEP:
|
case R_STEP:
|
||||||
// Print in kHz if it is smaller than 1MHz
|
value = freq_steps[last_state.step_index];
|
||||||
if (freq_steps[last_state.step_index] < 1000000)
|
|
||||||
snprintf(buf, max_len, "%gkHz", (float) freq_steps[last_state.step_index] / 1000.0f);
|
|
||||||
else
|
|
||||||
snprintf(buf, max_len, "%gMHz", (float) freq_steps[last_state.step_index] / 1000000.0f);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint32_t div = 1;
|
||||||
|
char prefix = ' ';
|
||||||
|
|
||||||
|
if(value >= 1000000)
|
||||||
|
{
|
||||||
|
prefix = 'M';
|
||||||
|
div = 1000000;
|
||||||
|
}
|
||||||
|
else if(value >= 1000)
|
||||||
|
{
|
||||||
|
prefix = 'k';
|
||||||
|
div = 1000;
|
||||||
|
}
|
||||||
|
|
||||||
|
// NOTE: casts are there only to squelch -Wformat warnings on the
|
||||||
|
// snprintf.
|
||||||
|
char str[16];
|
||||||
|
snprintf(str, sizeof(str), "%u.%u", (unsigned int)(value / div),
|
||||||
|
(unsigned int)(value % div));
|
||||||
|
stripTrailingZeroes(str);
|
||||||
|
snprintf(buf, max_len, "%s%cHz", str, prefix);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -973,16 +1005,28 @@ void _ui_drawSettingsRadio(ui_state_t* ui_state)
|
||||||
gfx_drawRect(rect_origin, rect_width, rect_height, color_white, false);
|
gfx_drawRect(rect_origin, rect_width, rect_height, color_white, false);
|
||||||
|
|
||||||
// Print frequency with the most sensible unit
|
// Print frequency with the most sensible unit
|
||||||
if (ui_state->new_offset < 1000)
|
char prefix = ' ';
|
||||||
snprintf(buf, 17, "%dHz", ui_state->new_offset);
|
uint32_t div = 1;
|
||||||
else if (ui_state->new_offset < 1000000)
|
if(ui_state->new_offset >= 1000000)
|
||||||
snprintf(buf, 17, "%gkHz", (float) ui_state->new_offset / 1000.0f);
|
{
|
||||||
else
|
prefix = 'M';
|
||||||
snprintf(buf, 17, "%gMHz", (float) ui_state->new_offset / 1000000.0f);
|
div = 1000000;
|
||||||
|
}
|
||||||
|
else if(ui_state->new_offset >= 1000)
|
||||||
|
{
|
||||||
|
prefix = 'k';
|
||||||
|
div = 1000;
|
||||||
|
}
|
||||||
|
|
||||||
|
// NOTE: casts are there only to squelch -Wformat warnings on the
|
||||||
|
// snprintf.
|
||||||
|
snprintf(buf, sizeof(buf), "%u.%u", (unsigned int)(ui_state->new_offset / div),
|
||||||
|
(unsigned int)(ui_state->new_offset % div));
|
||||||
|
stripTrailingZeroes(buf);
|
||||||
|
|
||||||
gfx_printLine(1, 1, layout.top_h, CONFIG_SCREEN_HEIGHT - layout.bottom_h,
|
gfx_printLine(1, 1, layout.top_h, CONFIG_SCREEN_HEIGHT - layout.bottom_h,
|
||||||
layout.horizontal_pad, layout.input_font,
|
layout.horizontal_pad, layout.input_font,
|
||||||
TEXT_ALIGN_CENTER, color_white, buf);
|
TEXT_ALIGN_CENTER, color_white, "%s%cHz", buf, prefix);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
Ładowanie…
Reference in New Issue