From 34f2e2986cf12c2d4db3e5b5ed368fb47d25c94d Mon Sep 17 00:00:00 2001 From: xawen Date: Sat, 18 Nov 2023 13:54:38 -0500 Subject: [PATCH] Loop timing updates --- app/spectrum.c | 52 +++++++++++++++++++++++++++++++++++--------------- 1 file changed, 37 insertions(+), 15 deletions(-) diff --git a/app/spectrum.c b/app/spectrum.c index deebcdae..58340b1a 100644 --- a/app/spectrum.c +++ b/app/spectrum.c @@ -17,6 +17,7 @@ #include "app/spectrum.h" #include "app/radio.h" #include "driver/bk4819.h" +#include "driver/delay.h" #include "driver/key.h" #include "driver/pins.h" #include "helper/helper.h" @@ -40,8 +41,11 @@ uint8_t CurrentFreqStepIndex; uint32_t CurrentFreqStep; uint8_t CurrentStepCountIndex; uint8_t CurrentStepCount; +uint16_t CurrentScanDelay; uint16_t RssiValue[128] = {0}; +uint8_t bDebug = 0; + void SetFreqMinMax(void){ uint32_t FreqDelta; @@ -74,6 +78,7 @@ void SetStepCount(void){ void IncrementStepIndex(void){ CurrentStepCountIndex = (CurrentStepCountIndex + 1) % STEPS_COUNT; SetStepCount(); + SetFreqMinMax(); } void DrawBars(){ @@ -137,14 +142,14 @@ void StopSpectrum(void) void Spectrum_Loop(void){ KEY_t Key; - KEY_t LastKey; + KEY_t LastKey = KEY_NONE; uint32_t FreqToCheck; while (1) { //Do non-interactive stuff here FreqToCheck = FreqMin; -// These are used in radio.h when the frequency is set. Maybe needed? +// These are used in radio.c when the frequency is set. Some combination is needed in the loop. // BK4819_SetSquelchGlitch(FALSE); // BK4819_SetSquelchNoise(FALSE); // BK4819_SetSquelchRSSI(FALSE); @@ -153,16 +158,31 @@ void Spectrum_Loop(void){ // BK4819_EnableFilter(false); for (uint8_t i = 0; i < CurrentStepCount; i++) { + BK4819_SetFrequency(FreqToCheck); + + //DELAY_WaitUS(CurrentScanDelay); + //BK4819_EnableRX(); + //contents of BK4819_EnableRX: + BK4819_WriteRegister(0x37, 0x1F0F); + //DELAY_WaitMS(10); + BK4819_WriteRegister(0x30, 0x0200); + BK4819_WriteRegister(0x30, 0xBFF1); + //BK4819_SetFilterBandwidth(false); + //BK4819_EnableFilter(true); + DELAY_WaitMS(50); + RssiValue[i] = BK4819_GetRSSI(); - //Test prints - remove - /* - Int2Ascii(FreqToCheck, 8); - UI_DrawSmallString(2, 50, gShortString, 8); - Int2Ascii(RssiValue[i], 8); - UI_DrawSmallString(60, 50, gShortString, 8); - */ - //end test + + //-----------------------Test prints - remove + if (bDebug) { + Int2Ascii(FreqToCheck, 8); + UI_DrawSmallString(2, 50, gShortString, 8); + Int2Ascii(RssiValue[i], 8); + UI_DrawSmallString(60, 50, gShortString, 8); + } + //------------------------end test + FreqToCheck += CurrentFreqStep; } @@ -172,13 +192,13 @@ void Spectrum_Loop(void){ Key = KEY_GetButton(); if (Key != LastKey) { - switch (Key) - { + switch (Key) { case KEY_NONE: break; case KEY_EXIT: StopSpectrum(); return; + break; case KEY_MENU: break; case KEY_UP: @@ -205,17 +225,19 @@ void Spectrum_Loop(void){ case KEY_9: break; case KEY_0: + bDebug ^= 1; break; case KEY_HASH: break; case KEY_STAR: break; + default: + break; } LastKey = Key; } } - } void APP_Spectrum(void){ @@ -224,7 +246,8 @@ void APP_Spectrum(void){ CurrentModulation = gVfoState[gSettings.CurrentVfo].gModulationType; CurrentFreqStepIndex = gSettings.FrequencyStep; CurrentFreqStep = FREQUENCY_GetStep(CurrentFreqStepIndex); - CurrentStepCountIndex = STEPS_128; + CurrentStepCountIndex = STEPS_16; + CurrentScanDelay = 100; SetStepCount(); SetFreqMinMax(); @@ -246,7 +269,6 @@ void APP_Spectrum(void){ #endif DISPLAY_Fill(0, 159, 1, 81, COLOR_BACKGROUND); - Spectrum_Loop(); }