Skip to content

Commit

Permalink
Merge pull request #3 from kamilsss655/spectrum-display-known-channels
Browse files Browse the repository at this point in the history
Spectrum display known channels
  • Loading branch information
kamilsss655 committed Dec 16, 2023
2 parents 80bf95a + 09ccd82 commit 5e7c59b
Show file tree
Hide file tree
Showing 10 changed files with 170 additions and 46 deletions.
52 changes: 28 additions & 24 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,30 +22,31 @@ ENABLE_PWRON_PASSWORD := 0
ENABLE_DTMF_CALLING := 0

# ---- CUSTOM MODS ----
ENABLE_BIG_FREQ := 1
ENABLE_SMALL_BOLD := 1
ENABLE_KEEP_MEM_NAME := 1
ENABLE_WIDE_RX := 1
ENABLE_TX_WHEN_AM := 0
ENABLE_F_CAL_MENU := 0
ENABLE_CTCSS_TAIL_PHASE_SHIFT := 0
ENABLE_BOOT_BEEPS := 0
ENABLE_SHOW_CHARGE_LEVEL := 1
ENABLE_REVERSE_BAT_SYMBOL := 0
ENABLE_NO_CODE_SCAN_TIMEOUT := 1
ENABLE_AM_FIX := 1
ENABLE_AM_FIX_SHOW_DATA := 0
ENABLE_SQUELCH_MORE_SENSITIVE := 1
ENABLE_FASTER_CHANNEL_SCAN := 1
ENABLE_RSSI_BAR := 1
ENABLE_AUDIO_BAR := 1
ENABLE_COPY_CHAN_TO_VFO := 1
ENABLE_SPECTRUM := 1
ENABLE_REDUCE_LOW_MID_TX_POWER:= 0
ENABLE_BYP_RAW_DEMODULATORS := 0
ENABLE_BLMIN_TMP_OFF := 0
ENABLE_SCAN_RANGES := 1
ENABLE_SPECTRUM_COPY_VFO := 1
ENABLE_BIG_FREQ := 1
ENABLE_SMALL_BOLD := 1
ENABLE_KEEP_MEM_NAME := 1
ENABLE_WIDE_RX := 1
ENABLE_TX_WHEN_AM := 0
ENABLE_F_CAL_MENU := 0
ENABLE_CTCSS_TAIL_PHASE_SHIFT := 0
ENABLE_BOOT_BEEPS := 0
ENABLE_SHOW_CHARGE_LEVEL := 1
ENABLE_REVERSE_BAT_SYMBOL := 0
ENABLE_NO_CODE_SCAN_TIMEOUT := 1
ENABLE_AM_FIX := 1
ENABLE_AM_FIX_SHOW_DATA := 0
ENABLE_SQUELCH_MORE_SENSITIVE := 1
ENABLE_FASTER_CHANNEL_SCAN := 1
ENABLE_RSSI_BAR := 1
ENABLE_AUDIO_BAR := 1
ENABLE_COPY_CHAN_TO_VFO := 1
ENABLE_SPECTRUM := 1
ENABLE_REDUCE_LOW_MID_TX_POWER := 0
ENABLE_BYP_RAW_DEMODULATORS := 0
ENABLE_BLMIN_TMP_OFF := 0
ENABLE_SCAN_RANGES := 1
ENABLE_SPECTRUM_COPY_VFO := 1
ENABLE_SPECTRUM_SHOW_CHANNEL_NAME := 1

#############################################################

Expand Down Expand Up @@ -359,6 +360,9 @@ endif
ifeq ($(ENABLE_SPECTRUM_COPY_VFO),1)
CFLAGS += -DENABLE_SPECTRUM_COPY_VFO
endif
ifeq ($(ENABLE_SPECTRUM_SHOW_CHANNEL_NAME),1)
CFLAGS += -DENABLE_SPECTRUM_SHOW_CHANNEL_NAME
endif
ifeq ($(ENABLE_DTMF_CALLING),1)
CFLAGS += -DENABLE_DTMF_CALLING
endif
Expand Down
53 changes: 33 additions & 20 deletions app/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,34 @@ void COMMON_SwitchVFOs()
gRequestDisplayScreen = DISPLAY_MAIN;
}

void COMMON_SwitchToVFOMode()
{
gEeprom.ScreenChannel[gEeprom.TX_VFO] = gEeprom.FreqChannel[gEeprom.TX_VFO];
#ifdef ENABLE_VOICE
gAnotherVoiceID = VOICE_ID_FREQUENCY_MODE;
#endif
const uint8_t Vfo = gEeprom.TX_VFO;
SETTINGS_SaveVfoIndices();
RADIO_ConfigureChannel(Vfo, VFO_CONFIGURE_RELOAD);
return;
}
void COMMON_SwitchToChannelMode()
{
uint8_t Channel = RADIO_FindNextChannel(gEeprom.MrChannel[gEeprom.TX_VFO], 1, false, 0);
if (Channel != 0xFF)
{ // swap to channel mode
gEeprom.ScreenChannel[gEeprom.TX_VFO] = Channel;
#ifdef ENABLE_VOICE
AUDIO_SetVoiceID(0, VOICE_ID_CHANNEL_MODE);
AUDIO_SetDigitVoice(1, Channel + 1);
gAnotherVoiceID = (VOICE_ID_t)0xFE;
#endif
gRequestSaveVFO = true;
gVfoConfigureMode = VFO_CONFIGURE_RELOAD;
return;
}
}

void COMMON_SwitchVFOMode()
{
#ifdef ENABLE_NOAA
Expand All @@ -51,27 +79,12 @@ void COMMON_SwitchVFOMode()
{
if (IS_MR_CHANNEL(gTxVfo->CHANNEL_SAVE))
{ // swap to frequency mode
gEeprom.ScreenChannel[gEeprom.TX_VFO] = gEeprom.FreqChannel[gEeprom.TX_VFO];
#ifdef ENABLE_VOICE
gAnotherVoiceID = VOICE_ID_FREQUENCY_MODE;
#endif
gRequestSaveVFO = true;
gVfoConfigureMode = VFO_CONFIGURE_RELOAD;
return;
COMMON_SwitchToVFOMode();
}

uint8_t Channel = RADIO_FindNextChannel(gEeprom.MrChannel[gEeprom.TX_VFO], 1, false, 0);
if (Channel != 0xFF)
{ // swap to channel mode
gEeprom.ScreenChannel[gEeprom.TX_VFO] = Channel;
#ifdef ENABLE_VOICE
AUDIO_SetVoiceID(0, VOICE_ID_CHANNEL_MODE);
AUDIO_SetDigitVoice(1, Channel + 1);
gAnotherVoiceID = (VOICE_ID_t)0xFE;
#endif
gRequestSaveVFO = true;
gVfoConfigureMode = VFO_CONFIGURE_RELOAD;
return;
else
{
//swap to channel mode
COMMON_SwitchToChannelMode();
}
}
}
2 changes: 2 additions & 0 deletions app/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,7 @@
void COMMON_KeypadLockToggle();
void COMMON_SwitchVFOs();
void COMMON_SwitchVFOMode();
void COMMON_SwitchToVFOMode();
void COMMON_SwitchToChannelMode();

#endif
47 changes: 47 additions & 0 deletions app/spectrum.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
#include "driver/backlight.h"
#include "audio.h"
#include "ui/helper.h"
#ifdef ENABLE_SPECTRUM_COPY_VFO
#include "common.h"
#endif

struct FrequencyBandInfo {
uint32_t lower;
Expand All @@ -33,6 +36,13 @@ static uint16_t R30, R37, R3D, R43, R47, R48, R7E;
static uint32_t initialFreq;
static char String[32];

#ifdef ENABLE_SPECTRUM_SHOW_CHANNEL_NAME
uint32_t lastPeakFrequency;
bool isKnownChannel = false;
int channel;
char channelName[12];
#endif

bool isInitialized = false;
bool isListening = true;
bool monitorMode = false;
Expand Down Expand Up @@ -259,6 +269,12 @@ static void TuneToPeak() {
}
#ifdef ENABLE_SPECTRUM_COPY_VFO
static void ExitAndCopyToVfo() {
//if we are in the channel mode
if (IS_MR_CHANNEL(gTxVfo->CHANNEL_SAVE)){
// swap to frequency mode
COMMON_SwitchToVFOMode();
}

gTxVfo->STEP_SETTING = FREQUENCY_GetStepIdxFromStepFrequency(GetScanStep());
gTxVfo->Modulation = settings.modulationType;
// TODO: Add support for NARROW- bandwidth in VFO (settings etc)
Expand Down Expand Up @@ -384,6 +400,9 @@ static void UpdatePeakInfoForce() {
peak.rssi = scanInfo.rssiMax;
peak.f = scanInfo.fPeak;
peak.i = scanInfo.iPeak;
#ifdef ENABLE_SPECTRUM_SHOW_CHANNEL_NAME
LookupChannelInfo();
#endif
AutoTriggerLevel();
}

Expand Down Expand Up @@ -625,6 +644,16 @@ static void DrawStatus() {
#ifdef SPECTRUM_EXTRA_VALUES
sprintf(String, "%d/%d P:%d T:%d", settings.dbMin, settings.dbMax,
Rssi2DBm(peak.rssi), Rssi2DBm(settings.rssiTriggerLevel));
#elif ENABLE_SPECTRUM_SHOW_CHANNEL_NAME
if (isKnownChannel)
{
sprintf(String, "%d/%d M%i:%s", settings.dbMin, settings.dbMax, channel+1, channelName);
}
else
{
sprintf(String, "%d/%d", settings.dbMin, settings.dbMax);
}

#else
sprintf(String, "%d/%d", settings.dbMin, settings.dbMax);
#endif
Expand Down Expand Up @@ -663,6 +692,24 @@ static void DrawF(uint32_t f) {
sprintf(String, "%s", bwOptions[settings.listenBw]);
GUI_DisplaySmallest(String, 108, 7, false, true);
}
#ifdef ENABLE_SPECTRUM_SHOW_CHANNEL_NAME
void LookupChannelInfo() {
if (lastPeakFrequency == peak.f)
return;

lastPeakFrequency = peak.f;

channel = BOARD_gMR_fetchChannel(peak.f);

isKnownChannel = channel == -1 ? false : true;

if (isKnownChannel){
memmove(channelName, gMR_ChannelFrequencyAttributes[channel].Name, sizeof(channelName));
}

redrawStatus = true;
}
#endif

static void DrawNums() {

Expand Down
4 changes: 4 additions & 0 deletions app/spectrum.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,10 @@ typedef struct PeakInfo {

void APP_RunSpectrum(void);

#ifdef ENABLE_SPECTRUM_SHOW_CHANNEL_NAME
void LookupChannelInfo();
#endif

#endif /* ifndef SPECTRUM_H */

// vim: ft=c
32 changes: 31 additions & 1 deletion board.c
Original file line number Diff line number Diff line change
Expand Up @@ -758,7 +758,27 @@ void BOARD_EEPROM_Init(void)
return;
}
}

#ifdef ENABLE_SPECTRUM_SHOW_CHANNEL_NAME
BOARD_gMR_LoadChannels();
#endif

}
#ifdef ENABLE_SPECTRUM_SHOW_CHANNEL_NAME
// Load channel frequencies, names into global memory lookup table
void BOARD_gMR_LoadChannels() {
uint8_t i;
uint32_t freq_buf;

for (i = MR_CHANNEL_FIRST; i < MR_CHANNEL_LAST; i++)
{
freq_buf = BOARD_fetchChannelFrequency(i);

gMR_ChannelFrequencyAttributes[i].Frequency = RX_freq_check(freq_buf) == -1 ? 0 : freq_buf;
BOARD_fetchChannelName(gMR_ChannelFrequencyAttributes[i].Name, i);
}
}
#endif

void BOARD_EEPROM_LoadCalibration(void)
{
Expand Down Expand Up @@ -827,7 +847,17 @@ uint32_t BOARD_fetchChannelFrequency(const int channel)

return info.frequency;
}

#ifdef ENABLE_SPECTRUM_SHOW_CHANNEL_NAME
int BOARD_gMR_fetchChannel(const uint32_t freq)
{
for (int i = MR_CHANNEL_FIRST; i <= MR_CHANNEL_LAST; i++) {
if (gMR_ChannelFrequencyAttributes[i].Frequency == freq)
return i;
}
// Return -1 if no channel found
return -1;
}
#endif
void BOARD_fetchChannelName(char *s, const int channel)
{
int i;
Expand Down
4 changes: 4 additions & 0 deletions board.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ void BOARD_EEPROM_LoadCalibration(void);
uint32_t BOARD_fetchChannelFrequency(const int channel);
void BOARD_fetchChannelName(char *s, const int channel);
void BOARD_FactoryReset(bool bIsAll);
#ifdef ENABLE_SPECTRUM_SHOW_CHANNEL_NAME
void BOARD_gMR_LoadChannels();
int BOARD_gMR_fetchChannel(const uint32_t freq);
#endif

#endif

4 changes: 4 additions & 0 deletions misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ uint16_t gEEPROM_1F8C;

ChannelAttributes_t gMR_ChannelAttributes[FREQ_CHANNEL_LAST + 1];

#ifdef ENABLE_SPECTRUM_SHOW_CHANNEL_NAME
ChannelFrequencyAttributes gMR_ChannelFrequencyAttributes[MR_CHANNEL_LAST +1];
#endif

volatile uint16_t gBatterySaveCountdown_10ms = battery_save_count_10ms;

volatile bool gPowerSaveCountdownExpired;
Expand Down
10 changes: 10 additions & 0 deletions misc.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,16 @@ typedef union {
uint8_t __val;
} ChannelAttributes_t;

#ifdef ENABLE_SPECTRUM_SHOW_CHANNEL_NAME
typedef struct
{
uint32_t Frequency;
char Name[12];
} __attribute__((packed)) ChannelFrequencyAttributes;

extern ChannelFrequencyAttributes gMR_ChannelFrequencyAttributes[200];
#endif

extern ChannelAttributes_t gMR_ChannelAttributes[207];

extern volatile uint16_t gBatterySaveCountdown_10ms;
Expand Down
8 changes: 7 additions & 1 deletion settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "driver/uart.h"
#include "misc.h"
#include "settings.h"
#include "board.h"

EEPROM_Config_t gEeprom;

Expand Down Expand Up @@ -242,7 +243,7 @@ void SETTINGS_SaveChannel(uint8_t Channel, uint8_t VFO, const VFO_Info_t *pVFO,

if (IS_MR_CHANNEL(Channel))
{ // it's a memory channel

#ifndef ENABLE_KEEP_MEM_NAME
// clear/reset the channel name
//memset(&State, 0xFF, sizeof(State));
Expand All @@ -258,6 +259,11 @@ void SETTINGS_SaveChannel(uint8_t Channel, uint8_t VFO, const VFO_Info_t *pVFO,
memset(State, 0x00, sizeof(State)); // follow the QS way
memmove(State, pVFO->Name + 8, 2);
EEPROM_WriteBuffer(0x0F58 + OffsetMR, State);

#ifdef ENABLE_SPECTRUM_SHOW_CHANNEL_NAME
//update channel names stored in memory
BOARD_gMR_LoadChannels();
#endif
}
#endif
}
Expand Down

0 comments on commit 5e7c59b

Please sign in to comment.