diff --git a/App/app/action.c b/App/app/action.c index 1792d474..410ee518 100644 --- a/App/app/action.c +++ b/App/app/action.c @@ -236,7 +236,7 @@ void ACTION_Scan(bool bRestart) } // channel mode. Keep scanning but toggle between scan lists - RADIO_NextValidList(); + RADIO_NextValidList(1); #ifdef ENABLE_FEAT_F4HWN_RESUME_STATE SETTINGS_WriteCurrentState(); diff --git a/App/app/chFrScanner.c b/App/app/chFrScanner.c index 339c389f..f6c6d479 100644 --- a/App/app/chFrScanner.c +++ b/App/app/chFrScanner.c @@ -55,7 +55,7 @@ void CHFRSCANNER_Start(const bool storeBackupSettings, const int8_t scan_directi { if(!RADIO_CheckValidList(gEeprom.SCAN_LIST_DEFAULT)) { - RADIO_NextValidList(); + RADIO_NextValidList(1); } // channel mode diff --git a/App/app/main.c b/App/app/main.c index 0f5323d8..716436e6 100644 --- a/App/app/main.c +++ b/App/app/main.c @@ -291,16 +291,25 @@ static void processFKeyFunction(const KEY_Code_t Key, const bool beep) #ifdef ENABLE_FEAT_F4HWN // Set Squelch F + UP or Down and Step F + SIDE1 or F + SIDE2 case KEY_UP: - gEeprom.SQUELCH_LEVEL = (gEeprom.SQUELCH_LEVEL < 9) ? gEeprom.SQUELCH_LEVEL + 1: 9; - gVfoConfigureMode = VFO_CONFIGURE; - gWasFKeyPressed = false; - break; case KEY_DOWN: - gEeprom.SQUELCH_LEVEL = (gEeprom.SQUELCH_LEVEL > 0) ? gEeprom.SQUELCH_LEVEL - 1: 0; - gVfoConfigureMode = VFO_CONFIGURE; - gWasFKeyPressed = false; - break; + { + int8_t direction = (Key == KEY_UP) ? 1 : -1; + if (gScanStateDir != SCAN_OFF) { + RADIO_NextValidList(direction); + } else { + // Adjust squelch: UP increments, DOWN decrements + if (direction > 0) { + gEeprom.SQUELCH_LEVEL = (gEeprom.SQUELCH_LEVEL < 9) ? gEeprom.SQUELCH_LEVEL + 1 : 9; + } else { + gEeprom.SQUELCH_LEVEL = (gEeprom.SQUELCH_LEVEL > 0) ? gEeprom.SQUELCH_LEVEL - 1 : 0; + } + gVfoConfigureMode = VFO_CONFIGURE; + } + + gWasFKeyPressed = false; + } + break; case KEY_SIDE1: uint8_t a = FREQUENCY_GetSortedIdxFromStepIdx(gTxVfo->STEP_SETTING); if (a < STEP_N_ELEM - 1) @@ -496,7 +505,7 @@ static void MAIN_Key_DIGITS(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld) /* Requested scan list is empty or invalid: jump to the next valid scan list */ gEeprom.SCAN_LIST_DEFAULT = value; - RADIO_NextValidList(); + RADIO_NextValidList(1); } #ifdef ENABLE_FEAT_F4HWN_RESUME_STATE diff --git a/App/radio.c b/App/radio.c index 5ef924ad..008fab87 100644 --- a/App/radio.c +++ b/App/radio.c @@ -102,28 +102,30 @@ bool RADIO_CheckValidList(uint8_t scanList) return false; } -void RADIO_NextValidList(void) +void RADIO_NextValidList(int8_t direction) { uint8_t startList = gEeprom.SCAN_LIST_DEFAULT; uint8_t attempts = 0; - const uint8_t MAX_LISTS = MR_CHANNELS_LIST + 2; // 1-25, includes ALL + const uint8_t MAX_VALUE = MR_CHANNELS_LIST + 1; // 25 (1-24 lists + ALL) do { - // Move to next scan list, wrapping around from 25 to 1 - gEeprom.SCAN_LIST_DEFAULT = ((gEeprom.SCAN_LIST_DEFAULT + 1) % MAX_LISTS) ?: 1; + if (direction > 0) { + // Forward: 1 → 2 → ... → 25 → 1 + gEeprom.SCAN_LIST_DEFAULT = (gEeprom.SCAN_LIST_DEFAULT % MAX_VALUE) + 1; + } else { + // Backward: 25 → 24 → ... → 1 → 25 + gEeprom.SCAN_LIST_DEFAULT = ((gEeprom.SCAN_LIST_DEFAULT - 2 + MAX_VALUE) % MAX_VALUE) + 1; + } attempts++; - // Check if current list has valid channels if (RADIO_CheckValidList(gEeprom.SCAN_LIST_DEFAULT)) return; - // Stop if we've cycled through all lists or made too many attempts - } while (gEeprom.SCAN_LIST_DEFAULT != startList && attempts < MAX_LISTS); + } while (gEeprom.SCAN_LIST_DEFAULT != startList && attempts < MAX_VALUE); - // Safety fallback: if no valid list found, switch to ALL mode - // This prevents infinite loops and ensures scanning can continue + // Safety fallback: switch to ALL mode if (!RADIO_CheckValidList(gEeprom.SCAN_LIST_DEFAULT)) { - gEeprom.SCAN_LIST_DEFAULT = MR_CHANNELS_LIST + 1; // ALL + gEeprom.SCAN_LIST_DEFAULT = MAX_VALUE; // ALL (25) } } diff --git a/App/radio.h b/App/radio.h index c93044b0..ee2c0efd 100644 --- a/App/radio.h +++ b/App/radio.h @@ -149,7 +149,7 @@ extern DCS_CodeType_t gCurrentCodeType; extern VfoState_t VfoState[2]; bool RADIO_CheckValidList(uint8_t scanList); -void RADIO_NextValidList(void); +void RADIO_NextValidList(int8_t direction); bool RADIO_CheckValidChannel(uint16_t channel, bool checkScanList, uint8_t scanList); uint16_t RADIO_FindNextChannel(uint16_t ChNum, int8_t Direction, bool bCheckScanList, uint8_t RadioNum); void RADIO_InitInfo(VFO_Info_t *pInfo, const uint16_t ChannelSave, const uint32_t Frequency);