Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
xawen committed Nov 16, 2023
1 parent ee6ba9d commit 176b4cd
Showing 1 changed file with 78 additions and 38 deletions.
116 changes: 78 additions & 38 deletions app/spectrum.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,35 +29,50 @@
//#include "driver/uart.h"
//#include "external/printf/printf.h"

static uint32_t StartFreq;
static uint32_t CurrentFreq;
uint8_t StepCount;
//static uint32_t StartFreq;
uint32_t CurrentFreq;
uint32_t FreqMin;
uint32_t FreqMax;
uint8_t CurrentModulation;
uint8_t CurrentFreqStepIndex;
uint32_t CurrentFreqStep;
uint8_t CurrentStepCount;
uint16_t RssiValue[128] = {0};

//SpectrumSettings Settings = {
// .stepsCount = STEPS_64,
// .scanStepIndex = STEP_25_0kHz,
//};
void uint32_t SetFreqMinMax(void){
uint32_t FreqDelta;

FreqDelta = CurrentFreqStep*(CurrentStepCount >> 1);
FreqMin = CurrentFreq - FreqDelta;
FreqMax = CurrentFreq + FreqDelta;
}

//---------------------------------------------------------------------------------------------
// These are probably going to be useful
//bool IsCenterMode() { return settings.scanStepIndex < STEP_1_0kHz; }

//uint8_t GetStepsCount() { return 128 >> settings.stepsCount; }

//uint16_t GetScanStep() { return StepFrequencyTable[settings.scanStepIndex]; }

//uint32_t GetFreqStart() { return IsCenterMode() ? currentFreq - (GetBW() >> 1) : currentFreq; }

//uint32_t GetFreqEnd() { return currentFreq + GetBW(); }
//---------------------------------------------------------------------------------------------
void DrawFreqLabel(uint32_t Frequency, uint8_t X, uint8_t Y)
{
Int2Ascii(Frequency, 8);
UI_DrawSmallString(X, Y, gShortString, 8);

/* Sample how to break down number to insert .
// uint32_t Divider = 10000000U;
// uint8_t i;
for (i = 0; i < 8; i++) {
UI_DrawBigDigit(X, Y, (Frequency / Divider) % 10U);
Divider /= 10;
if (i == 2) {
X += 16;
} else {
X += 12;
}
}
*/
}

void DrawBars(){
uint16_t Power;
uint8_t BarWidth = 128 / StepCount;
uint8_t BarWidth = 128 / CurrentStepCount;
for (uint8_t x = 0; x < 128; ++x) {
uint8_t i = x >> StepCount;
uint8_t i = x >> CurrentStepCount;
// if (blacklist[i]) {
// continue;
// }
Expand Down Expand Up @@ -93,8 +108,8 @@ void Spectrum_Loop(void){
Key = KEY_GetButton();
DISPLAY_Fill(80, 159, 8, 40, COLOR_BACKGROUND);

//----------------
//Do non-interactive stuff here
//----------------
//Test prints
if (test) {
UI_DrawString(24, 48, "Test 1", 6);
} else {
Expand All @@ -105,20 +120,29 @@ void Spectrum_Loop(void){
UI_DrawString(24, 24, gShortString, 2);
Int2Ascii(KEY_CurrentKey, 2);
UI_DrawString(48, 24, gShortString, 2);

// Placeholder for functions that will be needed
// BK4819_SetFrequency(someint32);
// someint16 = BK4819_GetRSSI();
//----------------

// Need to:
// Figure out starting freq
// Figure out freq range based on step count and step size
// Setup loop for freq range
// Tune freq (BK4819_SetFrequency above)
// Get rssi (BK4819_GetRSSI above) - assign to RssiValue[]
// ---Fix uses of CurrentFreqStep. It's an index value, not the real value.
// ---Figure out starting freq
// ---Figure out freq range based on step count and step size
// ---Setup loop for freq range
// Tune freq (BK4819_SetFrequency above)
// Get rssi (BK4819_GetRSSI above) - assign to RssiValue[]
// Resize bars
// Print freq ranges, step size, step count on screen

//----------------
//Do non-interactive stuff here
for (i = 0, i < CurrentStepCount, i++) {
uint32_t x = FreqMin;
BK4819_SetFrequency(x);
RssiValue[i] = BK4819_GetRSSI();
x += CurrentFreqStep;
}

DrawBars();
//----------------
//----------------

if (Key == KEY_1) {
Key = KEY_NONE;
Expand All @@ -143,12 +167,28 @@ void Spectrum_Loop(void){

void APP_Spectrum(void){

StepCount = 128;

StartFreq = gVfoInfo[gSettings.CurrentVfo].Frequency;
CurrentFreq = StartFreq;
// StartFreq = gVfoInfo[gSettings.CurrentVfo].Frequency;
CurrentFreq = gVfoState[gSettings.CurrentVfo].RX.Frequency;
CurrentModulation = gVfoState[gSettings.CurrentVfo].gModulationType;
CurrentFreqStepIndex = gFrequencyStep;
CurrentFreqStep = FREQUENCY_GetStep(CurrentFreqStepIndex);
CurrentStepCount = 128;


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


//---------------------------------------------------------------------------------------------
// These are probably going to be useful
//bool IsCenterMode() { return settings.scanStepIndex < STEP_1_0kHz; }

//uint8_t GetStepsCount() { return 128 >> settings.stepsCount; }

//uint16_t GetScanStep() { return StepFrequencyTable[settings.scanStepIndex]; }

//uint32_t GetFreqStart() { return IsCenterMode() ? currentFreq - (GetBW() >> 1) : currentFreq; }

//uint32_t GetFreqEnd() { return currentFreq + GetBW(); }
//---------------------------------------------------------------------------------------------

0 comments on commit 176b4cd

Please sign in to comment.