Fix #170: ChName saves a name with wrong settings when used in frequency mode

This commit is contained in:
Krzysiek Egzmont
2023-12-02 23:06:22 +01:00
parent cfa745fda0
commit d944ff4a34
4 changed files with 20 additions and 30 deletions

View File

@@ -501,12 +501,8 @@ void MENU_AcceptSetting(void)
break; break;
edit[i] = ' '; edit[i] = ' ';
} }
// save the channel name SETTINGS_SaveChannelName(gSubMenuSelection, edit);
memset(gTxVfo->Name, 0, sizeof(gTxVfo->Name));
memmove(gTxVfo->Name, edit, 10);
SETTINGS_SaveChannel(gSubMenuSelection, gEeprom.TX_VFO, gTxVfo, 3);
gFlagReconfigureVfos = true;
return; return;
case MENU_SAVE: case MENU_SAVE:

View File

@@ -379,11 +379,9 @@ void RADIO_ConfigureChannel(const unsigned int VFO, const unsigned int configure
RADIO_ApplyOffset(pVfo); RADIO_ApplyOffset(pVfo);
memset(pVfo->Name, 0, sizeof(pVfo->Name));
if (IS_MR_CHANNEL(channel)) if (IS_MR_CHANNEL(channel))
{ // 16 bytes allocated to the channel name but only 10 used, the rest are 0's { // 16 bytes allocated to the channel name but only 10 used, the rest are 0's
EEPROM_ReadBuffer(0x0F50 + (channel * 16), pVfo->Name + 0, 8); SETTINGS_FetchChannelName(pVfo->Name, channel);
EEPROM_ReadBuffer(0x0F58 + (channel * 16), pVfo->Name + 8, 2);
} }
if (!pVfo->FrequencyReverse) if (!pVfo->FrequencyReverse)

View File

@@ -598,8 +598,7 @@ void SETTINGS_SaveChannel(uint8_t Channel, uint8_t VFO, const VFO_Info_t *pVFO,
if (!IS_NOAA_CHANNEL(Channel)) if (!IS_NOAA_CHANNEL(Channel))
#endif #endif
{ {
const uint16_t OffsetMR = Channel * 16; uint16_t OffsetVFO = Channel * 16;
uint16_t OffsetVFO = OffsetMR;
if (!IS_MR_CHANNEL(Channel)) if (!IS_MR_CHANNEL(Channel))
{ // it's a VFO, not a channel { // it's a VFO, not a channel
@@ -636,24 +635,13 @@ void SETTINGS_SaveChannel(uint8_t Channel, uint8_t VFO, const VFO_Info_t *pVFO,
SETTINGS_UpdateChannel(Channel, pVFO, true); SETTINGS_UpdateChannel(Channel, pVFO, true);
if (IS_MR_CHANNEL(Channel)) if (IS_MR_CHANNEL(Channel)) {
{ // it's a memory channel
#ifndef ENABLE_KEEP_MEM_NAME #ifndef ENABLE_KEEP_MEM_NAME
// clear/reset the channel name // clear/reset the channel name
//memset(&State, 0xFF, sizeof(State)); SETTINGS_SaveChannelName(Channel, "");
memset(&State, 0x00, sizeof(State)); // follow the QS way
EEPROM_WriteBuffer(0x0F50 + OffsetMR, State);
EEPROM_WriteBuffer(0x0F58 + OffsetMR, State);
#else #else
if (Mode >= 3) if (Mode >= 3) {
{ // save the channel name SETTINGS_SaveChannelName(Channel, pVFO->Name);
memmove(State, pVFO->Name + 0, 8);
EEPROM_WriteBuffer(0x0F50 + OffsetMR, State);
//memset(State, 0xFF, sizeof(State));
memset(State, 0x00, sizeof(State)); // follow the QS way
memmove(State, pVFO->Name + 8, 2);
EEPROM_WriteBuffer(0x0F58 + OffsetMR, State);
} }
#endif #endif
} }
@@ -671,6 +659,16 @@ void SETTINGS_SaveBatteryCalibration(const uint16_t * batteryCalibration)
EEPROM_WriteBuffer(0x1F48, buf); EEPROM_WriteBuffer(0x1F48, buf);
} }
void SETTINGS_SaveChannelName(uint8_t channel, const char * name)
{
uint16_t offset = channel * 16;
uint8_t buf[16];
memset(&buf, 0x00, sizeof(buf));
memcpy(buf, name, MIN(strlen(name),10u));
EEPROM_WriteBuffer(0x0F50 + offset, buf);
EEPROM_WriteBuffer(0x0F58 + offset, buf + 8);
}
void SETTINGS_UpdateChannel(uint8_t channel, const VFO_Info_t *pVFO, bool keep) void SETTINGS_UpdateChannel(uint8_t channel, const VFO_Info_t *pVFO, bool keep)
{ {
#ifdef ENABLE_NOAA #ifdef ENABLE_NOAA
@@ -703,12 +701,9 @@ void SETTINGS_UpdateChannel(uint8_t channel, const VFO_Info_t *pVFO, bool keep)
gMR_ChannelAttributes[channel] = att; gMR_ChannelAttributes[channel] = att;
if (IS_MR_CHANNEL(channel)) { // it's a memory channel if (IS_MR_CHANNEL(channel)) { // it's a memory channel
const uint16_t OffsetMR = channel * 16;
if (!keep) { if (!keep) {
// clear/reset the channel name // clear/reset the channel name
memset(&state, 0x00, sizeof(state)); SETTINGS_SaveChannelName(channel, "");
EEPROM_WriteBuffer(0x0F50 + OffsetMR, state);
EEPROM_WriteBuffer(0x0F58 + OffsetMR, state);
} }
} }
} }

View File

@@ -263,6 +263,7 @@ void SETTINGS_FactoryReset(bool bIsAll);
#endif #endif
void SETTINGS_SaveVfoIndices(void); void SETTINGS_SaveVfoIndices(void);
void SETTINGS_SaveSettings(void); void SETTINGS_SaveSettings(void);
void SETTINGS_SaveChannelName(uint8_t channel, const char * name);
void SETTINGS_SaveChannel(uint8_t Channel, uint8_t VFO, const VFO_Info_t *pVFO, uint8_t Mode); void SETTINGS_SaveChannel(uint8_t Channel, uint8_t VFO, const VFO_Info_t *pVFO, uint8_t Mode);
void SETTINGS_SaveBatteryCalibration(const uint16_t * batteryCalibration); void SETTINGS_SaveBatteryCalibration(const uint16_t * batteryCalibration);
void SETTINGS_UpdateChannel(uint8_t channel, const VFO_Info_t *pVFO, bool keep); void SETTINGS_UpdateChannel(uint8_t channel, const VFO_Info_t *pVFO, bool keep);