From 7a2687b0b21824513d7978d0ddec6960dcf82aad Mon Sep 17 00:00:00 2001 From: Armel FAUVEAU Date: Thu, 10 Sep 2026 22:12:50 +0200 Subject: [PATCH] Fix SetNav persistence in Fusion and Transfer --- App/settings.c | 40 +++++++++++++++++++--------------------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/App/settings.c b/App/settings.c index 56a051f0..4878c802 100644 --- a/App/settings.c +++ b/App/settings.c @@ -149,15 +149,11 @@ void SETTINGS_InitEEPROM(void) #ifdef ENABLE_NOAA gEeprom.NOAA_AUTO_SCAN = (Data[3] < 2) ? Data[3] : false; #endif + gEeprom.KEY_LOCK = (Data[4] & 0x01) != 0; + gEeprom.SET_NAV = (Data[4] & 0x40) != 0; #ifdef ENABLE_FEAT_F4HWN_RESCUE_OPS - gEeprom.KEY_LOCK = (Data[4] & 0x01) != 0; gEeprom.MENU_LOCK = (Data[4] & 0x02) != 0; gEeprom.SET_KEY = ((Data[4] >> 2) & 0x0F) > 4 ? 0 : (Data[4] >> 2) & 0x0F; - gEeprom.SET_NAV = (Data[4] & 0x40) != 0; - #else - // RescueOps fields can be present in a config bank shared with another - // preset. Read only KEY_LOCK here and leave the other bits untouched. - gEeprom.KEY_LOCK = (Data[4] & 0x01) != 0; #endif #ifdef ENABLE_VOX gEeprom.VOX_SWITCH = (Data[5] < 2) ? Data[5] : false; @@ -753,30 +749,31 @@ void SETTINGS_FactoryReset(bool bIsAll) PY25Q16_SectorErase(0x00A000); } - // Prevent reset to restart in RO mode... + // Reset navigation in every edition and lock controls in RescueOps editions. + uint8_t Data8[0x10]; + PY25Q16_ReadBuffer(0x00A000, Data8, sizeof(Data8)); + + // SET_NAV to false + Data8[4] &= (uint8_t)~0x40; // Clear bit 6 (SET_NAV) for UV-K1 by default + #ifdef ENABLE_FEAT_F4HWN_RESCUE_OPS - // Bloc 0x0E70..0x0E7F -> offset 0x00A000 - uint8_t Data8[0x10]; - PY25Q16_ReadBuffer(0x00A000, Data8, sizeof(Data8)); - // MENU_LOCK & KEY_LOCK to 0 - Data8[4] &= (uint8_t)~0x01; Data8[4] &= (uint8_t)~0x02; // SET_KEY to 0 Data8[4] &= (uint8_t)~0x3C; // Clear bits 2-5 (SET_KEY) - // SET_NAV to false - Data8[4] &= (uint8_t)~0x40; // Clear bit 6 (SET_NAV) for UV-K1 by default - #ifdef ENABLE_FEAT_F4HWN_RESET_VFO Data8[7] = (1 & 0x01); #endif + #endif - PY25Q16_WriteBuffer(0x00A000, Data8, sizeof(Data8), false); + PY25Q16_WriteBuffer(0x00A000, Data8, sizeof(Data8), false); - // cohérence RAM + // Keep RAM consistent with the persisted defaults. + gEeprom.SET_NAV = false; + #ifdef ENABLE_FEAT_F4HWN_RESCUE_OPS gEeprom.MENU_LOCK = 0; #endif @@ -901,11 +898,12 @@ void SETTINGS_SaveSettings(void) ((gEeprom.SET_KEY & 0x0F) << 2) | (gEeprom.SET_NAV ? 0x40 : 0); #else - // A non-RescueOps preset owns KEY_LOCK only. Preserve Set RescueOps, - // SetKEY, SetNav and reserved bits from a config created by another - // preset while updating bit 0. + // A non-RescueOps preset owns KEY_LOCK and SET_NAV. Preserve the + // RescueOps-only MENU_LOCK and SET_KEY fields plus the reserved bit. PY25Q16_ReadBuffer(0x00A004, &State[4], 1); - State[4] = (State[4] & 0xFEu) | (gEeprom.KEY_LOCK ? 0x01u : 0u); + State[4] = (State[4] & 0xBEu) | + (gEeprom.KEY_LOCK ? 0x01u : 0u) | + (gEeprom.SET_NAV ? 0x40u : 0u); #endif #ifdef ENABLE_VOX