diff --git a/app/action.c b/app/action.c index 3922bb5..16034c4 100644 --- a/app/action.c +++ b/app/action.c @@ -193,7 +193,7 @@ void ACTION_Scan(bool bRestart) gEeprom.SCAN_LIST_DEFAULT = (gEeprom.SCAN_LIST_DEFAULT + 1) % 3; // jump to the next channel - CHANNEL_Next(true, gScanStateDir); + SCANNER_NextChannel(false, gScanStateDir); gScanPauseDelayIn_10ms = 1; gScheduleScanListen = false; @@ -212,7 +212,7 @@ void ACTION_Scan(bool bRestart) else { // start scanning - CHANNEL_Next(true, SCAN_FWD); + SCANNER_NextChannel(true, SCAN_FWD); #ifdef ENABLE_VOICE AUDIO_SetVoiceID(0, VOICE_ID_SCANNING_BEGIN); @@ -235,7 +235,7 @@ void ACTION_Scan(bool bRestart) gEeprom.SCAN_LIST_DEFAULT = (gEeprom.SCAN_LIST_DEFAULT + 1) % 3; // jump to the next channel - CHANNEL_Next(true, gScanStateDir); + SCANNER_NextChannel(false, gScanStateDir); gScanPauseDelayIn_10ms = 1; gScheduleScanListen = false; diff --git a/app/app.c b/app/app.c index 0dde658..b18e73d 100644 --- a/app/app.c +++ b/app/app.c @@ -621,123 +621,6 @@ uint32_t APP_SetFrequencyByStep(VFO_Info_t *pInfo, int8_t Step) return Frequency; } -static void FREQ_NextChannel(void) -{ - gRxVfo->freq_config_RX.Frequency = APP_SetFrequencyByStep(gRxVfo, gScanStateDir); - - RADIO_ApplyOffset(gRxVfo); - RADIO_ConfigureSquelchAndOutputPower(gRxVfo); - RADIO_SetupRegisters(true); - - #ifdef ENABLE_FASTER_CHANNEL_SCAN - gScanPauseDelayIn_10ms = 9; // 90ms - #else - gScanPauseDelayIn_10ms = scan_pause_delay_in_6_10ms; - #endif - - bScanKeepFrequency = false; - gUpdateDisplay = true; -} - -static void MR_NextChannel(void) -{ - static unsigned int prev_mr_chan = 0; - const bool enabled = (gEeprom.SCAN_LIST_DEFAULT < 2) ? gEeprom.SCAN_LIST_ENABLED[gEeprom.SCAN_LIST_DEFAULT] : true; - const int chan1 = (gEeprom.SCAN_LIST_DEFAULT < 2) ? gEeprom.SCANLIST_PRIORITY_CH1[gEeprom.SCAN_LIST_DEFAULT] : -1; - const int chan2 = (gEeprom.SCAN_LIST_DEFAULT < 2) ? gEeprom.SCANLIST_PRIORITY_CH2[gEeprom.SCAN_LIST_DEFAULT] : -1; - const unsigned int prev_chan = gNextMrChannel; - unsigned int chan = 0; - - if (enabled) - { - switch (gCurrentScanList) - { - case SCAN_NEXT_CHAN_SCANLIST1: - prev_mr_chan = gNextMrChannel; - - if (chan1 >= 0) - { - if (RADIO_CheckValidChannel(chan1, false, 0)) - { - gCurrentScanList = SCAN_NEXT_CHAN_SCANLIST1; - gNextMrChannel = chan1; - break; - } - } - [[fallthrough]]; - case SCAN_NEXT_CHAN_SCANLIST2: - if (chan2 >= 0) - { - if (RADIO_CheckValidChannel(chan2, false, 0)) - { - gCurrentScanList = SCAN_NEXT_CHAN_SCANLIST2; - gNextMrChannel = chan2; - break; - } - } - [[fallthrough]]; - - // this bit doesn't yet work if the other VFO is a frequency - case SCAN_NEXT_CHAN_DUAL_WATCH: - // dual watch is enabled - include the other VFO in the scan -// if (gEeprom.DUAL_WATCH != DUAL_WATCH_OFF) -// { -// chan = (gEeprom.RX_VFO + 1) & 1u; -// chan = gEeprom.ScreenChannel[chan]; -// if (chan <= MR_CHANNEL_LAST) -// { -// gCurrentScanList = SCAN_NEXT_CHAN_DUAL_WATCH; -// gNextMrChannel = chan; -// break; -// } -// } - - default: - case SCAN_NEXT_CHAN_MR: - gCurrentScanList = SCAN_NEXT_CHAN_MR; - gNextMrChannel = prev_mr_chan; - chan = 0xff; - break; - } - } - - if (!enabled || chan == 0xff) - { - chan = RADIO_FindNextChannel(gNextMrChannel + gScanStateDir, gScanStateDir, (gEeprom.SCAN_LIST_DEFAULT < 2) ? true : false, gEeprom.SCAN_LIST_DEFAULT); - if (chan == 0xFF) - { // no valid channel found - - chan = MR_CHANNEL_FIRST; -// return; - } - - gNextMrChannel = chan; - } - - if (gNextMrChannel != prev_chan) - { - gEeprom.MrChannel[ gEeprom.RX_VFO] = gNextMrChannel; - gEeprom.ScreenChannel[gEeprom.RX_VFO] = gNextMrChannel; - - RADIO_ConfigureChannel(gEeprom.RX_VFO, VFO_CONFIGURE_RELOAD); - RADIO_SetupRegisters(true); - - gUpdateDisplay = true; - } - - #ifdef ENABLE_FASTER_CHANNEL_SCAN - gScanPauseDelayIn_10ms = 9; // 90ms .. <= ~60ms it misses signals (squelch response and/or PLL lock time) ? - #else - gScanPauseDelayIn_10ms = scan_pause_delay_in_3_10ms; - #endif - - bScanKeepFrequency = false; - - if (enabled) - if (++gCurrentScanList >= SCAN_NEXT_NUM) - gCurrentScanList = SCAN_NEXT_CHAN_SCANLIST1; // back round we go -} - #ifdef ENABLE_NOAA static void NOAA_IncreaseChannel(void) { @@ -1072,25 +955,7 @@ void APP_Update(void) if (gScreenToDisplay != DISPLAY_SCANNER && gScanStateDir != SCAN_OFF && gScheduleScanListen && !gPttIsPressed) #endif { // scanning - - if (IS_FREQ_CHANNEL(gNextMrChannel)) - { - if (gCurrentFunction == FUNCTION_INCOMING) - APP_StartListening(gMonitor ? FUNCTION_MONITOR : FUNCTION_RECEIVE, true); - else - FREQ_NextChannel(); // switch to next frequency - } - else - { - if (gCurrentCodeType == CODE_TYPE_OFF && gCurrentFunction == FUNCTION_INCOMING) - APP_StartListening(gMonitor ? FUNCTION_MONITOR : FUNCTION_RECEIVE, true); - else - MR_NextChannel(); // switch to next channel - } - - gScanPauseMode = false; - gRxReceptionMode = RX_MODE_NONE; - gScheduleScanListen = false; + SCANNER_ContinueScanning(); } #ifdef ENABLE_VOICE @@ -2075,33 +1940,7 @@ void APP_TimeSlice500ms(void) } #endif -void CHANNEL_Next(const bool bFlag, const int8_t scan_direction) -{ - RADIO_SelectVfos(); - gNextMrChannel = gRxVfo->CHANNEL_SAVE; - gCurrentScanList = SCAN_NEXT_CHAN_SCANLIST1; - gScanStateDir = scan_direction; - - if (gNextMrChannel <= MR_CHANNEL_LAST) - { // channel mode - if (bFlag) - gRestoreMrChannel = gNextMrChannel; - MR_NextChannel(); - } - else - { // frequency mode - if (bFlag) - gRestoreFrequency = gRxVfo->freq_config_RX.Frequency; - FREQ_NextChannel(); - } - - gScanPauseDelayIn_10ms = scan_pause_delay_in_2_10ms; - gScheduleScanListen = false; - gRxReceptionMode = RX_MODE_NONE; - gScanPauseMode = false; - bScanKeepFrequency = false; -} static void APP_ProcessKey(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld) { diff --git a/app/app.h b/app/app.h index 6f958da..9406b00 100644 --- a/app/app.h +++ b/app/app.h @@ -29,7 +29,6 @@ extern const uint8_t orig_mixer; extern const uint8_t orig_pga; void APP_EndTransmission(void); -void CHANNEL_Next(const bool bFlag, const int8_t scan_direction); void APP_StartListening(FUNCTION_Type_t Function, const bool reset_am_fix); uint32_t APP_SetFrequencyByStep(VFO_Info_t *pInfo, int8_t Step); void APP_Update(void); diff --git a/app/main.c b/app/main.c index 916e811..f442a0b 100644 --- a/app/main.c +++ b/app/main.c @@ -803,7 +803,7 @@ static void MAIN_Key_UP_DOWN(bool bKeyPressed, bool bKeyHeld, int8_t Direction) } // jump to the next channel - CHANNEL_Next(false, Direction); + SCANNER_NextChannel(false, Direction); gScanPauseDelayIn_10ms = 1; gScheduleScanListen = false; diff --git a/app/scanner.c b/app/scanner.c index 25cb1e3..a5d24c4 100644 --- a/app/scanner.c +++ b/app/scanner.c @@ -14,6 +14,7 @@ * limitations under the License. */ +#include "app/app.h" #include "app/dtmf.h" #include "app/generic.h" #include "app/scanner.h" @@ -43,6 +44,7 @@ uint8_t gScanHitCount; bool gScanUseCssResult; int8_t gScanStateDir; bool bScanKeepFrequency; +uint8_t gRestoreMrChannel; static void SCANNER_Key_DIGITS(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld) { @@ -362,10 +364,10 @@ void SCANNER_Start(void) RADIO_SelectVfos(); - #ifdef ENABLE_NOAA - if (IS_NOAA_CHANNEL(gRxVfo->CHANNEL_SAVE)) - gRxVfo->CHANNEL_SAVE = FREQ_CHANNEL_FIRST + BAND6_400MHz; - #endif +#ifdef ENABLE_NOAA + if (IS_NOAA_CHANNEL(gRxVfo->CHANNEL_SAVE)) + gRxVfo->CHANNEL_SAVE = FREQ_CHANNEL_FIRST + BAND6_400MHz; +#endif BackupStep = gRxVfo->STEP_SETTING; BackupFrequency = gRxVfo->StepFrequency; @@ -377,9 +379,9 @@ void SCANNER_Start(void) RADIO_SetupRegisters(true); - #ifdef ENABLE_NOAA - gIsNoaaMode = false; - #endif +#ifdef ENABLE_NOAA + gIsNoaaMode = false; +#endif if (gScanSingleFrequency) { @@ -414,9 +416,9 @@ void SCANNER_Start(void) g_CDCSS_Lost = false; gCDCSSCodeType = 0; g_CTCSS_Lost = false; - #ifdef ENABLE_VOX - g_VOX_Lost = false; - #endif +#ifdef ENABLE_VOX + g_VOX_Lost = false; +#endif g_SquelchLost = false; gScannerEditState = 0; gScanProgressIndicator = 0; @@ -424,8 +426,6 @@ void SCANNER_Start(void) void SCANNER_Stop(void) { - const uint8_t Previous = gRestoreMrChannel; - gScanStateDir = SCAN_OFF; if (!bScanKeepFrequency) @@ -433,7 +433,7 @@ void SCANNER_Stop(void) if (gNextMrChannel <= MR_CHANNEL_LAST) { gEeprom.MrChannel[gEeprom.RX_VFO] = gRestoreMrChannel; - gEeprom.ScreenChannel[gEeprom.RX_VFO] = Previous; + gEeprom.ScreenChannel[gEeprom.RX_VFO] = gRestoreMrChannel; RADIO_ConfigureChannel(gEeprom.RX_VFO, VFO_CONFIGURE_RELOAD); } @@ -460,3 +460,170 @@ void SCANNER_Stop(void) gUpdateStatus = true; } + +static void SCANNER_NextFreqChannel(void) +{ + gRxVfo->freq_config_RX.Frequency = APP_SetFrequencyByStep(gRxVfo, gScanStateDir); + + RADIO_ApplyOffset(gRxVfo); + RADIO_ConfigureSquelchAndOutputPower(gRxVfo); + RADIO_SetupRegisters(true); + +#ifdef ENABLE_FASTER_CHANNEL_SCAN + gScanPauseDelayIn_10ms = 9; // 90ms +#else + gScanPauseDelayIn_10ms = scan_pause_delay_in_6_10ms; +#endif + + bScanKeepFrequency = false; + gUpdateDisplay = true; +} + +static void SCANNER_NextMemChannel(void) +{ + static unsigned int prev_mr_chan = 0; + const bool enabled = (gEeprom.SCAN_LIST_DEFAULT < 2) ? gEeprom.SCAN_LIST_ENABLED[gEeprom.SCAN_LIST_DEFAULT] : true; + const int chan1 = (gEeprom.SCAN_LIST_DEFAULT < 2) ? gEeprom.SCANLIST_PRIORITY_CH1[gEeprom.SCAN_LIST_DEFAULT] : -1; + const int chan2 = (gEeprom.SCAN_LIST_DEFAULT < 2) ? gEeprom.SCANLIST_PRIORITY_CH2[gEeprom.SCAN_LIST_DEFAULT] : -1; + const unsigned int prev_chan = gNextMrChannel; + unsigned int chan = 0; + + if (enabled) + { + switch (gCurrentScanList) + { + case SCAN_NEXT_CHAN_SCANLIST1: + prev_mr_chan = gNextMrChannel; + + if (chan1 >= 0) + { + if (RADIO_CheckValidChannel(chan1, false, 0)) + { + gCurrentScanList = SCAN_NEXT_CHAN_SCANLIST1; + gNextMrChannel = chan1; + break; + } + } + [[fallthrough]]; + case SCAN_NEXT_CHAN_SCANLIST2: + if (chan2 >= 0) + { + if (RADIO_CheckValidChannel(chan2, false, 0)) + { + gCurrentScanList = SCAN_NEXT_CHAN_SCANLIST2; + gNextMrChannel = chan2; + break; + } + } + [[fallthrough]]; + + // this bit doesn't yet work if the other VFO is a frequency + case SCAN_NEXT_CHAN_DUAL_WATCH: + // dual watch is enabled - include the other VFO in the scan +// if (gEeprom.DUAL_WATCH != DUAL_WATCH_OFF) +// { +// chan = (gEeprom.RX_VFO + 1) & 1u; +// chan = gEeprom.ScreenChannel[chan]; +// if (chan <= MR_CHANNEL_LAST) +// { +// gCurrentScanList = SCAN_NEXT_CHAN_DUAL_WATCH; +// gNextMrChannel = chan; +// break; +// } +// } + + default: + case SCAN_NEXT_CHAN_MR: + gCurrentScanList = SCAN_NEXT_CHAN_MR; + gNextMrChannel = prev_mr_chan; + chan = 0xff; + break; + } + } + + if (!enabled || chan == 0xff) + { + chan = RADIO_FindNextChannel(gNextMrChannel + gScanStateDir, gScanStateDir, (gEeprom.SCAN_LIST_DEFAULT < 2) ? true : false, gEeprom.SCAN_LIST_DEFAULT); + if (chan == 0xFF) + { // no valid channel found + + chan = MR_CHANNEL_FIRST; +// return; + } + + gNextMrChannel = chan; + } + + if (gNextMrChannel != prev_chan) + { + gEeprom.MrChannel[ gEeprom.RX_VFO] = gNextMrChannel; + gEeprom.ScreenChannel[gEeprom.RX_VFO] = gNextMrChannel; + + RADIO_ConfigureChannel(gEeprom.RX_VFO, VFO_CONFIGURE_RELOAD); + RADIO_SetupRegisters(true); + + gUpdateDisplay = true; + } + +#ifdef ENABLE_FASTER_CHANNEL_SCAN + gScanPauseDelayIn_10ms = 9; // 90ms .. <= ~60ms it misses signals (squelch response and/or PLL lock time) ? +#else + gScanPauseDelayIn_10ms = scan_pause_delay_in_3_10ms; +#endif + + bScanKeepFrequency = false; + + if (enabled) + if (++gCurrentScanList >= SCAN_NEXT_NUM) + gCurrentScanList = SCAN_NEXT_CHAN_SCANLIST1; // back round we go +} + +void SCANNER_NextChannel(const bool storeBackupSettings, const int8_t scan_direction) +{ + RADIO_SelectVfos(); + + gNextMrChannel = gRxVfo->CHANNEL_SAVE; + gCurrentScanList = SCAN_NEXT_CHAN_SCANLIST1; + gScanStateDir = scan_direction; + + if (gNextMrChannel <= MR_CHANNEL_LAST) + { // channel mode + if (storeBackupSettings) + gRestoreMrChannel = gNextMrChannel; + SCANNER_NextMemChannel(); + } + else + { // frequency mode + if (storeBackupSettings) + gRestoreFrequency = gRxVfo->freq_config_RX.Frequency; + SCANNER_NextFreqChannel(); + } + + gScanPauseDelayIn_10ms = scan_pause_delay_in_2_10ms; + gScheduleScanListen = false; + gRxReceptionMode = RX_MODE_NONE; + gScanPauseMode = false; + bScanKeepFrequency = false; +} + +void SCANNER_ContinueScanning() +{ + if (IS_FREQ_CHANNEL(gNextMrChannel)) + { + if (gCurrentFunction == FUNCTION_INCOMING) + APP_StartListening(gMonitor ? FUNCTION_MONITOR : FUNCTION_RECEIVE, true); + else + SCANNER_NextFreqChannel(); // switch to next frequency + } + else + { + if (gCurrentCodeType == CODE_TYPE_OFF && gCurrentFunction == FUNCTION_INCOMING) + APP_StartListening(gMonitor ? FUNCTION_MONITOR : FUNCTION_RECEIVE, true); + else + SCANNER_NextMemChannel(); // switch to next channel + } + + gScanPauseMode = false; + gRxReceptionMode = RX_MODE_NONE; + gScheduleScanListen = false; +} \ No newline at end of file diff --git a/app/scanner.h b/app/scanner.h index 8730ea6..f0d15ba 100644 --- a/app/scanner.h +++ b/app/scanner.h @@ -58,6 +58,8 @@ extern bool bScanKeepFrequency; void SCANNER_ProcessKeys(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld); void SCANNER_Start(void); void SCANNER_Stop(void); +void SCANNER_NextChannel(const bool storeBackupSettings, const int8_t scan_direction); +void SCANNER_ContinueScanning(); #endif diff --git a/misc.c b/misc.c index 3fef79d..9cf4634 100644 --- a/misc.c +++ b/misc.c @@ -205,7 +205,6 @@ uint16_t gLowBatteryCountdown; uint8_t gNextMrChannel; ReceptionMode_t gRxReceptionMode; -uint8_t gRestoreMrChannel; enum scan_next_chan_t gCurrentScanList; uint32_t gRestoreFrequency; diff --git a/misc.h b/misc.h index ae5e1f9..cbf1cce 100644 --- a/misc.h +++ b/misc.h @@ -277,7 +277,6 @@ extern uint16_t gLowBatteryCountdown; extern uint8_t gNextMrChannel; extern ReceptionMode_t gRxReceptionMode; -extern uint8_t gRestoreMrChannel; extern scan_next_chan_t gCurrentScanList; extern uint32_t gRestoreFrequency;