From 7857e8ed7a7863695e18f139419a43c1a346565d Mon Sep 17 00:00:00 2001 From: Krzysiek Egzmont Date: Mon, 27 Nov 2023 22:52:54 +0100 Subject: [PATCH] Scan range function #132 --- Makefile | 8 ++++++-- app/app.c | 18 +++++++++++++----- app/app.h | 1 + app/chFrScanner.c | 14 +++++++++++++- app/chFrScanner.h | 4 ++++ app/common.c | 4 ++++ app/main.c | 9 ++++++++- ui/main.c | 12 ++++++++++++ 8 files changed, 61 insertions(+), 9 deletions(-) diff --git a/Makefile b/Makefile index 8fb5a77..dd4d1d3 100644 --- a/Makefile +++ b/Makefile @@ -24,7 +24,7 @@ ENABLE_TX_WHEN_AM := 0 ENABLE_F_CAL_MENU := 0 ENABLE_CTCSS_TAIL_PHASE_SHIFT := 0 ENABLE_BOOT_BEEPS := 0 -ENABLE_SHOW_CHARGE_LEVEL := 1 +ENABLE_SHOW_CHARGE_LEVEL := 0 ENABLE_REVERSE_BAT_SYMBOL := 0 ENABLE_NO_CODE_SCAN_TIMEOUT := 1 ENABLE_AM_FIX := 1 @@ -37,7 +37,8 @@ ENABLE_COPY_CHAN_TO_VFO := 1 ENABLE_SPECTRUM := 1 ENABLE_REDUCE_LOW_MID_TX_POWER:= 0 ENABLE_BYP_RAW_DEMODULATORS := 0 -ENABLE_BLMIN_TMP_OFF := 0 +ENABLE_BLMIN_TMP_OFF := 0 +ENABLE_SCAN_RANGES := 1 ############################################################# TARGET = firmware @@ -347,6 +348,9 @@ endif ifeq ($(ENABLE_BLMIN_TMP_OFF),1) CFLAGS += -DENABLE_BLMIN_TMP_OFF endif +ifeq ($(ENABLE_SCAN_RANGES),1) + CFLAGS += -DENABLE_SCAN_RANGES +endif LDFLAGS = ifeq ($(ENABLE_CLANG),0) diff --git a/app/app.c b/app/app.c index 0934fce..bdcd0ed 100644 --- a/app/app.c +++ b/app/app.c @@ -551,18 +551,23 @@ void APP_StartListening(FUNCTION_Type_t Function, const bool reset_am_fix) gUpdateStatus = true; } -uint32_t APP_SetFrequencyByStep(VFO_Info_t *pInfo, int8_t direction) +uint32_t APP_SetFreqByStepAndLimits(VFO_Info_t *pInfo, int8_t direction, uint32_t lower, uint32_t upper) { uint32_t Frequency = FREQUENCY_RoundToStep(pInfo->freq_config_RX.Frequency + (direction * pInfo->StepFrequency), pInfo->StepFrequency); - if (Frequency >= frequencyBandTable[pInfo->Band].upper) - Frequency = frequencyBandTable[pInfo->Band].lower; - else if (Frequency < frequencyBandTable[pInfo->Band].lower) - Frequency = FREQUENCY_RoundToStep(frequencyBandTable[pInfo->Band].upper - pInfo->StepFrequency, pInfo->StepFrequency); + if (Frequency >= upper) + Frequency = lower; + else if (Frequency < lower) + Frequency = FREQUENCY_RoundToStep(upper - pInfo->StepFrequency, pInfo->StepFrequency); return Frequency; } +uint32_t APP_SetFrequencyByStep(VFO_Info_t *pInfo, int8_t direction) +{ + return APP_SetFreqByStepAndLimits(pInfo, direction, frequencyBandTable[pInfo->Band].lower, frequencyBandTable[pInfo->Band].upper); +} + #ifdef ENABLE_NOAA static void NOAA_IncreaseChannel(void) { @@ -1721,6 +1726,9 @@ static void ProcessKey(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld) if (gMonitor) ACTION_Monitor(); //turn off the monitor +#ifdef ENABLE_SCAN_RANGES + gScanRangeStart = 0; +#endif } if (gScreenToDisplay == DISPLAY_MENU) // 1of11 diff --git a/app/app.h b/app/app.h index fe1724f..ef3b706 100644 --- a/app/app.h +++ b/app/app.h @@ -25,6 +25,7 @@ void APP_EndTransmission(void); void APP_StartListening(FUNCTION_Type_t Function, const bool reset_am_fix); +uint32_t APP_SetFreqByStepAndLimits(VFO_Info_t *pInfo, int8_t direction, uint32_t lower, uint32_t upper); uint32_t APP_SetFrequencyByStep(VFO_Info_t *pInfo, int8_t direction); void APP_Update(void); void APP_TimeSlice10ms(void); diff --git a/app/chFrScanner.c b/app/chFrScanner.c index bb96fa3..37af4b8 100644 --- a/app/chFrScanner.c +++ b/app/chFrScanner.c @@ -9,6 +9,10 @@ int8_t gScanStateDir; bool gScanKeepResult; bool gScanPauseMode; +#ifdef ENABLE_SCAN_RANGES +uint32_t gScanRangeStart; +#endif + typedef enum { SCAN_NEXT_CHAN_SCANLIST1 = 0, SCAN_NEXT_CHAN_SCANLIST2, @@ -151,7 +155,15 @@ void CHFRSCANNER_Stop(void) static void NextFreqChannel(void) { - gRxVfo->freq_config_RX.Frequency = APP_SetFrequencyByStep(gRxVfo, gScanStateDir); +#ifdef ENABLE_SCAN_RANGES + if(gScanRangeStart) { + uint32_t start = gScanRangeStart; + uint32_t end = gEeprom.VfoInfo[(gEeprom.TX_VFO+1)%2].freq_config_RX.Frequency; + gRxVfo->freq_config_RX.Frequency = APP_SetFreqByStepAndLimits(gRxVfo, gScanStateDir, MIN(start, end), MAX(start, end)); + } + else +#endif + gRxVfo->freq_config_RX.Frequency = APP_SetFrequencyByStep(gRxVfo, gScanStateDir); RADIO_ApplyOffset(gRxVfo); RADIO_ConfigureSquelchAndOutputPower(gRxVfo); diff --git a/app/chFrScanner.h b/app/chFrScanner.h index 647a508..b3695ee 100644 --- a/app/chFrScanner.h +++ b/app/chFrScanner.h @@ -10,6 +10,10 @@ extern int8_t gScanStateDir; extern bool gScanKeepResult; extern bool gScanPauseMode; +#ifdef ENABLE_SCAN_RANGES +extern uint32_t gScanRangeStart; +#endif + void CHFRSCANNER_Found(void); void CHFRSCANNER_Stop(void); void CHFRSCANNER_Start(const bool storeBackupSettings, const int8_t scan_direction); diff --git a/app/common.c b/app/common.c index c64d268..4265dfa 100644 --- a/app/common.c +++ b/app/common.c @@ -1,3 +1,4 @@ +#include "app/chFrScanner.h" #include "audio.h" #include "functions.h" #include "misc.h" @@ -23,6 +24,9 @@ void COMMON_KeypadLockToggle() void COMMON_SwitchVFOs() { +#ifdef ENABLE_SCAN_RANGES + gScanRangeStart = 0; +#endif gEeprom.TX_VFO ^= 1; if (gEeprom.CROSS_BAND_RX_TX != CROSS_BAND_OFF) diff --git a/app/main.c b/app/main.c index 26ca9c4..97527a8 100644 --- a/app/main.c +++ b/app/main.c @@ -46,9 +46,16 @@ void toggle_chan_scanlist(void) { // toggle the selected channels scanlist setting - if ( SCANNER_IsScanning() || !IS_MR_CHANNEL(gTxVfo->CHANNEL_SAVE)) + if ( SCANNER_IsScanning()) return; + if(!IS_MR_CHANNEL(gTxVfo->CHANNEL_SAVE)) { +#ifdef ENABLE_SCAN_RANGES + gScanRangeStart = gScanRangeStart ? 0 : gTxVfo->pRX->Frequency; +#endif + return; + } + if (gTxVfo->SCANLIST1_PARTICIPATION) { if (gTxVfo->SCANLIST2_PARTICIPATION) diff --git a/ui/main.c b/ui/main.c index 588c925..6345b89 100644 --- a/ui/main.c +++ b/ui/main.c @@ -17,6 +17,7 @@ #include #include // abs() +#include "app/chFrScanner.h" #include "app/dtmf.h" #ifdef ENABLE_AM_FIX_SHOW_DATA #include "am_fix.h" @@ -281,6 +282,17 @@ void UI_DisplayMain(void) if (activeTxVFO != vfo_num) // this is not active TX VFO { +#ifdef ENABLE_SCAN_RANGES + if(gScanRangeStart) { + UI_PrintString("ScnRng", 5, 0, line, 8); + sprintf(String, "%3u.%05u", gScanRangeStart / 100000, gScanRangeStart % 100000); + UI_PrintStringSmall(String, 56, 0, line); + uint32_t frq = gEeprom.VfoInfo[vfo_num].pRX->Frequency; + sprintf(String, "%3u.%05u", frq / 100000, frq % 100000); + UI_PrintStringSmall(String, 56, 0, line + 1); + continue; + } +#endif if (gDTMF_CallState != DTMF_CALL_STATE_NONE || gDTMF_IsTx || gDTMF_InputMode) { // show DTMF stuff