Skip to content

Commit

Permalink
Fix #170: ChName saves a name with wrong settings when used in freque…
Browse files Browse the repository at this point in the history
…ncy mode
  • Loading branch information
egzumer committed Dec 2, 2023
1 parent cfa745f commit d944ff4
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 30 deletions.
8 changes: 2 additions & 6 deletions app/menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -501,12 +501,8 @@ void MENU_AcceptSetting(void)
break;
edit[i] = ' ';
}

// save the channel name
memset(gTxVfo->Name, 0, sizeof(gTxVfo->Name));
memmove(gTxVfo->Name, edit, 10);
SETTINGS_SaveChannel(gSubMenuSelection, gEeprom.TX_VFO, gTxVfo, 3);
gFlagReconfigureVfos = true;

SETTINGS_SaveChannelName(gSubMenuSelection, edit);
return;

case MENU_SAVE:
Expand Down
4 changes: 1 addition & 3 deletions radio.c
Original file line number Diff line number Diff line change
Expand Up @@ -379,11 +379,9 @@ void RADIO_ConfigureChannel(const unsigned int VFO, const unsigned int configure

RADIO_ApplyOffset(pVfo);

memset(pVfo->Name, 0, sizeof(pVfo->Name));
if (IS_MR_CHANNEL(channel))
{ // 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);
EEPROM_ReadBuffer(0x0F58 + (channel * 16), pVfo->Name + 8, 2);
SETTINGS_FetchChannelName(pVfo->Name, channel);
}

if (!pVfo->FrequencyReverse)
Expand Down
37 changes: 16 additions & 21 deletions settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -598,8 +598,7 @@ void SETTINGS_SaveChannel(uint8_t Channel, uint8_t VFO, const VFO_Info_t *pVFO,
if (!IS_NOAA_CHANNEL(Channel))
#endif
{
const uint16_t OffsetMR = Channel * 16;
uint16_t OffsetVFO = OffsetMR;
uint16_t OffsetVFO = Channel * 16;

if (!IS_MR_CHANNEL(Channel))
{ // it's a VFO, not a channel
Expand Down Expand Up @@ -636,24 +635,13 @@ void SETTINGS_SaveChannel(uint8_t Channel, uint8_t VFO, const VFO_Info_t *pVFO,

SETTINGS_UpdateChannel(Channel, pVFO, true);

if (IS_MR_CHANNEL(Channel))
{ // it's a memory channel

if (IS_MR_CHANNEL(Channel)) {
#ifndef ENABLE_KEEP_MEM_NAME
// clear/reset the channel name
//memset(&State, 0xFF, sizeof(State));
memset(&State, 0x00, sizeof(State)); // follow the QS way
EEPROM_WriteBuffer(0x0F50 + OffsetMR, State);
EEPROM_WriteBuffer(0x0F58 + OffsetMR, State);
SETTINGS_SaveChannelName(Channel, "");
#else
if (Mode >= 3)
{ // save the channel 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);
if (Mode >= 3) {
SETTINGS_SaveChannelName(Channel, pVFO->Name);
}
#endif
}
Expand All @@ -671,6 +659,16 @@ void SETTINGS_SaveBatteryCalibration(const uint16_t * batteryCalibration)
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)
{
#ifdef ENABLE_NOAA
Expand Down Expand Up @@ -703,12 +701,9 @@ void SETTINGS_UpdateChannel(uint8_t channel, const VFO_Info_t *pVFO, bool keep)
gMR_ChannelAttributes[channel] = att;

if (IS_MR_CHANNEL(channel)) { // it's a memory channel
const uint16_t OffsetMR = channel * 16;
if (!keep) {
// clear/reset the channel name
memset(&state, 0x00, sizeof(state));
EEPROM_WriteBuffer(0x0F50 + OffsetMR, state);
EEPROM_WriteBuffer(0x0F58 + OffsetMR, state);
SETTINGS_SaveChannelName(channel, "");
}
}
}
Expand Down
1 change: 1 addition & 0 deletions settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ void SETTINGS_FactoryReset(bool bIsAll);
#endif
void SETTINGS_SaveVfoIndices(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_SaveBatteryCalibration(const uint16_t * batteryCalibration);
void SETTINGS_UpdateChannel(uint8_t channel, const VFO_Info_t *pVFO, bool keep);
Expand Down

0 comments on commit d944ff4

Please sign in to comment.