0
mirror of https://github.com/OneOfEleven/uv-k5-firmware-custom.git synced 2025-04-28 14:21:25 +03:00

trim away trailing zeros compile option

This commit is contained in:
OneOfEleven 2023-10-23 11:46:51 +01:00
parent 0d36e997d4
commit 74f52f9d14
7 changed files with 52 additions and 21 deletions

View File

@ -37,6 +37,7 @@ ENABLE_PWRON_PASSWORD := 0
ENABLE_RESET_AES_KEY := 1
ENABLE_BIG_FREQ := 0
ENABLE_SMALL_BOLD := 0
ENABLE_TRIM_TRAILING_ZEROS := 1
ENABLE_KEEP_MEM_NAME := 1
ENABLE_WIDE_RX := 1
ENABLE_TX_WHEN_AM := 0
@ -304,6 +305,9 @@ endif
ifeq ($(ENABLE_SMALL_BOLD),1)
CFLAGS += -DENABLE_SMALL_BOLD
endif
ifeq ($(ENABLE_TRIM_TRAILING_ZEROS),1)
CFLAGS += -DENABLE_TRIM_TRAILING_ZEROS
endif
ifeq ($(ENABLE_NOAA),1)
CFLAGS += -DENABLE_NOAA
endif

View File

@ -59,6 +59,7 @@ ENABLE_PWRON_PASSWORD := 0 include power-on password code
ENABLE_RESET_AES_KEY := 1 '1' = reset/clear the AES key stored in the eeprom (only if it's set)
ENABLE_BIG_FREQ := 0 big font frequencies (like original QS firmware)
ENABLE_SMALL_BOLD := 1 bold channel name/no. (when name + freq channel display mode)
ENABLE_TRIM_TRAILING_ZEROS := 1 trim away any trailing zeros on frequencies
ENABLE_KEEP_MEM_NAME := 1 maintain channel name when (re)saving memory channel
ENABLE_WIDE_RX := 1 full 18MHz to 1300MHz RX (though front-end/PA not designed for full range)
ENABLE_TX_WHEN_AM := 0 allow TX (always FM) when RX is set to AM

10
misc.c
View File

@ -341,3 +341,13 @@ int32_t NUMBER_AddWithWraparound(int32_t Base, int32_t Add, int32_t LowerLimit,
return Base;
}
void NUMBER_trim_trailing_zeros(char *str)
{
if (str != NULL)
{
int i = (int)strlen(str) - 1;
while (i > 0 && (str[i] == '0' || str[i] == ' ') && str[i - 1] != '.')
str[i--] = 0;
}
}

1
misc.h
View File

@ -352,6 +352,7 @@ unsigned int get_RX_VFO(void);
void NUMBER_Get(char *pDigits, uint32_t *pInteger);
void NUMBER_ToDigits(uint32_t Value, char *pDigits);
int32_t NUMBER_AddWithWraparound(int32_t Base, int32_t Add, int32_t LowerLimit, int32_t UpperLimit);
void NUMBER_trim_trailing_zeros(char *str);
#endif

View File

@ -99,20 +99,21 @@ void UI_print_string(
const unsigned int font_size,
const unsigned int char_width)
{
const unsigned int char_spacing = char_width + 1;
const unsigned int char_pitch = char_width + 1;
const size_t length = strlen(str);
unsigned int i;
uint8_t *f_buf;
if (end > start)
start += ((end - start) - (length * char_spacing)) / 2;
start += ((end - start) - (length * char_pitch)) / 2;
f_buf = g_frame_buffer[line] + start;
for (i = 0; i < length; i++)
{
const int c = (int)str[i] - ' ';
if (c >= 0 && c < (int)font_size)
memmove(f_buf + (char_spacing * i) + 1, font + (char_width * c), char_width);
memmove(f_buf + (char_pitch * i), font + (char_width * c), char_width);
}
}

View File

@ -643,6 +643,8 @@ void UI_DisplayMain(void)
}
else
{
const unsigned int x = 32;
uint32_t frequency = g_eeprom.vfo_info[vfo_num].p_rx->frequency;
if (g_current_function == FUNCTION_TRANSMIT)
{ // transmitting
@ -663,13 +665,16 @@ void UI_DisplayMain(void)
#ifdef ENABLE_BIG_FREQ
NUMBER_ToDigits(frequency, String);
// show the main large frequency digits
UI_DisplayFrequency(String, 32, line, false, false);
UI_DisplayFrequency(String, x, line, false, false);
// show the remaining 2 small frequency digits
UI_Displaysmall_digits(2, String + 6, 113, line + 1, true);
UI_Displaysmall_digits(2, String + 6, x + 81, line + 1, true);
#else
// show the frequency in the main font
sprintf(String, "%03u.%05u", frequency / 100000, frequency % 100000);
UI_PrintString(String, 32, 0, line, 8);
#ifdef ENABLE_TRIM_TRAILING_ZEROS
NUMBER_trim_trailing_zeros(String);
#endif
UI_PrintString(String, x, 0, line, 8);
#endif
break;
@ -677,7 +682,7 @@ void UI_DisplayMain(void)
case MDF_CHANNEL: // just channel number
sprintf(String, "CH-%03u", g_eeprom.screen_channel[vfo_num] + 1);
UI_PrintString(String, 32, 0, line, 8);
UI_PrintString(String, x, 0, line, 8);
break;
@ -688,26 +693,29 @@ void UI_DisplayMain(void)
if (String[0] == 0)
{ // no channel name available, channel number instead
sprintf(String, "CH-%03u", g_eeprom.screen_channel[vfo_num] + 1);
sprintf(String, "CH-%03u", 1 + g_eeprom.screen_channel[vfo_num]);
}
if (g_eeprom.channel_display_mode == MDF_NAME)
{ // just the name
UI_PrintString(String, 32, 0, line, 8);
UI_PrintString(String, x, 0, line, 8);
}
else
{ // name & frequency
// name
#ifdef ENABLE_SMALL_BOLD
UI_PrintStringSmallBold(String, 32 + 4, 0, line);
UI_PrintStringSmallBold(String, x, 0, line);
#else
UI_PrintStringSmall(String, 32 + 4, 0, line);
UI_PrintStringSmall(String, x, 0, line);
#endif
// frequency
sprintf(String, "%03u.%05u", frequency / 100000, frequency % 100000);
UI_PrintStringSmall(String, 32 + 4, 0, line + 1);
#ifdef ENABLE_TRIM_TRAILING_ZEROS
NUMBER_trim_trailing_zeros(String);
#endif
UI_PrintStringSmall(String, x, 0, line + 1);
}
break;
@ -719,15 +727,24 @@ void UI_DisplayMain(void)
// if (IS_FREQ_CHANNEL(g_eeprom.screen_channel[vfo_num]))
{ // frequency mode
#ifdef ENABLE_BIG_FREQ
NUMBER_ToDigits(frequency, String); // 8 digits
// show the main large frequency digits
UI_DisplayFrequency(String, 32, line, false, false);
UI_DisplayFrequency(String, x, line, false, false);
// show the remaining 2 small frequency digits
UI_Displaysmall_digits(2, String + 6, 113, line + 1, true);
UI_Displaysmall_digits(2, String + 6, x + 81, line + 1, true);
#else
// show the frequency in the main font
sprintf(String, "%03u.%05u", frequency / 100000, frequency % 100000);
UI_PrintString(String, 32, 0, line, 8);
#ifdef ENABLE_TRIM_TRAILING_ZEROS
NUMBER_trim_trailing_zeros(String);
#endif
UI_PrintString(String, x, 0, line, 8);
#endif
}

View File

@ -574,11 +574,8 @@ void UI_DisplayMenu(void)
}
else
{ // kHz
int i;
sprintf(String, "%u.%03u", step / 1000, step % 1000);
i = strlen(String) - 1;
while (i > 0 && String[i] == '0' && String[i - 1] != '.')
String[i--] = 0; // trim trailing zeros away
NUMBER_trim_trailing_zeros(String);
strcat(String, "kHz");
}
break;