Skip to content

Commit

Permalink
Maintain monitor state when up/down freq/chan
Browse files Browse the repository at this point in the history
  • Loading branch information
OneOfEleven committed Sep 26, 2023
1 parent 9d178c5 commit 14f154b
Show file tree
Hide file tree
Showing 11 changed files with 103 additions and 48 deletions.
45 changes: 31 additions & 14 deletions am_fix.c
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ const uint8_t orig_pga = 6; // -3dB
#endif

unsigned int counter = 0;

int16_t orig_dB_gain = -17;

#ifdef ENABLE_AM_FIX_TEST1
Expand All @@ -321,8 +321,14 @@ const uint8_t orig_pga = 6; // -3dB
// used to limit the max front end gain
unsigned int max_index = ARRAY_SIZE(am_fix_gain_table) - 1;

#ifndef ENABLE_AM_FIX_TEST1
// -89dBm, any higher and the AM demodulator starts to saturate/clip/distort
const int16_t desired_rssi = (-89 + 160) * 2;
#endif

void AM_fix_init(void)
{
{ // called at boot-up

/* unsigned int i;
for (i = 0; i < 2; i++)
{
Expand Down Expand Up @@ -359,6 +365,8 @@ const uint8_t orig_pga = 6; // -3dB
void AM_fix_reset(const int vfo)
{ // reset the AM fixer

counter = 0;

prev_rssi[vfo] = 0;

am_gain_hold_counter[vfo] = 0;
Expand All @@ -372,8 +380,6 @@ const uint8_t orig_pga = 6; // -3dB
#endif

am_fix_gain_table_index_prev[vfo] = 0;

// AM_fix_init(); // bootup calls this
}

// adjust the RX RF gain to try and prevent the AM demodulator from
Expand All @@ -388,20 +394,14 @@ const uint8_t orig_pga = 6; // -3dB
int16_t diff_dB;
int16_t rssi;

#ifndef ENABLE_AM_FIX_TEST1
// -89dBm, any higher and the AM demodulator starts to saturate/clip/distort
const int16_t desired_rssi = (-89 + 160) * 2; // dBm to ADC sample
#endif

counter++;

// but we're not in FM mode, we're in AM mode

switch (gCurrentFunction)
{
case FUNCTION_TRANSMIT:
case FUNCTION_BAND_SCOPE:
case FUNCTION_POWER_SAVE:
counter = 0;
return;

case FUNCTION_FOREGROUND:
Expand All @@ -414,6 +414,10 @@ const uint8_t orig_pga = 6; // -3dB
break;
}

if (counter > 0)
if (++counter >= 20) // limit display update rate to 200ms
counter = 0;

{ // sample the current RSSI level
// average it with the previous rssi (a bit of noise/spike immunity)
const int16_t new_rssi = BK4819_GetRSSI();
Expand All @@ -427,7 +431,11 @@ const uint8_t orig_pga = 6; // -3dB
if (gCurrentRSSI[vfo] != new_rssi)
{
gCurrentRSSI[vfo] = new_rssi;
gUpdateDisplay = ((counter & 15u) == 0); // limit the screen update rate to once every 150ms
if (counter == 0)
{
counter = 1;
gUpdateDisplay = true;
}
}
}

Expand Down Expand Up @@ -545,13 +553,21 @@ const uint8_t orig_pga = 6; // -3dB
if (gCurrentRSSI[vfo] != new_rssi)
{
gCurrentRSSI[vfo] = new_rssi;
gUpdateDisplay = ((counter & 15u) == 0); // limit the screen update rate to once every 150ms
if (counter == 0)
{
counter = 1;
gUpdateDisplay = true;
}
}
}
}

#ifdef ENABLE_AM_FIX_SHOW_DATA
gUpdateDisplay = ((counter & 15u) == 0); // limit the screen update rate to once every 150ms
if (counter == 0)
{
counter = 1;
gUpdateDisplay = true;
}
#endif
}

Expand All @@ -568,6 +584,7 @@ const uint8_t orig_pga = 6; // -3dB
const int16_t gain_dB = lna_short_dB[lna_short] + lna_dB[lna] + mixer_dB[mixer] + pga_dB[pga];
if (s != NULL)
sprintf(s, "idx %2d %4ddB %3u", index, gain_dB, prev_rssi[vfo]);
counter = 1;
}

#endif
Expand Down
48 changes: 28 additions & 20 deletions app/action.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,27 +66,25 @@ void ACTION_Power(void)
gRequestDisplayScreen = gScreenToDisplay;
}

static void ACTION_Monitor(void)
void ACTION_Monitor(void)
{
if (gCurrentFunction != FUNCTION_MONITOR)
{
{ // enable the monitor
RADIO_SelectVfos();

#ifdef ENABLE_NOAA
if (gRxVfo->CHANNEL_SAVE >= NOAA_CHANNEL_FIRST && gIsNoaaMode)
gNoaaChannel = gRxVfo->CHANNEL_SAVE - NOAA_CHANNEL_FIRST;
#endif

RADIO_SetupRegisters(true);

APP_StartListening(FUNCTION_MONITOR, false);

return;
}

gMonitor = false;

if (gScanState != SCAN_OFF)
{
ScanPauseDelayIn_10ms = 500; // 5 seconds
ScanPauseDelayIn_10ms = scan_pause_delay_in_1_10ms;
gScheduleScanListen = false;
gScanPauseMode = true;
}
Expand All @@ -98,7 +96,7 @@ static void ACTION_Monitor(void)
gScheduleNOAA = false;
}
#endif

RADIO_SetupRegisters(true);

#ifdef ENABLE_FMRADIO
Expand All @@ -117,22 +115,26 @@ void ACTION_Scan(bool bRestart)
#ifdef ENABLE_FMRADIO
if (gFmRadioMode)
{
if (gCurrentFunction != FUNCTION_RECEIVE && gCurrentFunction != FUNCTION_MONITOR && gCurrentFunction != FUNCTION_TRANSMIT)
if (gCurrentFunction != FUNCTION_RECEIVE &&
gCurrentFunction != FUNCTION_MONITOR &&
gCurrentFunction != FUNCTION_TRANSMIT)
{
GUI_SelectNextDisplay(DISPLAY_FM);


gMonitor = false;

if (gFM_ScanState != FM_SCAN_OFF)
{
FM_PlayAndUpdate();

#ifdef ENABLE_VOICE
gAnotherVoiceID = VOICE_ID_SCANNING_STOP;
#endif
}
else
{
uint16_t Frequency;

if (bRestart)
{
gFM_AutoScan = true;
Expand All @@ -146,23 +148,25 @@ void ACTION_Scan(bool bRestart)
gFM_ChannelPosition = 0;
Frequency = gEeprom.FM_FrequencyPlaying;
}

BK1080_GetFrequencyDeviation(Frequency);
FM_Tune(Frequency, 1, bRestart);

#ifdef ENABLE_VOICE
gAnotherVoiceID = VOICE_ID_SCANNING_BEGIN;
#endif
}
}

return;
}
#endif

if (gScreenToDisplay != DISPLAY_SCANNER)
{ // not scanning

gMonitor = false;

RADIO_SelectVfos();

#ifdef ENABLE_NOAA
Expand Down Expand Up @@ -201,6 +205,8 @@ void ACTION_Scan(bool bRestart)
if (!bRestart)
{ // scanning

gMonitor = false;

SCANNER_Stop();

#ifdef ENABLE_VOICE
Expand Down Expand Up @@ -241,19 +247,21 @@ void ACTION_Vox(void)
if (gFmRadioMode)
{
FM_TurnOff();

gInputBoxIndex = 0;
gVoxResumeCountdown = 80;
gFlagReconfigureVfos = true;
gRequestDisplayScreen = DISPLAY_MAIN;
return;
}


gMonitor = false;

RADIO_SelectVfos();
RADIO_SetupRegisters(true);

FM_Start();

gInputBoxIndex = 0;
gRequestDisplayScreen = DISPLAY_FM;
}
Expand All @@ -280,7 +288,7 @@ void ACTION_Handle(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld)
return;
}
}

#ifdef ENABLE_VOICE
gAnotherVoiceID = VOICE_ID_CANCEL;
#endif
Expand Down
2 changes: 1 addition & 1 deletion app/action.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

//static void ACTION_FlashLight(void)
void ACTION_Power(void);
//static void ACTION_Monitor(void)
void ACTION_Monitor(void);
void ACTION_Scan(bool bFlag);
void ACTION_Vox(void);
#ifdef ENABLE_ALARM
Expand Down
26 changes: 20 additions & 6 deletions app/app.c
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ static void APP_HandleIncoming(void)
}
}

APP_StartListening(FUNCTION_RECEIVE, false);
APP_StartListening(gMonitor ? FUNCTION_MONITOR : FUNCTION_RECEIVE, false);
}

static void APP_HandleReceive(void)
Expand Down Expand Up @@ -979,14 +979,14 @@ void APP_Update(void)
if (IS_FREQ_CHANNEL(gNextMrChannel))
{
if (gCurrentFunction == FUNCTION_INCOMING)
APP_StartListening(FUNCTION_RECEIVE, true);
APP_StartListening(gMonitor ? FUNCTION_MONITOR : FUNCTION_RECEIVE, true);
else
FREQ_NextChannel();
}
else
{
if (gCurrentCodeType == CODE_TYPE_OFF && gCurrentFunction == FUNCTION_INCOMING)
APP_StartListening(FUNCTION_RECEIVE, true);
APP_StartListening(gMonitor ? FUNCTION_MONITOR : FUNCTION_RECEIVE, true);
else
MR_NextChannel();
}
Expand Down Expand Up @@ -1726,8 +1726,13 @@ void APP_TimeSlice500ms(void)
gAskToDelete = false;

#ifdef ENABLE_FMRADIO
if (gFmRadioMode && gCurrentFunction != FUNCTION_RECEIVE && gCurrentFunction != FUNCTION_MONITOR && gCurrentFunction != FUNCTION_TRANSMIT)
if (gFmRadioMode &&
gCurrentFunction != FUNCTION_RECEIVE &&
gCurrentFunction != FUNCTION_MONITOR &&
gCurrentFunction != FUNCTION_TRANSMIT)
{
GUI_SelectNextDisplay(DISPLAY_FM);
}
else
#endif
#ifdef ENABLE_NO_SCAN_TIMEOUT
Expand All @@ -1747,7 +1752,11 @@ void APP_TimeSlice500ms(void)
if (--gFM_ResumeCountdown_500ms == 0)
{
RADIO_SetVfoState(VFO_STATE_NORMAL);
if (gCurrentFunction != FUNCTION_RECEIVE && gCurrentFunction != FUNCTION_TRANSMIT && gCurrentFunction != FUNCTION_MONITOR && gFmRadioMode)

if (gCurrentFunction != FUNCTION_RECEIVE &&
gCurrentFunction != FUNCTION_TRANSMIT &&
gCurrentFunction != FUNCTION_MONITOR &&
gFmRadioMode)
{ // switch back to FM radio mode
FM_Start();
GUI_SelectNextDisplay(DISPLAY_FM);
Expand Down Expand Up @@ -1919,7 +1928,7 @@ void CHANNEL_Next(bool bFlag, int8_t Direction)
FREQ_NextChannel();
}

ScanPauseDelayIn_10ms = 50; // 500ms
ScanPauseDelayIn_10ms = scan_pause_delay_in_2_10ms;
gScheduleScanListen = false;
gRxReceptionMode = RX_MODE_NONE;
gScanPauseMode = false;
Expand Down Expand Up @@ -2340,6 +2349,9 @@ static void APP_ProcessKey(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld)
gVFO_RSSI_bar_level[1] = 0;

gFlagReconfigureVfos = false;

if (gMonitor)
ACTION_Monitor(); // 1of11
}

if (gFlagRefreshSetting)
Expand All @@ -2350,6 +2362,8 @@ static void APP_ProcessKey(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld)

if (gFlagStartScan)
{
gMonitor = false;

#ifdef ENABLE_VOICE
AUDIO_SetVoiceID(0, VOICE_ID_SCANNING_BEGIN);
AUDIO_PlaySingleVoice(true);
Expand Down
4 changes: 2 additions & 2 deletions app/menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ void MENU_StartCssScan(int8_t Direction)

MENU_SelectNextCode();

ScanPauseDelayIn_10ms = 50;
ScanPauseDelayIn_10ms = scan_pause_delay_in_2_10ms;
gScheduleScanListen = false;
}

Expand Down Expand Up @@ -746,7 +746,7 @@ void MENU_SelectNextCode(void)

RADIO_SetupRegisters(true);

ScanPauseDelayIn_10ms = (gSelectedCodeType == CODE_TYPE_CONTINUOUS_TONE) ? 20 : 30;
ScanPauseDelayIn_10ms = (gSelectedCodeType == CODE_TYPE_CONTINUOUS_TONE) ? scan_pause_delay_in_3_10ms : scan_pause_delay_in_4_10ms;

gUpdateDisplay = true;
}
Expand Down
Binary file modified firmware.bin
Binary file not shown.
Binary file modified firmware.packed.bin
Binary file not shown.
6 changes: 6 additions & 0 deletions functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,15 +125,21 @@ void FUNCTION_Select(FUNCTION_Type_t Function)
return;

case FUNCTION_MONITOR:
gMonitor = true;
break;

case FUNCTION_INCOMING:
case FUNCTION_RECEIVE:
gMonitor = false;
break;

case FUNCTION_POWER_SAVE:
gPowerSave_10ms = gEeprom.BATTERY_SAVE * 10;
gPowerSaveCountdownExpired = false;

gRxIdleMode = true;

gMonitor = false;

BK4819_DisableVox();
BK4819_Sleep();
Expand Down
Loading

0 comments on commit 14f154b

Please sign in to comment.