Skip to content

Commit

Permalink
feat: toggle presets by 3/9
Browse files Browse the repository at this point in the history
  • Loading branch information
fagci committed Oct 5, 2023
1 parent 6193cdd commit a24ba63
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 28 deletions.
44 changes: 38 additions & 6 deletions app/spectrum.c
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ static void ResetPeak() {
peak.rssi = 0;
}

bool IsCenterMode() { return settings.scanStepIndex < S_STEP_2_5kHz; }
bool IsCenterMode() { return settings.scanStepIndex < S_STEP_1_0kHz; }
uint8_t GetStepsCount() { return 128 >> settings.stepsCount; }
uint16_t GetScanStep() { return scanStepValues[settings.scanStepIndex]; }
uint32_t GetBW() { return GetStepsCount() * GetScanStep(); }
Expand Down Expand Up @@ -596,6 +596,40 @@ static void UpdateRssiTriggerLevel(bool inc) {
SYSTEM_DelayMs(10);
}

static void SelectPreset(FreqPreset p) {
currentFreq = p.fStart;
settings.scanStepIndex = p.stepSizeIndex;
settings.listenBw = p.listenBW;
settings.modulationType = p.modulationType;
settings.stepsCount = p.stepsCountIndex;
RelaunchScan();
ResetBlacklist();
redrawScreen = true;
}

static void SelectNearestPreset(bool inc) {
FreqPreset p;
const uint8_t SZ = ARRAY_SIZE(freqPresets);
if (inc) {
for (int i = 0; i < SZ; ++i) {
p = freqPresets[i];
if (currentFreq < p.fStart) {
SelectPreset(p);
return;
}
}
} else {
for (int i = SZ - 1; i >= 0; --i) {
p = freqPresets[i];
if (currentFreq > p.fEnd) {
SelectPreset(p);
return;
}
}
}
SelectPreset(p);
}

static void UpdateScanStep(bool inc) {
if (inc && settings.scanStepIndex < S_STEP_100_0kHz) {
settings.scanStepIndex++;
Expand Down Expand Up @@ -929,8 +963,10 @@ static void DrawArrow(uint8_t x) {
static void OnKeyDown(uint8_t key) {
switch (key) {
case KEY_3:
SelectNearestPreset(true);
break;
case KEY_9:
SelectNearestPreset(false);
break;
case KEY_1:
UpdateScanStep(true);
Expand Down Expand Up @@ -1372,11 +1408,7 @@ static void AutomaticPresetChoose(uint32_t f) {
for (int i = 0; i < ARRAY_SIZE(freqPresets); ++i) {
FreqPreset p = freqPresets[i];
if (f >= p.fStart && f <= freqPresets[i].fEnd) {
currentFreq = p.fStart;
settings.scanStepIndex = p.stepSizeIndex;
settings.listenBw = p.listenBW;
settings.modulationType = p.modulationType;
settings.stepsCount = p.stepsCountIndex;
SelectPreset(p);
}
}
}
Expand Down
18 changes: 9 additions & 9 deletions app/spectrum.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,24 +170,24 @@ typedef struct PeakInfo {
} PeakInfo;

typedef struct FreqPreset {
const char name[16];
const uint32_t fStart;
const uint32_t fEnd;
const StepsCount stepsCountIndex;
const uint8_t stepSizeIndex;
const ModulationType modulationType;
const BK4819_FilterBandwidth_t listenBW;
char name[16];
uint32_t fStart;
uint32_t fEnd;
StepsCount stepsCountIndex;
uint8_t stepSizeIndex;
ModulationType modulationType;
BK4819_FilterBandwidth_t listenBW;
} FreqPreset;

static const FreqPreset freqPresets[] = {
{"CB", 2697500, 2785500, STEPS_128, S_STEP_5_0kHz, MOD_FM,
BK4819_FILTER_BW_NARROW},
{"17m", 1806800, 1831800, STEPS_128, S_STEP_1_0kHz, MOD_USB,
BK4819_FILTER_BW_NARROWER},
{"15m", 2100000, 2145000, STEPS_128, S_STEP_1_0kHz, MOD_USB,
BK4819_FILTER_BW_NARROWER},
{"12m", 2489000, 2514000, STEPS_128, S_STEP_1_0kHz, MOD_USB,
BK4819_FILTER_BW_NARROWER},
{"CB", 2697500, 2785500, STEPS_128, S_STEP_5_0kHz, MOD_FM,
BK4819_FILTER_BW_NARROW},
{"10m", 2800000, 2970000, STEPS_128, S_STEP_1_0kHz, MOD_USB,
BK4819_FILTER_BW_NARROWER},
{"2m", 14400000, 14600000, STEPS_128, S_STEP_25_0kHz, MOD_FM,
Expand Down
28 changes: 15 additions & 13 deletions frequencies.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,25 @@
#ifndef FREQUENCIES_H
#define FREQUENCIES_H

#include <stdint.h>
#include "radio.h"
#include <stdint.h>

enum FREQUENCY_Band_t {
BAND1_50MHz = 0,
BAND2_108MHz,
BAND3_136MHz,
BAND4_174MHz,
BAND5_350MHz,
BAND6_400MHz,
BAND7_470MHz,
BAND1_50MHz,
BAND2_108MHz,
BAND3_136MHz,
BAND4_174MHz,
BAND5_350MHz,
BAND6_400MHz,
BAND7_470MHz,
};

typedef enum FREQUENCY_Band_t FREQUENCY_Band_t;

struct FrequencyBandInfo {
uint32_t lower;
uint32_t upper;
uint32_t middle;
uint32_t lower;
uint32_t upper;
uint32_t middle;
};
extern const struct FrequencyBandInfo FrequencyBandTable[7];
#if defined(ENABLE_NOAA)
Expand All @@ -44,9 +44,11 @@ extern const uint32_t NoaaFrequencyTable[10];
extern const uint16_t StepFrequencyTable[7];

FREQUENCY_Band_t FREQUENCY_GetBand(uint32_t Frequency);
uint8_t FREQUENCY_CalculateOutputPower(uint8_t TxpLow, uint8_t TxpMid, uint8_t TxpHigh, int32_t LowerLimit, int32_t Middle, int32_t UpperLimit, int32_t Frequency);
uint8_t FREQUENCY_CalculateOutputPower(uint8_t TxpLow, uint8_t TxpMid,
uint8_t TxpHigh, int32_t LowerLimit,
int32_t Middle, int32_t UpperLimit,
int32_t Frequency);
uint32_t FREQUENCY_FloorToStep(uint32_t Upper, uint32_t Step, uint32_t Lower);
int FREQUENCY_Check(VFO_Info_t *pInfo);

#endif

0 comments on commit a24ba63

Please sign in to comment.