From 2f7042056a6496a78342dc6e7290749d46c40684 Mon Sep 17 00:00:00 2001 From: Krzysiek Egzmont Date: Wed, 18 Oct 2023 20:43:02 +0200 Subject: [PATCH] Display frequencies >=1GHz --- misc.c | 12 ----- misc.h | 1 - ui/aircopy.c | 17 ++++--- ui/fmradio.c | 11 +++-- ui/helper.c | 121 +++++++++----------------------------------------- ui/helper.h | 4 +- ui/inputbox.c | 9 ++++ ui/inputbox.h | 1 + ui/main.c | 58 ++++++++++++++---------- ui/menu.c | 6 +-- 10 files changed, 88 insertions(+), 152 deletions(-) diff --git a/misc.c b/misc.c index 9cf4634..d39c1b2 100644 --- a/misc.c +++ b/misc.c @@ -272,18 +272,6 @@ void NUMBER_Get(char *pDigits, uint32_t *pInteger) *pInteger = Value; } -void NUMBER_ToDigits(uint32_t Value, char *pDigits) -{ - unsigned int i; - for (i = 0; i < 8; i++) - { - const uint32_t Result = Value / 10U; - pDigits[7 - i] = Value - (Result * 10U); - Value = Result; - } - pDigits[8] = 0; -} - int32_t NUMBER_AddWithWraparound(int32_t Base, int32_t Add, int32_t LowerLimit, int32_t UpperLimit) { Base += Add; diff --git a/misc.h b/misc.h index cbf1cce..17e75c2 100644 --- a/misc.h +++ b/misc.h @@ -324,7 +324,6 @@ extern uint8_t gIsLocked; extern volatile uint8_t boot_counter_10ms; 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); #endif diff --git a/ui/aircopy.c b/ui/aircopy.c index 1163275..164c421 100644 --- a/ui/aircopy.c +++ b/ui/aircopy.c @@ -44,12 +44,19 @@ void UI_DisplayAircopy(void) if (gInputBoxIndex == 0) { - NUMBER_ToDigits(gRxVfo->freq_config_RX.Frequency, String); - UI_DisplayFrequency(String, 16, 2, 0, 0); - UI_DisplaySmallDigits(2, String + 6, 97, 3, true); + uint32_t frequency = gRxVfo->freq_config_RX.Frequency; + sprintf(String, "%3u.%05u", frequency / 100000, frequency % 100000); + // show the remaining 2 small frequency digits + UI_PrintStringSmall(String + 7, 97, 0, 3); + String[7] = 0; + // show the main large frequency digits + UI_DisplayFrequency(String, 16, 2, false); + } + else { + const char * ascii = INPUTBOX_GetAscii(); + sprintf(String, "%.3s.%.3s",ascii, ascii + 3); + UI_DisplayFrequency(String, 16, 2, false); } - else - UI_DisplayFrequency(gInputBox, 16, 2, 1, 0); memset(String, 0, sizeof(String)); if (gAirCopyIsSendMode == 0) diff --git a/ui/fmradio.c b/ui/fmradio.c index 9574f5f..d5b5fc8 100644 --- a/ui/fmradio.c +++ b/ui/fmradio.c @@ -90,11 +90,14 @@ void UI_DisplayFM(void) { if (gInputBoxIndex == 0) { - NUMBER_ToDigits(gEeprom.FM_FrequencyPlaying * 10000, String); - UI_DisplayFrequency(String, 23, 4, false, true); + sprintf(String, "%3d.%d", gEeprom.FM_FrequencyPlaying / 10, gEeprom.FM_FrequencyPlaying % 10); + UI_DisplayFrequency(String, 32, 4, true); + } + else { + const char * ascii = INPUTBOX_GetAscii(); + sprintf(String, "%.3s.%.1s",ascii, ascii + 3); + UI_DisplayFrequency(String, 32, 4, false); } - else - UI_DisplayFrequency(gInputBox, 23, 4, true, false); ST7565_BlitFullScreen(); return; diff --git a/ui/helper.c b/ui/helper.c index 11b3545..d013b9b 100644 --- a/ui/helper.c +++ b/ui/helper.c @@ -144,117 +144,40 @@ void UI_PrintStringSmallBuffer(const char *pString, uint8_t *buffer) } } -void UI_DisplayFrequency(const char *pDigits, uint8_t X, uint8_t Y, bool bDisplayLeadingZero, bool bFlag) +void UI_DisplayFrequency(const char *string, uint8_t X, uint8_t Y, bool center) { const unsigned int char_width = 13; uint8_t *pFb0 = gFrameBuffer[Y] + X; uint8_t *pFb1 = pFb0 + 128; bool bCanDisplay = false; - unsigned int i = 0; - - // MHz - while (i < 3) - { - const unsigned int Digit = pDigits[i++]; - if (bDisplayLeadingZero || bCanDisplay || Digit > 0) + + uint8_t len = strlen(string); + for(int i = 0; i < len; i++) { + const char c = string[i]; + if (bCanDisplay || c != ' ') { bCanDisplay = true; - memmove(pFb0, gFontBigDigits[Digit], char_width); - memmove(pFb1, gFontBigDigits[Digit] + char_width, char_width); + if(c>='0' && c<='9') { + memmove(pFb0, gFontBigDigits[c-'0'], char_width); + memmove(pFb1, gFontBigDigits[c-'0'] + char_width, char_width); + } + else if(c=='-') { + memmove(pFb0, gFontBigDigits[10], char_width); + memmove(pFb1, gFontBigDigits[10] + char_width, char_width); + } + else if(c=='.') { + *pFb1 = 0x60; pFb0++; pFb1++; + *pFb1 = 0x60; pFb0++; pFb1++; + *pFb1 = 0x60; pFb0++; pFb1++; + continue; + } + } - else - if (bFlag) - { + else if (center) { pFb0 -= 6; pFb1 -= 6; } pFb0 += char_width; pFb1 += char_width; } - - // decimal point - *pFb1 = 0x60; pFb0++; pFb1++; - *pFb1 = 0x60; pFb0++; pFb1++; - *pFb1 = 0x60; pFb0++; pFb1++; - - // kHz - while (i < 6) - { - const unsigned int Digit = pDigits[i++]; - memmove(pFb0, gFontBigDigits[Digit], char_width); - memmove(pFb1, gFontBigDigits[Digit] + char_width, char_width); - pFb0 += char_width; - pFb1 += char_width; - } -} - -void UI_DisplayFrequencySmall(const char *pDigits, uint8_t X, uint8_t Y, bool bDisplayLeadingZero) -{ - const unsigned int char_width = ARRAY_SIZE(gFontSmall[0]); - const unsigned int spacing = 1 + char_width; - uint8_t *pFb = gFrameBuffer[Y] + X; - bool bCanDisplay = false; - unsigned int i = 0; - - // MHz - while (i < 3) - { - const unsigned int c = pDigits[i++]; - if (bDisplayLeadingZero || bCanDisplay || c > 0) - { - #if 0 - memmove(pFb + 1, gFontSmallDigits[c], char_width); - #else - const unsigned int index = (c < 10) ? '0' - 32 + c : '-' - 32; - memmove(pFb + 1, gFontSmall[index], char_width); - #endif - pFb += spacing; - bCanDisplay = true; - } - } - - // decimal point - pFb++; - pFb++; - *pFb++ = 0x60; - *pFb++ = 0x60; - pFb++; - - // kHz - while (i < 8) - { - const unsigned int c = pDigits[i++]; - #if 0 - memmove(pFb + 1, gFontSmallDigits[c], char_width); - #else - const unsigned int index = (c < 10) ? '0' - 32 + c : '-' - 32; - memmove(pFb + 1, gFontSmall[index], char_width); - #endif - pFb += spacing; - } -} - -void UI_DisplaySmallDigits(const uint8_t size, const char *str, const uint8_t x, const uint8_t y, const bool display_leading_zeros) -{ - const unsigned int char_width = ARRAY_SIZE(gFontSmall[0]); - const unsigned int spacing = 1 + char_width; - bool display = display_leading_zeros; - unsigned int xx; - unsigned int i; - for (i = 0, xx = x; i < size; i++) - { - const unsigned int c = (unsigned int)str[i]; - if (c > 0) - display = true; // non '0' - if (display && c < 11) - { - #if 0 - memmove(gFrameBuffer[y] + xx, gFontSmallDigits[c], char_width); - #else - const unsigned int index = (c < 10) ? '0' - 32 + c : '-' - 32; - memmove(gFrameBuffer[y] + xx + 1, gFontSmall[index], char_width); - #endif - xx += spacing; - } - } } diff --git a/ui/helper.h b/ui/helper.h index 87eb686..11eb16b 100644 --- a/ui/helper.h +++ b/ui/helper.h @@ -28,9 +28,7 @@ void UI_PrintStringSmall(const char *pString, uint8_t Start, uint8_t End, uint8_ void UI_PrintStringSmallBold(const char *pString, uint8_t Start, uint8_t End, uint8_t Line); #endif void UI_PrintStringSmallBuffer(const char *pString, uint8_t *buffer); -void UI_DisplayFrequency(const char *pDigits, uint8_t X, uint8_t Y, bool bDisplayLeadingZero, bool bFlag); -void UI_DisplayFrequencySmall(const char *pDigits, uint8_t X, uint8_t Y, bool bDisplayLeadingZero); -void UI_DisplaySmallDigits(const uint8_t size, const char *str, const uint8_t x, const uint8_t y, const bool display_leading_zeros); +void UI_DisplayFrequency(const char *string, uint8_t X, uint8_t Y, bool center); #endif diff --git a/ui/inputbox.c b/ui/inputbox.c index 3731bb1..39a6596 100644 --- a/ui/inputbox.c +++ b/ui/inputbox.c @@ -19,6 +19,7 @@ #include "ui/inputbox.h" char gInputBox[8]; +char inputBoxAscii[9]; uint8_t gInputBoxIndex; void INPUTBOX_Append(const KEY_Code_t Digit) @@ -33,3 +34,11 @@ void INPUTBOX_Append(const KEY_Code_t Digit) gInputBox[gInputBoxIndex++] = (char)(Digit - KEY_0); } +const char* INPUTBOX_GetAscii() +{ + for(int i = 0; i < 8; i++) { + char c = gInputBox[i]; + inputBoxAscii[i] = (c==10)? '-' : '0' + c; + } + return inputBoxAscii; +} \ No newline at end of file diff --git a/ui/inputbox.h b/ui/inputbox.h index d7a6d2e..eb450ca 100644 --- a/ui/inputbox.h +++ b/ui/inputbox.h @@ -25,6 +25,7 @@ extern char gInputBox[8]; extern uint8_t gInputBoxIndex; void INPUTBOX_Append(const KEY_Code_t Digit); +const char* INPUTBOX_GetAscii(); #endif diff --git a/ui/main.c b/ui/main.c index c8e6b71..308ac67 100644 --- a/ui/main.c +++ b/ui/main.c @@ -408,19 +408,17 @@ void UI_DisplayMain(void) const unsigned int x = 2; const bool inputting = (gInputBoxIndex == 0 || gEeprom.TX_VFO != vfo_num) ? false : true; if (!inputting) - NUMBER_ToDigits(gEeprom.ScreenChannel[vfo_num] + 1, String); // show the memory channel number + sprintf(String, "M%u", gEeprom.ScreenChannel[vfo_num] + 1); else - memmove(String + 5, gInputBox, 3); // show the input text - UI_PrintStringSmall("M", x, 0, line + 1); - UI_DisplaySmallDigits(3, String + 5, x + 7, line + 1, inputting); + sprintf(String, "M%.3s", INPUTBOX_GetAscii()); // show the input text + UI_PrintStringSmall(String, x, 0, line + 1); } else if (IS_FREQ_CHANNEL(gEeprom.ScreenChannel[vfo_num])) { // frequency mode // show the frequency band number - const unsigned int x = 2; // was 14 -// sprintf(String, "FB%u", 1 + gEeprom.ScreenChannel[vfo_num] - FREQ_CHANNEL_FIRST); - sprintf(String, "VFO%u", 1 + gEeprom.ScreenChannel[vfo_num] - FREQ_CHANNEL_FIRST); + const unsigned int x = 2; + sprintf(String, "FB%u", 1 + gEeprom.ScreenChannel[vfo_num] - FREQ_CHANNEL_FIRST); UI_PrintStringSmall(String, x, 0, line + 1); } #ifdef ENABLE_NOAA @@ -460,7 +458,9 @@ void UI_DisplayMain(void) else if (gInputBoxIndex > 0 && IS_FREQ_CHANNEL(gEeprom.ScreenChannel[vfo_num]) && gEeprom.TX_VFO == vfo_num) { // user entering a frequency - UI_DisplayFrequency(gInputBox, 32, line, true, false); + const char * ascii = INPUTBOX_GetAscii(); + sprintf(String, "%.3s.%.3s", ascii, ascii + 3); + UI_DisplayFrequency(String, 32, line, false); // center_line = CENTER_LINE_IN_USE; } @@ -496,17 +496,22 @@ void UI_DisplayMain(void) switch (gEeprom.CHANNEL_DISPLAY_MODE) { case MDF_FREQUENCY: // show the channel frequency - #ifdef ENABLE_BIG_FREQ - NUMBER_ToDigits(frequency, String); - // show the main large frequency digits - UI_DisplayFrequency(String, 32, line, false, false); + sprintf(String, "%3u.%05u", frequency / 100000, frequency % 100000); +#ifdef ENABLE_BIG_FREQ + if(frequency < 100000000) { // show the remaining 2 small frequency digits - UI_DisplaySmallDigits(2, String + 6, 113, line + 1, true); - #else + UI_PrintStringSmall(String + 7, 113, 0, line + 1); + String[7] = 0; + // show the main large frequency digits + UI_DisplayFrequency(String, 32, line, false); + } + else +#endif + { // show the frequency in the main font - sprintf(String, "%03u.%05u", frequency / 100000, frequency % 100000); UI_PrintString(String, 32, 0, line, 8); - #endif + } + break; case MDF_CHANNEL: // show the channel number @@ -545,17 +550,22 @@ void UI_DisplayMain(void) } else { // 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); + sprintf(String, "%3u.%05u", frequency / 100000, frequency % 100000); + +#ifdef ENABLE_BIG_FREQ + if(frequency < 100000000) { // show the remaining 2 small frequency digits - UI_DisplaySmallDigits(2, String + 6, 113, line + 1, true); - #else + UI_PrintStringSmall(String + 7, 113, 0, line + 1); + String[7] = 0; + // show the main large frequency digits + UI_DisplayFrequency(String, 32, line, false); + } + else +#endif + { // show the frequency in the main font - sprintf(String, "%03u.%05u", frequency / 100000, frequency % 100000); UI_PrintString(String, 32, 0, line, 8); - #endif + } // show the channel symbols const uint8_t attributes = gMR_ChannelAttributes[gEeprom.ScreenChannel[vfo_num]]; diff --git a/ui/menu.c b/ui/menu.c index 19884c8..253e442 100644 --- a/ui/menu.c +++ b/ui/menu.c @@ -974,10 +974,8 @@ void UI_DisplayMenu(void) GetCurrentMenuId() == MENU_T_DCS || GetCurrentMenuId() == MENU_D_LIST) { - unsigned int Offset; - NUMBER_ToDigits(gSubMenuSelection, String); - Offset = (GetCurrentMenuId() == MENU_D_LIST) ? 2 : 3; - UI_DisplaySmallDigits(Offset, String + (8 - Offset), 105, 0, false); + sprintf(String, "%2d", gSubMenuSelection); + UI_PrintStringSmall(String, 105, 0, 0); } if ((GetCurrentMenuId() == MENU_RESET ||