diff --git a/app/menu.c b/app/menu.c index a0f0dae40..8b05a9d40 100644 --- a/app/menu.c +++ b/app/menu.c @@ -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: diff --git a/radio.c b/radio.c index e269399bd..ac99e9d30 100644 --- a/radio.c +++ b/radio.c @@ -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) diff --git a/settings.c b/settings.c index 8c5651764..0e785adf5 100644 --- a/settings.c +++ b/settings.c @@ -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 @@ -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 } @@ -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 @@ -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, ""); } } } diff --git a/settings.h b/settings.h index b167cc403..20949f1f2 100644 --- a/settings.h +++ b/settings.h @@ -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);