From e055a5f020cf119fbb0cf5a87b1779705b1f702e Mon Sep 17 00:00:00 2001 From: Armel FAUVEAU Date: Mon, 1 Jul 2024 02:45:09 +0200 Subject: [PATCH] Work on this fucking priority feature --- app/chFrScanner.c | 29 +++++++++++++++++++------- app/menu.c | 16 +++++++-------- radio.c | 8 +++----- settings.c | 52 +++++++++++++++++++++++++++++++++++++++-------- settings.h | 6 +++--- ui/menu.c | 8 +++++++- 6 files changed, 86 insertions(+), 33 deletions(-) diff --git a/app/chFrScanner.c b/app/chFrScanner.c index c18168a..a2904a3 100644 --- a/app/chFrScanner.c +++ b/app/chFrScanner.c @@ -4,6 +4,7 @@ #include "functions.h" #include "misc.h" #include "settings.h" +//#include "debugging.h" int8_t gScanStateDir; bool gScanKeepResult; @@ -17,7 +18,6 @@ uint32_t gScanRangeStop; typedef enum { SCAN_NEXT_CHAN_SCANLIST1 = 0, SCAN_NEXT_CHAN_SCANLIST2, - SCAN_NEXT_CHAN_SCANLIST3, SCAN_NEXT_CHAN_DUAL_WATCH, SCAN_NEXT_CHAN_MR, SCAN_NEXT_NUM @@ -195,13 +195,14 @@ static void NextFreqChannel(void) static void NextMemChannel(void) { static unsigned int prev_mr_chan = 0; - const bool enabled = (gEeprom.SCAN_LIST_DEFAULT < 5) ? gEeprom.SCAN_LIST_ENABLED[gEeprom.SCAN_LIST_DEFAULT] : true; - const int chan1 = -1; - const int chan2 = -1; - const int chan3 = -1; + const bool enabled = (gEeprom.SCAN_LIST_DEFAULT > 0 && gEeprom.SCAN_LIST_DEFAULT < 4) ? gEeprom.SCAN_LIST_ENABLED[gEeprom.SCAN_LIST_DEFAULT - 1] : true; + const int chan1 = (gEeprom.SCAN_LIST_DEFAULT > 0 && gEeprom.SCAN_LIST_DEFAULT < 4) ? gEeprom.SCANLIST_PRIORITY_CH1[gEeprom.SCAN_LIST_DEFAULT - 1] : -1; + const int chan2 = (gEeprom.SCAN_LIST_DEFAULT > 0 && gEeprom.SCAN_LIST_DEFAULT < 4) ? gEeprom.SCANLIST_PRIORITY_CH2[gEeprom.SCAN_LIST_DEFAULT - 1] : -1; const unsigned int prev_chan = gNextMrChannel; unsigned int chan = 0; + //char str[64] = ""; + if (enabled) { switch (currentScanList) @@ -209,27 +210,37 @@ static void NextMemChannel(void) case SCAN_NEXT_CHAN_SCANLIST1: prev_mr_chan = gNextMrChannel; + //sprintf(str, "-> Chan1 %d\n", chan1 + 1); + //LogUart(str); + if (chan1 >= 0) { - if (RADIO_CheckValidChannel(chan1, false, 0)) + if (RADIO_CheckValidChannel(chan1, false, gEeprom.SCAN_LIST_DEFAULT)) { currentScanList = SCAN_NEXT_CHAN_SCANLIST1; gNextMrChannel = chan1; break; } } + [[fallthrough]]; case SCAN_NEXT_CHAN_SCANLIST2: + + //sprintf(str, "-> Chan2 %d\n", chan2 + 1); + //LogUart(str); + if (chan2 >= 0) { - if (RADIO_CheckValidChannel(chan2, false, 0)) + if (RADIO_CheckValidChannel(chan2, false, gEeprom.SCAN_LIST_DEFAULT)) { currentScanList = SCAN_NEXT_CHAN_SCANLIST2; gNextMrChannel = chan2; break; } } + [[fallthrough]]; + /* case SCAN_NEXT_CHAN_SCANLIST3: if (chan3 >= 0) { @@ -241,6 +252,7 @@ static void NextMemChannel(void) } } [[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 @@ -274,6 +286,9 @@ static void NextMemChannel(void) } gNextMrChannel = chan; + + //sprintf(str, "----> Chan %d\n", chan + 1); + //LogUart(str); } if (gNextMrChannel != prev_chan) diff --git a/app/menu.c b/app/menu.c index f3d44f5..8916f7d 100644 --- a/app/menu.c +++ b/app/menu.c @@ -1131,17 +1131,17 @@ void MENU_ShowCurrentSetting(void) break; case MENU_SLIST1: - gSubMenuSelection = RADIO_FindNextChannel(0, 1, true, 0); - break; - - case MENU_SLIST2: gSubMenuSelection = RADIO_FindNextChannel(0, 1, true, 1); break; - case MENU_SLIST3: + case MENU_SLIST2: gSubMenuSelection = RADIO_FindNextChannel(0, 1, true, 2); break; + case MENU_SLIST3: + gSubMenuSelection = RADIO_FindNextChannel(0, 1, true, 3); + break; + #ifdef ENABLE_ALARM case MENU_AL_MOD: gSubMenuSelection = gEeprom.ALARM_MODE; @@ -1823,14 +1823,14 @@ static void MENU_Key_UP_DOWN(bool bKeyPressed, bool bKeyHeld, int8_t Direction) case MENU_SLIST3: bCheckScanList = true; - VFO = 2; + VFO = 3; break; case MENU_SLIST2: bCheckScanList = true; - VFO = 1; + VFO = 2; break; case MENU_SLIST1: - VFO = 0; + VFO = 1; bCheckScanList = true; break; diff --git a/radio.c b/radio.c index f706a96..2b8315a 100644 --- a/radio.c +++ b/radio.c @@ -101,16 +101,14 @@ bool RADIO_CheckValidChannel(uint16_t channel, bool checkScanList, uint8_t scanL return false; } - return true; + //return true; - /* // I don't understand what this code is for... - const uint8_t PriorityCh1 = gEeprom.SCANLIST_PRIORITY_CH1[scanList]; - const uint8_t PriorityCh2 = gEeprom.SCANLIST_PRIORITY_CH2[scanList]; + const uint8_t PriorityCh1 = gEeprom.SCANLIST_PRIORITY_CH1[scanList - 1]; + const uint8_t PriorityCh2 = gEeprom.SCANLIST_PRIORITY_CH2[scanList - 1]; return PriorityCh1 != channel && PriorityCh2 != channel; - */ } uint8_t RADIO_FindNextChannel(uint8_t Channel, int8_t Direction, bool bCheckScanList, uint8_t VFO) diff --git a/settings.c b/settings.c index 1359ad2..689ca9e 100644 --- a/settings.c +++ b/settings.c @@ -226,13 +226,35 @@ void SETTINGS_InitEEPROM(void) // 0F18..0F1F EEPROM_ReadBuffer(0x0F18, Data, 8); gEeprom.SCAN_LIST_DEFAULT = (Data[0] < 5) ? Data[0] : 0; // we now have 'all' channel scan option - for (unsigned int i = 0; i < 2; i++) + + // Fake data + gEeprom.SCAN_LIST_ENABLED[0] = 0; + gEeprom.SCAN_LIST_ENABLED[1] = 0; + gEeprom.SCAN_LIST_ENABLED[2] = 0; + + gEeprom.SCANLIST_PRIORITY_CH1[0] = 0; + gEeprom.SCANLIST_PRIORITY_CH2[0] = 2; + + gEeprom.SCANLIST_PRIORITY_CH1[1] = 14; + gEeprom.SCANLIST_PRIORITY_CH2[1] = 15; + + gEeprom.SCANLIST_PRIORITY_CH1[2] = 40; + gEeprom.SCANLIST_PRIORITY_CH2[2] = 41; + + // Fix me probably after Chirp update... + /* + for (unsigned int i = 0; i < 3; i++) { - const unsigned int j = 1 + (i * 3); - gEeprom.SCAN_LIST_ENABLED[i] = (Data[j + 0] < 5) ? Data[j] : false; + gEeprom.SCAN_LIST_ENABLED[i] = (Data[1] >> i) & 1; + } + + for (unsigned int i = 0; i < 3; i++) + { + const unsigned int j = 1 + (i * 2); gEeprom.SCANLIST_PRIORITY_CH1[i] = Data[j + 1]; gEeprom.SCANLIST_PRIORITY_CH2[i] = Data[j + 2]; } + */ // 0F40..0F47 EEPROM_ReadBuffer(0x0F40, Data, 8); @@ -506,6 +528,8 @@ void SETTINGS_SaveVfoIndices(void) void SETTINGS_SaveSettings(void) { uint8_t State[8]; + uint8_t tmp = 0; + #ifdef ENABLE_PWRON_PASSWORD uint32_t Password[2]; #endif @@ -617,13 +641,23 @@ void SETTINGS_SaveSettings(void) EEPROM_WriteBuffer(0x0ED8, State); State[0] = gEeprom.SCAN_LIST_DEFAULT; - State[1] = gEeprom.SCAN_LIST_ENABLED[0]; + + tmp = 0; + + if (gEeprom.SCAN_LIST_ENABLED[0] == 1) + tmp = tmp | (1 << 0); + if (gEeprom.SCAN_LIST_ENABLED[1] == 1) + tmp = tmp | (1 << 1); + if (gEeprom.SCAN_LIST_ENABLED[2] == 1) + tmp = tmp | (1 << 2); + + State[1] = tmp; State[2] = gEeprom.SCANLIST_PRIORITY_CH1[0]; State[3] = gEeprom.SCANLIST_PRIORITY_CH2[0]; - State[4] = gEeprom.SCAN_LIST_ENABLED[1]; - State[5] = gEeprom.SCANLIST_PRIORITY_CH1[1]; - State[6] = gEeprom.SCANLIST_PRIORITY_CH2[1]; - State[7] = 0xFF; + State[4] = gEeprom.SCANLIST_PRIORITY_CH1[1]; + State[5] = gEeprom.SCANLIST_PRIORITY_CH2[1]; + State[6] = gEeprom.SCANLIST_PRIORITY_CH1[2]; + State[7] = gEeprom.SCANLIST_PRIORITY_CH2[2]; EEPROM_WriteBuffer(0x0F18, State); memset(State, 0xFF, sizeof(State)); @@ -660,7 +694,7 @@ void SETTINGS_SaveSettings(void) #ifdef ENABLE_FEAT_F4HWN memset(State, 0xFF, sizeof(State)); - int tmp = 0; + tmp = 0; if(gSetting_set_inv == 1) tmp = tmp | (1 << 0); diff --git a/settings.h b/settings.h index 86e248e..acb7fb9 100644 --- a/settings.h +++ b/settings.h @@ -192,9 +192,9 @@ typedef struct { uint8_t BACKLIGHT_TIME; uint8_t SCAN_RESUME_MODE; uint8_t SCAN_LIST_DEFAULT; - bool SCAN_LIST_ENABLED[2]; - uint8_t SCANLIST_PRIORITY_CH1[2]; - uint8_t SCANLIST_PRIORITY_CH2[2]; + bool SCAN_LIST_ENABLED[3]; + uint8_t SCANLIST_PRIORITY_CH1[3]; + uint8_t SCANLIST_PRIORITY_CH2[3]; uint8_t field29_0x26; uint8_t field30_0x27; diff --git a/ui/menu.c b/ui/menu.c index 5d607dd..532d223 100644 --- a/ui/menu.c +++ b/ui/menu.c @@ -1037,7 +1037,13 @@ void UI_DisplayMenu(void) if (UI_MENU_GetCurrentMenuId() == MENU_SLIST1 || UI_MENU_GetCurrentMenuId() == MENU_SLIST2 || UI_MENU_GetCurrentMenuId() == MENU_SLIST3) { - i = (UI_MENU_GetCurrentMenuId() == MENU_SLIST1) ? 0 : 1; + if(UI_MENU_GetCurrentMenuId() == MENU_SLIST1) + i = 0; + else if(UI_MENU_GetCurrentMenuId() == MENU_SLIST2) + i = 1; + else if(UI_MENU_GetCurrentMenuId() == MENU_SLIST3) + i = 2; + char *pPrintStr = String; if (gSubMenuSelection < 0) {