Skip to content

Commit

Permalink
Loop timing updates
Browse files Browse the repository at this point in the history
  • Loading branch information
xawen committed Nov 18, 2023
1 parent b9db1ae commit 34f2e29
Showing 1 changed file with 37 additions and 15 deletions.
52 changes: 37 additions & 15 deletions app/spectrum.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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;

Expand Down Expand Up @@ -74,6 +78,7 @@ void SetStepCount(void){
void IncrementStepIndex(void){
CurrentStepCountIndex = (CurrentStepCountIndex + 1) % STEPS_COUNT;
SetStepCount();
SetFreqMinMax();
}

void DrawBars(){
Expand Down Expand Up @@ -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);
Expand All @@ -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;
}

Expand All @@ -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:
Expand All @@ -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){
Expand All @@ -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();
Expand All @@ -246,7 +269,6 @@ void APP_Spectrum(void){
#endif

DISPLAY_Fill(0, 159, 1, 81, COLOR_BACKGROUND);

Spectrum_Loop();
}

Expand Down

0 comments on commit 34f2e29

Please sign in to comment.