From 08cce229686b2f6a4ab3c3ab956570892b755949 Mon Sep 17 00:00:00 2001 From: Armel FAUVEAU Date: Mon, 28 Oct 2024 02:03:52 +0100 Subject: [PATCH] Add RESTORE_SCAN feature --- Makefile | 4 ++++ app/action.c | 3 +++ app/chFrScanner.c | 5 +++++ app/main.c | 15 +++++++++++++++ main.c | 48 +++++++++++++++++++++++++++++++++++++++++++++++ settings.c | 29 +++++++++++++++++++++++++--- settings.h | 7 +++++++ 7 files changed, 108 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index f2455bc..54ef5ac 100644 --- a/Makefile +++ b/Makefile @@ -46,6 +46,7 @@ ENABLE_FEAT_F4HWN_SPECTRUM ?= 1 ENABLE_FEAT_F4HWN_RX_TX_TIMER ?= 1 ENABLE_FEAT_F4HWN_CHARGING_C ?= 1 ENABLE_FEAT_F4HWN_SLEEP ?= 1 +ENABLE_FEAT_F4HWN_RESTORE_SCAN ?= 1 ENABLE_FEAT_F4HWN_PMR ?= 0 ENABLE_FEAT_F4HWN_GMRS_FRS_MURS ?= 0 ENABLE_FEAT_F4HWN_CA ?= 1 @@ -422,6 +423,9 @@ endif ifeq ($(ENABLE_FEAT_F4HWN_SLEEP),1) CFLAGS += -DENABLE_FEAT_F4HWN_SLEEP endif +ifeq ($(ENABLE_FEAT_F4HWN_RESTORE_SCAN),1) + CFLAGS += -DENABLE_FEAT_F4HWN_RESTORE_SCAN +endif ifeq ($(ENABLE_FEAT_F4HWN_PMR),1) CFLAGS += -DENABLE_FEAT_F4HWN_PMR endif diff --git a/app/action.c b/app/action.c index 73a2f0b..4a30254 100644 --- a/app/action.c +++ b/app/action.c @@ -220,6 +220,9 @@ void ACTION_Scan(bool bRestart) // channel mode. Keep scanning but toggle between scan lists gEeprom.SCAN_LIST_DEFAULT = (gEeprom.SCAN_LIST_DEFAULT + 1) % 6; + #ifdef ENABLE_FEAT_F4HWN_RESTORE_SCAN + SETTINGS_WriteCurrentState(); + #endif // jump to the next channel CHFRSCANNER_Start(false, gScanStateDir); diff --git a/app/chFrScanner.c b/app/chFrScanner.c index b249dc6..f326c4d 100644 --- a/app/chFrScanner.c +++ b/app/chFrScanner.c @@ -196,6 +196,11 @@ void CHFRSCANNER_Stop(void) } } + #ifdef ENABLE_FEAT_F4HWN_RESTORE_SCAN + gEeprom.CURRENT_STATE = 0; + SETTINGS_WriteCurrentState(); + #endif + RADIO_SetupRegisters(true); gUpdateDisplay = true; } diff --git a/app/main.c b/app/main.c index 328cb06..9232c7f 100644 --- a/app/main.c +++ b/app/main.c @@ -407,6 +407,9 @@ static void MAIN_Key_DIGITS(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld) switch(Key) { case KEY_0...KEY_5: gEeprom.SCAN_LIST_DEFAULT = Key; + #ifdef ENABLE_FEAT_F4HWN_RESTORE_SCAN + SETTINGS_WriteCurrentState(); + #endif break; default: break; @@ -684,6 +687,17 @@ static void MAIN_Key_STAR(bool bKeyPressed, bool bKeyHeld) if (!bKeyPressed) // released return; + #ifdef ENABLE_FEAT_F4HWN_RESTORE_SCAN + if(gScanRangeStart == 0) // No ScanRange + { + gEeprom.CURRENT_STATE = 1; + } + else // ScanRange + { + gEeprom.CURRENT_STATE = 2; + } + SETTINGS_WriteCurrentState(); + #endif ACTION_Scan(false);// toggle scanning gBeepToPlay = BEEP_1KHZ_60MS_OPTIONAL; @@ -732,6 +746,7 @@ static void MAIN_Key_STAR(bool bKeyPressed, bool bKeyHeld) // scan the CTCSS/DCS code gBackup_CROSS_BAND_RX_TX = gEeprom.CROSS_BAND_RX_TX; gEeprom.CROSS_BAND_RX_TX = CROSS_BAND_OFF; + SCANNER_Start(true); gRequestDisplayScreen = DISPLAY_SCANNER; } diff --git a/main.c b/main.c index 3af6286..95d5e49 100644 --- a/main.c +++ b/main.c @@ -29,6 +29,16 @@ #include "settings.h" #include "version.h" +#ifdef ENABLE_FEAT_F4HWN + #ifdef ENABLE_FMRADIO + #include "app/fm.h" + #endif + #ifdef ENABLE_SPECTRUM + #include "app/spectrum.h" + #endif + #include "app/chFrScanner.h" +#endif + #include "app/app.h" #include "app/dtmf.h" #include "bsp/dp32g030/gpio.h" @@ -242,6 +252,44 @@ void Main(void) #endif } + #ifdef ENABLE_FEAT_F4HWN_RESTORE_SCAN + switch (gEeprom.CURRENT_STATE) { + case 1: + //gScanRangeStart = 0; + //ACTION_Scan(false); + gEeprom.SCAN_LIST_DEFAULT = gEeprom.CURRENT_LIST; + CHFRSCANNER_Start(true, SCAN_FWD); + break; + + case 2: + gScanRangeStart = gScanRangeStart ? 0 : gTxVfo->pRX->Frequency; + gScanRangeStop = gEeprom.VfoInfo[!gEeprom.TX_VFO].freq_config_RX.Frequency; + if(gScanRangeStart > gScanRangeStop) + { + SWAP(gScanRangeStart, gScanRangeStop); + } + //ACTION_Scan(false); + CHFRSCANNER_Start(true, SCAN_FWD); + break; + + #ifdef ENABLE_FMRADIO + case 3: + FM_Start(); // For compiler alignments and paddings... + break; + #endif + + #ifdef ENABLE_SPECTRUM + case 4: + APP_RunSpectrum(); // For compiler alignments and paddings... + break; + #endif + + default: + // No action for CURRENT_STATE == 0 or other unexpected values + break; + } + #endif + while (true) { APP_Update(); diff --git a/settings.c b/settings.c index 43a7cdf..42be85b 100644 --- a/settings.c +++ b/settings.c @@ -69,7 +69,14 @@ void SETTINGS_InitEEPROM(void) gEeprom.DUAL_WATCH = (Data[4] < 3) ? Data[4] : DUAL_WATCH_CHAN_A; gEeprom.BACKLIGHT_TIME = (Data[5] < 62) ? Data[5] : 12; gEeprom.TAIL_TONE_ELIMINATION = (Data[6] < 2) ? Data[6] : false; - gEeprom.VFO_OPEN = (Data[7] < 2) ? Data[7] : true; + + #ifdef ENABLE_FEAT_F4HWN_RESTORE_SCAN + gEeprom.VFO_OPEN = Data[7] & 0x01; + gEeprom.CURRENT_STATE = (Data[7] >> 1) & 0x07; + gEeprom.CURRENT_LIST = (Data[7] >> 4) & 0x07; + #else + gEeprom.VFO_OPEN = (Data[7] < 2) ? Data[7] : true; + #endif // 0E80..0E87 EEPROM_ReadBuffer(0x0E80, Data, 8); @@ -610,7 +617,12 @@ void SETTINGS_SaveSettings(void) #endif State[6] = gEeprom.TAIL_TONE_ELIMINATION; - State[7] = gEeprom.VFO_OPEN; + + #ifdef ENABLE_FEAT_F4HWN_RESTORE_SCAN + State[7] = (gEeprom.VFO_OPEN & 0x01) | ((gEeprom.CURRENT_STATE & 0x07) << 1) | ((gEeprom.SCAN_LIST_DEFAULT & 0x07) << 4); + #else + State[7] = gEeprom.VFO_OPEN; + #endif EEPROM_WriteBuffer(0x0E78, State); State[0] = gEeprom.BEEP_CONTROL; @@ -960,4 +972,15 @@ State[1] = 0 #endif ; EEPROM_WriteBuffer(0x1FF0, State); -} \ No newline at end of file +} + +#ifdef ENABLE_FEAT_F4HWN_RESTORE_SCAN + void SETTINGS_WriteCurrentState(void) + { + uint8_t State[8]; + EEPROM_ReadBuffer(0x0E78, State, sizeof(State)); + //State[3] = (gEeprom.CURRENT_STATE << 4) | (gEeprom.BATTERY_SAVE & 0x0F); + State[7] = (gEeprom.VFO_OPEN & 0x01) | ((gEeprom.CURRENT_STATE & 0x07) << 1) | ((gEeprom.SCAN_LIST_DEFAULT & 0x07) << 4); + EEPROM_WriteBuffer(0x0E78, State); + } +#endif diff --git a/settings.h b/settings.h index cd26363..b2a9897 100644 --- a/settings.h +++ b/settings.h @@ -204,6 +204,10 @@ typedef struct { bool SCAN_LIST_ENABLED[3]; uint8_t SCANLIST_PRIORITY_CH1[3]; uint8_t SCANLIST_PRIORITY_CH2[3]; +#ifdef ENABLE_FEAT_F4HWN_RESTORE_SCAN + uint8_t CURRENT_STATE; + uint8_t CURRENT_LIST; +#endif uint8_t field29_0x26; uint8_t field30_0x27; @@ -301,5 +305,8 @@ void SETTINGS_SaveChannel(uint8_t Channel, uint8_t VFO, const VFO_Info_t *pVFO, void SETTINGS_SaveBatteryCalibration(const uint16_t * batteryCalibration); void SETTINGS_UpdateChannel(uint8_t channel, const VFO_Info_t *pVFO, bool keep, bool check, bool save); void SETTINGS_WriteBuildOptions(void); +#ifdef ENABLE_FEAT_F4HWN_RESTORE_SCAN + void SETTINGS_WriteCurrentState(void); +#endif #endif