From 05b6313f894ab62d90e01ef6550b1ce4d87e1f03 Mon Sep 17 00:00:00 2001 From: Nunu Date: Mon, 25 Dec 2023 15:04:18 +0100 Subject: [PATCH] Spectrum CHANNEL_MODE, FREQUENCY_MODE added. --- app/main.c | 16 +++++++++++++- app/spectrum.c | 58 +++++++++++++++++++++++++++++++++++--------------- app/spectrum.h | 13 ++++++++++- 3 files changed, 68 insertions(+), 19 deletions(-) diff --git a/app/main.c b/app/main.c index ee51c6d..9f59e5b 100644 --- a/app/main.c +++ b/app/main.c @@ -235,7 +235,21 @@ static void processFKeyFunction(const KEY_Code_t Key, const bool beep) gRequestSaveVFO = true; gVfoConfigureMode = VFO_CONFIGURE_RELOAD; #elif defined(ENABLE_SPECTRUM) - APP_RunSpectrum(); + #ifdef ENABLE_SPECTRUM_CHANNEL_SCAN + // if we are in channel mode then enter spectrum in channel mode + if(IS_MR_CHANNEL(gTxVfo->CHANNEL_SAVE)) + { + APP_RunSpectrum(CHANNEL_MODE); + } + // otherwise enter spectrum in frequency mode + else + { + APP_RunSpectrum(FREQUENCY_MODE); + } + + #elif + APP_RunSpectrum(); + #endif gRequestDisplayScreen = DISPLAY_MAIN; #endif } diff --git a/app/spectrum.c b/app/spectrum.c index 0f221e3..d255091 100644 --- a/app/spectrum.c +++ b/app/spectrum.c @@ -35,6 +35,7 @@ struct FrequencyBandInfo { #define F_MAX frequencyBandTable[ARRAY_SIZE(frequencyBandTable) - 1].upper #ifdef ENABLE_SPECTRUM_CHANNEL_SCAN + Mode appMode; //Idea - make this user adjustable to compensate for different antennas, frontends, conditions #define UHF_NOISE_FLOOR 40 //Current channel scan index @@ -84,7 +85,6 @@ const uint8_t modTypeReg47Values[] = {1, 7, 5}; SpectrumSettings settings = {stepsCount: STEPS_128, scanStepIndex: S_STEP_25_0kHz, frequencyChangeStep: 80000, - scanDelay: 3200, rssiTriggerLevel: 150, backlightState: true, bw: BK4819_FILTER_BW_WIDE, @@ -278,8 +278,12 @@ uint16_t GetScanStep() { return scanStepValues[settings.scanStepIndex]; } uint16_t GetStepsCount() { #ifdef ENABLE_SPECTRUM_CHANNEL_SCAN - return (RADIO_ValidMemoryChannelsCount()); -#elif ENABLE_SCAN_RANGES + if (appMode==CHANNEL_MODE) + { + return (RADIO_ValidMemoryChannelsCount()); + } +#endif +#ifdef ENABLE_SCAN_RANGES if(gScanRangeStart) { return (gScanRangeStop - gScanRangeStart) / GetScanStep(); } @@ -353,9 +357,12 @@ uint16_t GetRssi() { rssi = BK4819_GetRSSI(); #ifdef ENABLE_SPECTRUM_CHANNEL_SCAN - // Increase perceived RSSI for UHF bands to imitate radio squelch - if(FREQUENCY_GetBand(fMeasure) > BAND4_174MHz) + if ((appMode==CHANNEL_MODE) && (FREQUENCY_GetBand(fMeasure) > BAND4_174MHz)) + { + // Increase perceived RSSI for UHF bands to imitate radio squelch rssi+=UHF_NOISE_FLOOR; + } + #endif return rssi; } @@ -1211,21 +1218,33 @@ static void Scan() { static void NextScanStep() { ++peak.t; #ifdef ENABLE_SPECTRUM_CHANNEL_SCAN - int nextChannel; - if(scanInfo.i==0) - channelIndex = MR_CHANNEL_FIRST; + // channel mode + if (appMode==CHANNEL_MODE) + { + int nextChannel; + if(scanInfo.i==0) + channelIndex = MR_CHANNEL_FIRST; - nextChannel = RADIO_FindNextChannel((channelIndex)+1, 1, false, 0); - channelIndex = nextChannel; - scanInfo.f = gMR_ChannelFrequencyAttributes[channelIndex].Frequency; - - if (nextChannel == 0xFF) - { // no valid channel found - channelIndex = MR_CHANNEL_FIRST; + nextChannel = RADIO_FindNextChannel((channelIndex)+1, 1, false, 0); + channelIndex = nextChannel; + scanInfo.f = gMR_ChannelFrequencyAttributes[channelIndex].Frequency; + + if (nextChannel == 0xFF) + { // no valid channel found + channelIndex = MR_CHANNEL_FIRST; + } + + ++scanInfo.i; } - - ++scanInfo.i; + else + // frequency mode + { + ++scanInfo.i; + scanInfo.f += scanInfo.scanStep; + } + #elif + ++scanInfo.i; scanInfo.f += scanInfo.scanStep; #endif @@ -1347,7 +1366,12 @@ static void Tick() { } } +#ifdef ENABLE_SPECTRUM_CHANNEL_SCAN +void APP_RunSpectrum(Mode mode) { + appMode = mode; +#elif void APP_RunSpectrum() { +#endif #ifdef ENABLE_SCAN_RANGES if(gScanRangeStart) { currentFreq = initialFreq = gScanRangeStart; diff --git a/app/spectrum.h b/app/spectrum.h index 68f1975..4afe3e9 100644 --- a/app/spectrum.h +++ b/app/spectrum.h @@ -92,6 +92,13 @@ typedef enum State { STILL, } State; +#ifdef ENABLE_SPECTRUM_CHANNEL_SCAN +typedef enum Mode { + FREQUENCY_MODE, + CHANNEL_MODE +} Mode; +#endif + typedef enum StepsCount { STEPS_128, STEPS_64, @@ -149,8 +156,12 @@ typedef struct PeakInfo { uint32_t f; uint16_t i; } PeakInfo; - +#ifdef ENABLE_SPECTRUM_CHANNEL_SCAN +void APP_RunSpectrum(Mode mode); +#elif void APP_RunSpectrum(void); +#endif + #ifdef ENABLE_SPECTRUM_SHOW_CHANNEL_NAME void LookupChannelInfo();