From 74f52f9d146f7d6b5c1244e611abab8e7b0efd30 Mon Sep 17 00:00:00 2001 From: OneOfEleven Date: Mon, 23 Oct 2023 11:46:51 +0100 Subject: [PATCH] trim away trailing zeros compile option --- Makefile | 4 ++++ README.md | 1 + misc.c | 10 ++++++++++ misc.h | 1 + ui/helper.c | 9 +++++---- ui/main.c | 43 ++++++++++++++++++++++++++++++------------- ui/menu.c | 5 +---- 7 files changed, 52 insertions(+), 21 deletions(-) diff --git a/Makefile b/Makefile index 2168da4..f2009c2 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/README.md b/README.md index cfb546e..ba5af51 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/misc.c b/misc.c index 3565e4c..0a1c31e 100644 --- a/misc.c +++ b/misc.c @@ -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; + } +} diff --git a/misc.h b/misc.h index dd25b4a..97fe356 100644 --- a/misc.h +++ b/misc.h @@ -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 diff --git a/ui/helper.c b/ui/helper.c index 8d14d92..3e97be1 100644 --- a/ui/helper.c +++ b/ui/helper.c @@ -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 size_t length = strlen(str); + 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); } } diff --git a/ui/main.c b/ui/main.c index b0f32d4..544c87a 100644 --- a/ui/main.c +++ b/ui/main.c @@ -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 } diff --git a/ui/menu.c b/ui/menu.c index 45bf8ac..9460c81 100644 --- a/ui/menu.c +++ b/ui/menu.c @@ -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;