diff --git a/App/app/main.c b/App/app/main.c index 76d88219..28764407 100644 --- a/App/app/main.c +++ b/App/app/main.c @@ -556,10 +556,10 @@ static void MAIN_Key_DIGITS(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld) return; } - gKeyInputCountdown = (gInputBoxIndex >= totalDigits) ? (key_input_timeout_500ms / 16) : (key_input_timeout_500ms / 3); + gKeyInputCountdown = key_input_timeout_500ms / (gInputBoxIndex >= totalDigits ? 16 : 3); if (gInputBoxIndex > totalDigits) { - gInputBoxIndex = totalDigits; + gInputBoxIndex = totalDigits; return; } @@ -570,11 +570,8 @@ static void MAIN_Key_DIGITS(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld) // convert to int uint32_t inputFreq = StrToUL(inputStr); - // how many zero to add - uint8_t zerosToAdd = totalDigits - inputLength; - // add missing zero - for (uint8_t i = 0; i < zerosToAdd; i++) { + for (uint8_t i = 0; i < totalDigits - inputLength; i++) { inputFreq *= 10; } diff --git a/App/app/menu.c b/App/app/menu.c index 646a956a..8f160f9f 100644 --- a/App/app/menu.c +++ b/App/app/menu.c @@ -1586,7 +1586,7 @@ static void MENU_Key_0_to_9(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld) gInputBoxIndex = 0; //Value = ((gInputBox[0] * 100) + (gInputBox[1] * 10) + gInputBox[2]) - 1; - Value = ((gInputBox[0] * 1000) + (gInputBox[1] * 100) + (gInputBox[2] * 10) + gInputBox[3]) - 1; + Value = (((gInputBox[0] * 10 + gInputBox[1]) * 10 + gInputBox[2]) * 10 + gInputBox[3]) - 1; if (IS_MR_CHANNEL(Value)) { diff --git a/App/app/scanner.c b/App/app/scanner.c index 4c7cad7a..afb806ff 100644 --- a/App/app/scanner.c +++ b/App/app/scanner.c @@ -62,7 +62,7 @@ static void SCANNER_Key_DIGITS(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld) gInputBoxIndex = 0; // uint16_t chan = ((gInputBox[0] * 100) + (gInputBox[1] * 10) + gInputBox[2]) - 1; - uint16_t chan = ((gInputBox[0] * 1000) + (gInputBox[1] * 100) + (gInputBox[2] * 10) + gInputBox[3]) - 1; + uint16_t chan = (((gInputBox[0] * 10 + gInputBox[1]) * 10 + gInputBox[2]) * 10 + gInputBox[3]) - 1; if (IS_MR_CHANNEL(chan)) { #ifdef ENABLE_VOICE gAnotherVoiceID = (VOICE_ID_t)Key; diff --git a/App/radio.c b/App/radio.c index eee9a34a..c20704cb 100644 --- a/App/radio.c +++ b/App/radio.c @@ -242,13 +242,9 @@ void RADIO_ValidateAndSetCode(FREQ_Config_t *pFreq_Config, uint8_t tmp) { break; case CODE_TYPE_CONTINUOUS_TONE: - if (tmp > (ARRAY_SIZE(CTCSS_Options) - 1)) - tmp = 0; - break; - case CODE_TYPE_DIGITAL: case CODE_TYPE_REVERSE_DIGITAL: - if (tmp > (ARRAY_SIZE(DCS_Options) - 1)) + if (tmp > ((pFreq_Config->CodeType == CODE_TYPE_CONTINUOUS_TONE ? ARRAY_SIZE(CTCSS_Options) : ARRAY_SIZE(DCS_Options)) - 1)) tmp = 0; break; } @@ -586,30 +582,15 @@ void RADIO_ConfigureSquelchAndOutputPower(VFO_Info_t *pInfo) uint8_t Op = 0; // Low eeprom calibration data uint8_t currentPower = pInfo->OUTPUT_POWER; - if(currentPower == OUTPUT_POWER_USER) - { - if(gSetting_set_pwr == 5) - { - Op = 1; // Mid eeprom calibration data - } - else if(gSetting_set_pwr == 6) - { - Op = 2; // High eeprom calibration data - } + if (currentPower == OUTPUT_POWER_USER) currentPower = gSetting_set_pwr; - } else - { - if (currentPower == OUTPUT_POWER_MID) - { - Op = 1; // Mid eeprom calibration data - } - else if(currentPower == OUTPUT_POWER_HIGH) - { - Op = 2; // High eeprom calibration data - } currentPower--; - } + + if (currentPower == 5) + Op = 1; // Mid eeprom calibration data + else if (currentPower == 6) + Op = 2; // High eeprom calibration data PY25Q16_ReadBuffer(0x100D0 + (Band * 16) + (Op * 3), Txp, 3); diff --git a/App/settings.c b/App/settings.c index cd2bec22..a66766f2 100644 --- a/App/settings.c +++ b/App/settings.c @@ -218,9 +218,12 @@ gEeprom.FreqChannel[1] = IS_FREQ_CHANNEL(Data16[5]) ? Data16[5] : (FREQ_CHANNE gEeprom.FM_Band = fmCfg.band; //gEeprom.FM_Space = fmCfg.space; + + uint16_t freqLoLimit = BK1080_GetFreqLoLimit(gEeprom.FM_Band); + gEeprom.FM_SelectedFrequency = - (fmCfg.selFreq >= BK1080_GetFreqLoLimit(gEeprom.FM_Band) && fmCfg.selFreq <= BK1080_GetFreqHiLimit(gEeprom.FM_Band)) ? - fmCfg.selFreq : BK1080_GetFreqLoLimit(gEeprom.FM_Band); + (fmCfg.selFreq >= freqLoLimit && fmCfg.selFreq <= BK1080_GetFreqHiLimit(gEeprom.FM_Band)) ? + fmCfg.selFreq : freqLoLimit; gEeprom.FM_SelectedChannel = fmCfg.selChn; gEeprom.FM_IsMrMode = fmCfg.isMrMode; @@ -294,51 +297,35 @@ gEeprom.FreqChannel[1] = IS_FREQ_CHANNEL(Data16[5]) ? Data16[5] : (FREQ_CHANNE PY25Q16_ReadBuffer(0x00A0A8 + 0x48, Data, 8); gEeprom.DTMF_CODE_PERSIST_TIME = (Data[0] < 101) ? Data[0] * 10 : 100; gEeprom.DTMF_CODE_INTERVAL_TIME = (Data[1] < 101) ? Data[1] * 10 : 100; + + void SETTINGS_LoadEepromDtmf(uint32_t addr, char *dest, size_t size, const char *default_val) { + PY25Q16_ReadBuffer(addr, Data, size); + + if (DTMF_ValidateCodes((char *)Data, size)) { + memcpy(dest, Data, size); + } else { + strcpy(dest, default_val); + } + } + #ifdef ENABLE_DTMF_CALLING gEeprom.PERMIT_REMOTE_KILL = (Data[2] < 2) ? Data[2] : true; // 0EE0..0EE7 - - PY25Q16_ReadBuffer(0x00A0F8, Data, sizeof(gEeprom.ANI_DTMF_ID)); - if (DTMF_ValidateCodes((char *)Data, sizeof(gEeprom.ANI_DTMF_ID))) { - memcpy(gEeprom.ANI_DTMF_ID, Data, sizeof(gEeprom.ANI_DTMF_ID)); - } else { - strcpy(gEeprom.ANI_DTMF_ID, "123"); - } - + SETTINGS_LoadEepromDtmf(0x00A0F8, gEeprom.ANI_DTMF_ID, sizeof(gEeprom.ANI_DTMF_ID), "123"); // 0EE8..0EEF - PY25Q16_ReadBuffer(0x00A0F8 + 0x8, Data, sizeof(gEeprom.KILL_CODE)); - if (DTMF_ValidateCodes((char *)Data, sizeof(gEeprom.KILL_CODE))) { - memcpy(gEeprom.KILL_CODE, Data, sizeof(gEeprom.KILL_CODE)); - } else { - strcpy(gEeprom.KILL_CODE, "ABCD9"); - } + SETTINGS_LoadEepromDtmf(0x00A0F8 + 0x08, gEeprom.KILL_CODE, sizeof(gEeprom.KILL_CODE), "ABCD9"); // 0EF0..0EF7 - PY25Q16_ReadBuffer(0x00A0F8 + 0x10, Data, sizeof(gEeprom.REVIVE_CODE)); - if (DTMF_ValidateCodes((char *)Data, sizeof(gEeprom.REVIVE_CODE))) { - memcpy(gEeprom.REVIVE_CODE, Data, sizeof(gEeprom.REVIVE_CODE)); - } else { - strcpy(gEeprom.REVIVE_CODE, "9DCBA"); - } + SETTINGS_LoadEepromDtmf(0x00A0F8 + 0x10, gEeprom.REVIVE_CODE, sizeof(gEeprom.REVIVE_CODE), "9DCBA"); #endif // 0EF8..0F07 - PY25Q16_ReadBuffer(0x00A0F8 + 0x18, Data, sizeof(gEeprom.DTMF_UP_CODE)); - if (DTMF_ValidateCodes((char *)Data, sizeof(gEeprom.DTMF_UP_CODE))) { - memcpy(gEeprom.DTMF_UP_CODE, Data, sizeof(gEeprom.DTMF_UP_CODE)); - } else { - strcpy(gEeprom.DTMF_UP_CODE, "12345"); - } + SETTINGS_LoadEepromDtmf(0x00A0F8 + 0x18, gEeprom.DTMF_UP_CODE, sizeof(gEeprom.DTMF_UP_CODE), "12345"); // 0F08..0F17 - PY25Q16_ReadBuffer(0x00A0F8 + 0x28, Data, sizeof(gEeprom.DTMF_DOWN_CODE)); - if (DTMF_ValidateCodes((char *)Data, sizeof(gEeprom.DTMF_DOWN_CODE))) { - memcpy(gEeprom.DTMF_DOWN_CODE, Data, sizeof(gEeprom.DTMF_DOWN_CODE)); - } else { - strcpy(gEeprom.DTMF_DOWN_CODE, "54321"); - } + SETTINGS_LoadEepromDtmf(0x00A0F8 + 0x28, gEeprom.DTMF_DOWN_CODE, sizeof(gEeprom.DTMF_DOWN_CODE), "54321"); // 0F18..0F1F PY25Q16_ReadBuffer(0x00A130, Data, 8); diff --git a/App/ui/main.c b/App/ui/main.c index 49c0e5b0..aa1d814d 100644 --- a/App/ui/main.c +++ b/App/ui/main.c @@ -973,6 +973,10 @@ void UI_MAIN_TimeSlice500ms(void) // ---------------------------------------- +static void UI_FormatFrequency(uint32_t freq, char *buffer) { + sprintf(buffer, "%3u.%05u", freq / 100000, freq % 100000); +} + void UI_DisplayMain(void) { char String[22]; @@ -1066,9 +1070,9 @@ void UI_DisplayMain(void) } UI_PrintString("ScnRng", 5, 0, line + shift, 8); - sprintf(String, "%3u.%05u", gScanRangeStart / 100000, gScanRangeStart % 100000); + UI_FormatFrequency(gScanRangeStart, String); UI_PrintStringSmallNormal(String, 56, 0, line + shift); - sprintf(String, "%3u.%05u", gScanRangeStop / 100000, gScanRangeStop % 100000); + UI_FormatFrequency(gScanRangeStop, String); UI_PrintStringSmallNormal(String, 56, 0, line + shift + 1); if (!isMainOnly()) @@ -1080,9 +1084,9 @@ void UI_DisplayMain(void) } #else UI_PrintString("ScnRng", 5, 0, line, 8); - sprintf(String, "%3u.%05u", gScanRangeStart / 100000, gScanRangeStart % 100000); + UI_FormatFrequency(gScanRangeStart, String); UI_PrintStringSmallNormal(String, 56, 0, line); - sprintf(String, "%3u.%05u", gScanRangeStop / 100000, gScanRangeStop % 100000); + UI_FormatFrequency(gScanRangeStop, String); UI_PrintStringSmallNormal(String, 56, 0, line + 1); continue; #endif @@ -1381,29 +1385,22 @@ void UI_DisplayMain(void) const ChannelAttributes_t* att = MR_GetChannelAttributes(gEeprom.ScreenChannel[vfo_num]); + const char *displayStr; + uint8_t xStart = 113; // 3-char name aligned left if(att->exclude == false) { // show the scan list assigment symbols - const ChannelAttributes_t* att = MR_GetChannelAttributes(gEeprom.ScreenChannel[vfo_num]); - uint8_t countList = att->scanlist; if(countList > MR_CHANNELS_LIST + 1) { countList = 0; } - const char *displayStr; - uint8_t xStart, xDisplay; - if (countList == MR_CHANNELS_LIST + 1) { displayStr = "ALL"; - xStart = 113; - xDisplay = 115; } else if (countList == 0) { displayStr = "OFF"; - xStart = 113; - xDisplay = 115; } else { // List 1 to MR_CHANNELS_LIST @@ -1413,41 +1410,27 @@ void UI_DisplayMain(void) if (IsEmptyName(name, sizeof(gListName[0]))) { sprintf(String, "%02d", countList); xStart = 117; // 2-digit number aligned right - xDisplay = 119; } else { sprintf(String, "%.3s", name); - xStart = 113; // 3-char name aligned left - xDisplay = 115; } displayStr = String; } - - GUI_DisplaySmallest(displayStr, xDisplay, line == 0 ? 1 : 33, false, true); - - gFrameBuffer[line][xStart] ^= 0x3E; - for (uint8_t x = xStart + 1; x < 127; x++) { - gFrameBuffer[line][x] ^= 0x7F; - } - gFrameBuffer[line][127] ^= 0x3E; - } else { - const char *displayStr = "EX"; - - uint8_t xStart = 117; - uint8_t xDisplay = 119; - - GUI_DisplaySmallest(displayStr, xDisplay, line == 0 ? 1 : 33, false, true); - - gFrameBuffer[line][xStart] ^= 0x3E; - for (uint8_t x = xStart + 1; x < 127; x++) { - gFrameBuffer[line][x] ^= 0x7F; - } - gFrameBuffer[line][127] ^= 0x3E; + displayStr = "EX"; + xStart = 117; } + GUI_DisplaySmallest(displayStr, xStart + 2, line == 0 ? 1 : 33, false, true); + + gFrameBuffer[line][xStart] ^= 0x3E; + for (uint8_t x = xStart + 1; x < 127; x++) { + gFrameBuffer[line][x] ^= 0x7F; + } + gFrameBuffer[line][127] ^= 0x3E; + #ifdef ENABLE_FEAT_F4HWN_RESCUE_OPS { } @@ -1465,7 +1448,7 @@ void UI_DisplayMain(void) switch (gEeprom.CHANNEL_DISPLAY_MODE) { case MDF_FREQUENCY: // show the channel frequency - sprintf(String, "%3u.%05u", frequency / 100000, frequency % 100000); + UI_FormatFrequency(frequency, String); #ifdef ENABLE_BIG_FREQ if(frequency < _1GHz_in_KHz) { // show the remaining 2 small frequency digits @@ -1525,7 +1508,7 @@ void UI_DisplayMain(void) #ifdef ENABLE_FEAT_F4HWN if (isMainOnly()) { - sprintf(String, "%3u.%05u", frequency / 100000, frequency % 100000); + UI_FormatFrequency(frequency, String); if(frequency < _1GHz_in_KHz) { // show the remaining 2 small frequency digits UI_PrintStringSmallNormal(String + 7, 113, 0, line + 4); @@ -1555,7 +1538,7 @@ void UI_DisplayMain(void) } else { // frequency mode - sprintf(String, "%3u.%05u", frequency / 100000, frequency % 100000); + UI_FormatFrequency(frequency, String); #ifdef ENABLE_BIG_FREQ if(frequency < _1GHz_in_KHz) {