Fix restore VFO settings after scan

This commit is contained in:
Krzysiek Egzmont 2023-10-16 21:57:32 +02:00
parent f70707e17f
commit 298ff29cf4
8 changed files with 187 additions and 182 deletions

View File

@ -193,7 +193,7 @@ void ACTION_Scan(bool bRestart)
gEeprom.SCAN_LIST_DEFAULT = (gEeprom.SCAN_LIST_DEFAULT + 1) % 3; gEeprom.SCAN_LIST_DEFAULT = (gEeprom.SCAN_LIST_DEFAULT + 1) % 3;
// jump to the next channel // jump to the next channel
CHANNEL_Next(true, gScanStateDir); SCANNER_NextChannel(false, gScanStateDir);
gScanPauseDelayIn_10ms = 1; gScanPauseDelayIn_10ms = 1;
gScheduleScanListen = false; gScheduleScanListen = false;
@ -212,7 +212,7 @@ void ACTION_Scan(bool bRestart)
else else
{ // start scanning { // start scanning
CHANNEL_Next(true, SCAN_FWD); SCANNER_NextChannel(true, SCAN_FWD);
#ifdef ENABLE_VOICE #ifdef ENABLE_VOICE
AUDIO_SetVoiceID(0, VOICE_ID_SCANNING_BEGIN); AUDIO_SetVoiceID(0, VOICE_ID_SCANNING_BEGIN);
@ -235,7 +235,7 @@ void ACTION_Scan(bool bRestart)
gEeprom.SCAN_LIST_DEFAULT = (gEeprom.SCAN_LIST_DEFAULT + 1) % 3; gEeprom.SCAN_LIST_DEFAULT = (gEeprom.SCAN_LIST_DEFAULT + 1) % 3;
// jump to the next channel // jump to the next channel
CHANNEL_Next(true, gScanStateDir); SCANNER_NextChannel(false, gScanStateDir);
gScanPauseDelayIn_10ms = 1; gScanPauseDelayIn_10ms = 1;
gScheduleScanListen = false; gScheduleScanListen = false;

163
app/app.c
View File

@ -621,123 +621,6 @@ uint32_t APP_SetFrequencyByStep(VFO_Info_t *pInfo, int8_t Step)
return Frequency; return Frequency;
} }
static void FREQ_NextChannel(void)
{
gRxVfo->freq_config_RX.Frequency = APP_SetFrequencyByStep(gRxVfo, gScanStateDir);
RADIO_ApplyOffset(gRxVfo);
RADIO_ConfigureSquelchAndOutputPower(gRxVfo);
RADIO_SetupRegisters(true);
#ifdef ENABLE_FASTER_CHANNEL_SCAN
gScanPauseDelayIn_10ms = 9; // 90ms
#else
gScanPauseDelayIn_10ms = scan_pause_delay_in_6_10ms;
#endif
bScanKeepFrequency = false;
gUpdateDisplay = true;
}
static void MR_NextChannel(void)
{
static unsigned int prev_mr_chan = 0;
const bool enabled = (gEeprom.SCAN_LIST_DEFAULT < 2) ? gEeprom.SCAN_LIST_ENABLED[gEeprom.SCAN_LIST_DEFAULT] : true;
const int chan1 = (gEeprom.SCAN_LIST_DEFAULT < 2) ? gEeprom.SCANLIST_PRIORITY_CH1[gEeprom.SCAN_LIST_DEFAULT] : -1;
const int chan2 = (gEeprom.SCAN_LIST_DEFAULT < 2) ? gEeprom.SCANLIST_PRIORITY_CH2[gEeprom.SCAN_LIST_DEFAULT] : -1;
const unsigned int prev_chan = gNextMrChannel;
unsigned int chan = 0;
if (enabled)
{
switch (gCurrentScanList)
{
case SCAN_NEXT_CHAN_SCANLIST1:
prev_mr_chan = gNextMrChannel;
if (chan1 >= 0)
{
if (RADIO_CheckValidChannel(chan1, false, 0))
{
gCurrentScanList = SCAN_NEXT_CHAN_SCANLIST1;
gNextMrChannel = chan1;
break;
}
}
[[fallthrough]];
case SCAN_NEXT_CHAN_SCANLIST2:
if (chan2 >= 0)
{
if (RADIO_CheckValidChannel(chan2, false, 0))
{
gCurrentScanList = SCAN_NEXT_CHAN_SCANLIST2;
gNextMrChannel = chan2;
break;
}
}
[[fallthrough]];
// this bit doesn't yet work if the other VFO is a frequency
case SCAN_NEXT_CHAN_DUAL_WATCH:
// dual watch is enabled - include the other VFO in the scan
// if (gEeprom.DUAL_WATCH != DUAL_WATCH_OFF)
// {
// chan = (gEeprom.RX_VFO + 1) & 1u;
// chan = gEeprom.ScreenChannel[chan];
// if (chan <= MR_CHANNEL_LAST)
// {
// gCurrentScanList = SCAN_NEXT_CHAN_DUAL_WATCH;
// gNextMrChannel = chan;
// break;
// }
// }
default:
case SCAN_NEXT_CHAN_MR:
gCurrentScanList = SCAN_NEXT_CHAN_MR;
gNextMrChannel = prev_mr_chan;
chan = 0xff;
break;
}
}
if (!enabled || chan == 0xff)
{
chan = RADIO_FindNextChannel(gNextMrChannel + gScanStateDir, gScanStateDir, (gEeprom.SCAN_LIST_DEFAULT < 2) ? true : false, gEeprom.SCAN_LIST_DEFAULT);
if (chan == 0xFF)
{ // no valid channel found
chan = MR_CHANNEL_FIRST;
// return;
}
gNextMrChannel = chan;
}
if (gNextMrChannel != prev_chan)
{
gEeprom.MrChannel[ gEeprom.RX_VFO] = gNextMrChannel;
gEeprom.ScreenChannel[gEeprom.RX_VFO] = gNextMrChannel;
RADIO_ConfigureChannel(gEeprom.RX_VFO, VFO_CONFIGURE_RELOAD);
RADIO_SetupRegisters(true);
gUpdateDisplay = true;
}
#ifdef ENABLE_FASTER_CHANNEL_SCAN
gScanPauseDelayIn_10ms = 9; // 90ms .. <= ~60ms it misses signals (squelch response and/or PLL lock time) ?
#else
gScanPauseDelayIn_10ms = scan_pause_delay_in_3_10ms;
#endif
bScanKeepFrequency = false;
if (enabled)
if (++gCurrentScanList >= SCAN_NEXT_NUM)
gCurrentScanList = SCAN_NEXT_CHAN_SCANLIST1; // back round we go
}
#ifdef ENABLE_NOAA #ifdef ENABLE_NOAA
static void NOAA_IncreaseChannel(void) static void NOAA_IncreaseChannel(void)
{ {
@ -1072,25 +955,7 @@ void APP_Update(void)
if (gScreenToDisplay != DISPLAY_SCANNER && gScanStateDir != SCAN_OFF && gScheduleScanListen && !gPttIsPressed) if (gScreenToDisplay != DISPLAY_SCANNER && gScanStateDir != SCAN_OFF && gScheduleScanListen && !gPttIsPressed)
#endif #endif
{ // scanning { // scanning
SCANNER_ContinueScanning();
if (IS_FREQ_CHANNEL(gNextMrChannel))
{
if (gCurrentFunction == FUNCTION_INCOMING)
APP_StartListening(gMonitor ? FUNCTION_MONITOR : FUNCTION_RECEIVE, true);
else
FREQ_NextChannel(); // switch to next frequency
}
else
{
if (gCurrentCodeType == CODE_TYPE_OFF && gCurrentFunction == FUNCTION_INCOMING)
APP_StartListening(gMonitor ? FUNCTION_MONITOR : FUNCTION_RECEIVE, true);
else
MR_NextChannel(); // switch to next channel
}
gScanPauseMode = false;
gRxReceptionMode = RX_MODE_NONE;
gScheduleScanListen = false;
} }
#ifdef ENABLE_VOICE #ifdef ENABLE_VOICE
@ -2075,33 +1940,7 @@ void APP_TimeSlice500ms(void)
} }
#endif #endif
void CHANNEL_Next(const bool bFlag, const int8_t scan_direction)
{
RADIO_SelectVfos();
gNextMrChannel = gRxVfo->CHANNEL_SAVE;
gCurrentScanList = SCAN_NEXT_CHAN_SCANLIST1;
gScanStateDir = scan_direction;
if (gNextMrChannel <= MR_CHANNEL_LAST)
{ // channel mode
if (bFlag)
gRestoreMrChannel = gNextMrChannel;
MR_NextChannel();
}
else
{ // frequency mode
if (bFlag)
gRestoreFrequency = gRxVfo->freq_config_RX.Frequency;
FREQ_NextChannel();
}
gScanPauseDelayIn_10ms = scan_pause_delay_in_2_10ms;
gScheduleScanListen = false;
gRxReceptionMode = RX_MODE_NONE;
gScanPauseMode = false;
bScanKeepFrequency = false;
}
static void APP_ProcessKey(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld) static void APP_ProcessKey(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld)
{ {

View File

@ -29,7 +29,6 @@ extern const uint8_t orig_mixer;
extern const uint8_t orig_pga; extern const uint8_t orig_pga;
void APP_EndTransmission(void); void APP_EndTransmission(void);
void CHANNEL_Next(const bool bFlag, const int8_t scan_direction);
void APP_StartListening(FUNCTION_Type_t Function, const bool reset_am_fix); void APP_StartListening(FUNCTION_Type_t Function, const bool reset_am_fix);
uint32_t APP_SetFrequencyByStep(VFO_Info_t *pInfo, int8_t Step); uint32_t APP_SetFrequencyByStep(VFO_Info_t *pInfo, int8_t Step);
void APP_Update(void); void APP_Update(void);

View File

@ -803,7 +803,7 @@ static void MAIN_Key_UP_DOWN(bool bKeyPressed, bool bKeyHeld, int8_t Direction)
} }
// jump to the next channel // jump to the next channel
CHANNEL_Next(false, Direction); SCANNER_NextChannel(false, Direction);
gScanPauseDelayIn_10ms = 1; gScanPauseDelayIn_10ms = 1;
gScheduleScanListen = false; gScheduleScanListen = false;

View File

@ -14,6 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
#include "app/app.h"
#include "app/dtmf.h" #include "app/dtmf.h"
#include "app/generic.h" #include "app/generic.h"
#include "app/scanner.h" #include "app/scanner.h"
@ -43,6 +44,7 @@ uint8_t gScanHitCount;
bool gScanUseCssResult; bool gScanUseCssResult;
int8_t gScanStateDir; int8_t gScanStateDir;
bool bScanKeepFrequency; bool bScanKeepFrequency;
uint8_t gRestoreMrChannel;
static void SCANNER_Key_DIGITS(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld) static void SCANNER_Key_DIGITS(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld)
{ {
@ -362,10 +364,10 @@ void SCANNER_Start(void)
RADIO_SelectVfos(); RADIO_SelectVfos();
#ifdef ENABLE_NOAA #ifdef ENABLE_NOAA
if (IS_NOAA_CHANNEL(gRxVfo->CHANNEL_SAVE)) if (IS_NOAA_CHANNEL(gRxVfo->CHANNEL_SAVE))
gRxVfo->CHANNEL_SAVE = FREQ_CHANNEL_FIRST + BAND6_400MHz; gRxVfo->CHANNEL_SAVE = FREQ_CHANNEL_FIRST + BAND6_400MHz;
#endif #endif
BackupStep = gRxVfo->STEP_SETTING; BackupStep = gRxVfo->STEP_SETTING;
BackupFrequency = gRxVfo->StepFrequency; BackupFrequency = gRxVfo->StepFrequency;
@ -377,9 +379,9 @@ void SCANNER_Start(void)
RADIO_SetupRegisters(true); RADIO_SetupRegisters(true);
#ifdef ENABLE_NOAA #ifdef ENABLE_NOAA
gIsNoaaMode = false; gIsNoaaMode = false;
#endif #endif
if (gScanSingleFrequency) if (gScanSingleFrequency)
{ {
@ -414,9 +416,9 @@ void SCANNER_Start(void)
g_CDCSS_Lost = false; g_CDCSS_Lost = false;
gCDCSSCodeType = 0; gCDCSSCodeType = 0;
g_CTCSS_Lost = false; g_CTCSS_Lost = false;
#ifdef ENABLE_VOX #ifdef ENABLE_VOX
g_VOX_Lost = false; g_VOX_Lost = false;
#endif #endif
g_SquelchLost = false; g_SquelchLost = false;
gScannerEditState = 0; gScannerEditState = 0;
gScanProgressIndicator = 0; gScanProgressIndicator = 0;
@ -424,8 +426,6 @@ void SCANNER_Start(void)
void SCANNER_Stop(void) void SCANNER_Stop(void)
{ {
const uint8_t Previous = gRestoreMrChannel;
gScanStateDir = SCAN_OFF; gScanStateDir = SCAN_OFF;
if (!bScanKeepFrequency) if (!bScanKeepFrequency)
@ -433,7 +433,7 @@ void SCANNER_Stop(void)
if (gNextMrChannel <= MR_CHANNEL_LAST) if (gNextMrChannel <= MR_CHANNEL_LAST)
{ {
gEeprom.MrChannel[gEeprom.RX_VFO] = gRestoreMrChannel; gEeprom.MrChannel[gEeprom.RX_VFO] = gRestoreMrChannel;
gEeprom.ScreenChannel[gEeprom.RX_VFO] = Previous; gEeprom.ScreenChannel[gEeprom.RX_VFO] = gRestoreMrChannel;
RADIO_ConfigureChannel(gEeprom.RX_VFO, VFO_CONFIGURE_RELOAD); RADIO_ConfigureChannel(gEeprom.RX_VFO, VFO_CONFIGURE_RELOAD);
} }
@ -460,3 +460,170 @@ void SCANNER_Stop(void)
gUpdateStatus = true; gUpdateStatus = true;
} }
static void SCANNER_NextFreqChannel(void)
{
gRxVfo->freq_config_RX.Frequency = APP_SetFrequencyByStep(gRxVfo, gScanStateDir);
RADIO_ApplyOffset(gRxVfo);
RADIO_ConfigureSquelchAndOutputPower(gRxVfo);
RADIO_SetupRegisters(true);
#ifdef ENABLE_FASTER_CHANNEL_SCAN
gScanPauseDelayIn_10ms = 9; // 90ms
#else
gScanPauseDelayIn_10ms = scan_pause_delay_in_6_10ms;
#endif
bScanKeepFrequency = false;
gUpdateDisplay = true;
}
static void SCANNER_NextMemChannel(void)
{
static unsigned int prev_mr_chan = 0;
const bool enabled = (gEeprom.SCAN_LIST_DEFAULT < 2) ? gEeprom.SCAN_LIST_ENABLED[gEeprom.SCAN_LIST_DEFAULT] : true;
const int chan1 = (gEeprom.SCAN_LIST_DEFAULT < 2) ? gEeprom.SCANLIST_PRIORITY_CH1[gEeprom.SCAN_LIST_DEFAULT] : -1;
const int chan2 = (gEeprom.SCAN_LIST_DEFAULT < 2) ? gEeprom.SCANLIST_PRIORITY_CH2[gEeprom.SCAN_LIST_DEFAULT] : -1;
const unsigned int prev_chan = gNextMrChannel;
unsigned int chan = 0;
if (enabled)
{
switch (gCurrentScanList)
{
case SCAN_NEXT_CHAN_SCANLIST1:
prev_mr_chan = gNextMrChannel;
if (chan1 >= 0)
{
if (RADIO_CheckValidChannel(chan1, false, 0))
{
gCurrentScanList = SCAN_NEXT_CHAN_SCANLIST1;
gNextMrChannel = chan1;
break;
}
}
[[fallthrough]];
case SCAN_NEXT_CHAN_SCANLIST2:
if (chan2 >= 0)
{
if (RADIO_CheckValidChannel(chan2, false, 0))
{
gCurrentScanList = SCAN_NEXT_CHAN_SCANLIST2;
gNextMrChannel = chan2;
break;
}
}
[[fallthrough]];
// this bit doesn't yet work if the other VFO is a frequency
case SCAN_NEXT_CHAN_DUAL_WATCH:
// dual watch is enabled - include the other VFO in the scan
// if (gEeprom.DUAL_WATCH != DUAL_WATCH_OFF)
// {
// chan = (gEeprom.RX_VFO + 1) & 1u;
// chan = gEeprom.ScreenChannel[chan];
// if (chan <= MR_CHANNEL_LAST)
// {
// gCurrentScanList = SCAN_NEXT_CHAN_DUAL_WATCH;
// gNextMrChannel = chan;
// break;
// }
// }
default:
case SCAN_NEXT_CHAN_MR:
gCurrentScanList = SCAN_NEXT_CHAN_MR;
gNextMrChannel = prev_mr_chan;
chan = 0xff;
break;
}
}
if (!enabled || chan == 0xff)
{
chan = RADIO_FindNextChannel(gNextMrChannel + gScanStateDir, gScanStateDir, (gEeprom.SCAN_LIST_DEFAULT < 2) ? true : false, gEeprom.SCAN_LIST_DEFAULT);
if (chan == 0xFF)
{ // no valid channel found
chan = MR_CHANNEL_FIRST;
// return;
}
gNextMrChannel = chan;
}
if (gNextMrChannel != prev_chan)
{
gEeprom.MrChannel[ gEeprom.RX_VFO] = gNextMrChannel;
gEeprom.ScreenChannel[gEeprom.RX_VFO] = gNextMrChannel;
RADIO_ConfigureChannel(gEeprom.RX_VFO, VFO_CONFIGURE_RELOAD);
RADIO_SetupRegisters(true);
gUpdateDisplay = true;
}
#ifdef ENABLE_FASTER_CHANNEL_SCAN
gScanPauseDelayIn_10ms = 9; // 90ms .. <= ~60ms it misses signals (squelch response and/or PLL lock time) ?
#else
gScanPauseDelayIn_10ms = scan_pause_delay_in_3_10ms;
#endif
bScanKeepFrequency = false;
if (enabled)
if (++gCurrentScanList >= SCAN_NEXT_NUM)
gCurrentScanList = SCAN_NEXT_CHAN_SCANLIST1; // back round we go
}
void SCANNER_NextChannel(const bool storeBackupSettings, const int8_t scan_direction)
{
RADIO_SelectVfos();
gNextMrChannel = gRxVfo->CHANNEL_SAVE;
gCurrentScanList = SCAN_NEXT_CHAN_SCANLIST1;
gScanStateDir = scan_direction;
if (gNextMrChannel <= MR_CHANNEL_LAST)
{ // channel mode
if (storeBackupSettings)
gRestoreMrChannel = gNextMrChannel;
SCANNER_NextMemChannel();
}
else
{ // frequency mode
if (storeBackupSettings)
gRestoreFrequency = gRxVfo->freq_config_RX.Frequency;
SCANNER_NextFreqChannel();
}
gScanPauseDelayIn_10ms = scan_pause_delay_in_2_10ms;
gScheduleScanListen = false;
gRxReceptionMode = RX_MODE_NONE;
gScanPauseMode = false;
bScanKeepFrequency = false;
}
void SCANNER_ContinueScanning()
{
if (IS_FREQ_CHANNEL(gNextMrChannel))
{
if (gCurrentFunction == FUNCTION_INCOMING)
APP_StartListening(gMonitor ? FUNCTION_MONITOR : FUNCTION_RECEIVE, true);
else
SCANNER_NextFreqChannel(); // switch to next frequency
}
else
{
if (gCurrentCodeType == CODE_TYPE_OFF && gCurrentFunction == FUNCTION_INCOMING)
APP_StartListening(gMonitor ? FUNCTION_MONITOR : FUNCTION_RECEIVE, true);
else
SCANNER_NextMemChannel(); // switch to next channel
}
gScanPauseMode = false;
gRxReceptionMode = RX_MODE_NONE;
gScheduleScanListen = false;
}

View File

@ -58,6 +58,8 @@ extern bool bScanKeepFrequency;
void SCANNER_ProcessKeys(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld); void SCANNER_ProcessKeys(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld);
void SCANNER_Start(void); void SCANNER_Start(void);
void SCANNER_Stop(void); void SCANNER_Stop(void);
void SCANNER_NextChannel(const bool storeBackupSettings, const int8_t scan_direction);
void SCANNER_ContinueScanning();
#endif #endif

1
misc.c
View File

@ -205,7 +205,6 @@ uint16_t gLowBatteryCountdown;
uint8_t gNextMrChannel; uint8_t gNextMrChannel;
ReceptionMode_t gRxReceptionMode; ReceptionMode_t gRxReceptionMode;
uint8_t gRestoreMrChannel;
enum scan_next_chan_t gCurrentScanList; enum scan_next_chan_t gCurrentScanList;
uint32_t gRestoreFrequency; uint32_t gRestoreFrequency;

1
misc.h
View File

@ -277,7 +277,6 @@ extern uint16_t gLowBatteryCountdown;
extern uint8_t gNextMrChannel; extern uint8_t gNextMrChannel;
extern ReceptionMode_t gRxReceptionMode; extern ReceptionMode_t gRxReceptionMode;
extern uint8_t gRestoreMrChannel;
extern scan_next_chan_t gCurrentScanList; extern scan_next_chan_t gCurrentScanList;
extern uint32_t gRestoreFrequency; extern uint32_t gRestoreFrequency;