From 7a12c1ffa4556c59a81473076594a9cc8daf5b33 Mon Sep 17 00:00:00 2001 From: Sjef Verhoeven PE5PVB Date: Sat, 6 Apr 2024 15:03:20 +0200 Subject: [PATCH] Moved memory channels to struct --- TEF6686_ESP32.ino | 57 ++++++++++++++++++++++++----------------------- src/comms.cpp | 18 ++++++++------- src/comms.h | 4 ---- src/constants.h | 10 +++++++++ 4 files changed, 49 insertions(+), 40 deletions(-) diff --git a/TEF6686_ESP32.ino b/TEF6686_ESP32.ino index ca39288..a19acac 100644 --- a/TEF6686_ESP32.ino +++ b/TEF6686_ESP32.ino @@ -76,7 +76,7 @@ bool haseonold; bool hasrtplusold; bool hastmcold; bool LowLevelInit; -bool memoryms[EE_PRESETS_CNT]; +//bool memoryms[EE_PRESETS_CNT]; bool memorystore; bool menu; bool menuopen; @@ -161,8 +161,8 @@ byte iMSEQ; byte iMSset; byte language; byte licold; -byte memoryband[EE_PRESETS_CNT]; -byte memorybw[EE_PRESETS_CNT]; +//byte memoryband[EE_PRESETS_CNT]; +//byte memorybw[EE_PRESETS_CNT]; byte memorypos; byte memoryposold; byte memoryposstatus; @@ -338,7 +338,7 @@ unsigned int LWLowEdgeSet; unsigned int mappedfreqold[20]; unsigned int mappedfreqold2[20]; unsigned int mappedfreqold3[20]; -unsigned int memory[EE_PRESETS_CNT]; +//unsigned int memory[EE_PRESETS_CNT]; unsigned int MWHighEdgeSet; unsigned int MWLowEdgeSet; unsigned int scanner_end; @@ -362,6 +362,7 @@ unsigned long tottimer; unsigned long tuningtimer; unsigned long udptimer; +mem presets[EE_PRESETS_CNT]; TEF6686 radio; ESP32Time rtc(0); @@ -491,10 +492,10 @@ void setup() { LowEdgeOIRTSet = LowEdgeOIRTSet; HighEdgeOIRTSet = FREQ_FM_OIRT_END; - for (int i = 0; i < EE_PRESETS_CNT; i++) memoryband[i] = EEPROM.readByte(i + EE_PRESETS_BAND_START); - for (int i = 0; i < EE_PRESETS_CNT; i++) memory[i] = EEPROM.readUInt((i * 4) + EE_PRESETS_START); - for (int i = 0; i < EE_PRESETS_CNT; i++) memorybw[i] = EEPROM.readByte(i + EE_PRESET_BW_START); - for (int i = 0; i < EE_PRESETS_CNT; i++) memoryms[i] = EEPROM.readByte(i + EE_PRESET_MS_START); + for (int i = 0; i < EE_PRESETS_CNT; i++) presets[i].memoryband = EEPROM.readByte(i + EE_PRESETS_BAND_START); + for (int i = 0; i < EE_PRESETS_CNT; i++) presets[i].frequency = EEPROM.readUInt((i * 4) + EE_PRESETS_START); + for (int i = 0; i < EE_PRESETS_CNT; i++) presets[i].memorybw = EEPROM.readByte(i + EE_PRESET_BW_START); + for (int i = 0; i < EE_PRESETS_CNT; i++) presets[i].memoryms = EEPROM.readByte(i + EE_PRESET_MS_START); btStop(); @@ -1344,7 +1345,7 @@ void BANDBUTTONPress() { if (memorystore) { EEPROM.writeUInt((memorypos * 4) + EE_PRESETS_START, EE_PRESETS_FREQUENCY); EEPROM.commit(); - memory[memorypos] = EE_PRESETS_FREQUENCY; + presets[memorypos].frequency = EE_PRESETS_FREQUENCY; memorystore = false; ShowTuneMode(); if (memoryposstatus == MEM_DARK || memoryposstatus == MEM_EXIST) { @@ -2231,19 +2232,19 @@ void ButtonPress() { EEPROM.writeUInt((memorypos * 4) + EE_PRESETS_START, frequency_SW); } EEPROM.commit(); - memoryband[memorypos] = band; - memorybw[memorypos] = BWset; - memoryms[memorypos] = StereoToggle; + presets[memorypos].memoryband = band; + presets[memorypos].memorybw = BWset; + presets[memorypos].memoryms = StereoToggle; if (band == BAND_FM) { - memory[memorypos] = frequency; + presets[memorypos].frequency = frequency; } else if (band == BAND_OIRT) { - memory[memorypos] = frequency_OIRT; + presets[memorypos].frequency = frequency_OIRT; } else if (band == BAND_LW) { - memory[memorypos] = frequency_LW; + presets[memorypos].frequency = frequency_LW; } else if (band == BAND_MW) { - memory[memorypos] = frequency_MW; + presets[memorypos].frequency = frequency_MW; } else { - memory[memorypos] = frequency_SW; + presets[memorypos].frequency = frequency_SW; } ShowTuneMode(); if (memoryposstatus == MEM_DARK || memoryposstatus == MEM_EXIST) { @@ -2466,7 +2467,7 @@ void KeyDown() { } bool IsStationEmpty() { - if (memoryband[memorypos] == BAND_FM && memory[memorypos] == EE_PRESETS_FREQUENCY) { + if (presets[memorypos].memoryband == BAND_FM && presets[memorypos].frequency == EE_PRESETS_FREQUENCY) { return true; } return false; @@ -2516,33 +2517,33 @@ void DoMemoryPosTune() { memoryposstatus = MEM_NORMAL; } - if (band != memoryband[memorypos]) { - band = memoryband[memorypos]; + if (band != presets[memorypos].memoryband) { + band = presets[memorypos].memoryband; SelectBand(); } else { - band = memoryband[memorypos]; + band = presets[memorypos].memoryband; } if (band == BAND_FM) { - frequency = memory[memorypos]; + frequency = presets[memorypos].frequency; radio.SetFreq(frequency); } else if (band == BAND_OIRT) { - frequency_OIRT = memory[memorypos]; + frequency_OIRT = presets[memorypos].frequency; radio.SetFreq(frequency_OIRT); } else if (band == BAND_LW) { - frequency_LW = memory[memorypos]; + frequency_LW = presets[memorypos].frequency; radio.SetFreqAM(frequency_LW); } else if (band == BAND_MW) { - frequency_MW = memory[memorypos]; + frequency_MW = presets[memorypos].frequency; radio.SetFreqAM(frequency_MW); } else if (band == BAND_SW) { - frequency_SW = memory[memorypos]; + frequency_SW = presets[memorypos].frequency; radio.SetFreqAM(frequency_SW); } ShowFreq(0); if (band == BAND_FM || band == BAND_OIRT) { - StereoToggle = memoryms[memorypos]; + StereoToggle = presets[memorypos].memoryms; if (!StereoToggle) { Stereostatusold = false; if (CurrentSkin == 1 && !advancedRDS && !afscreen) { @@ -2570,7 +2571,7 @@ void DoMemoryPosTune() { } } - BWset = memorybw[memorypos]; + BWset = presets[memorypos].memorybw; doBW(); BWtune = true; diff --git a/src/comms.cpp b/src/comms.cpp index 6651133..afd57b2 100644 --- a/src/comms.cpp +++ b/src/comms.cpp @@ -3,6 +3,8 @@ #include "constants.h" #include +extern mem presets[]; + void Communication() { if (!menu) { if (wifi) { @@ -173,12 +175,12 @@ void Communication() { for (byte x = 0; x < EE_PRESETS_CNT; x++) { Serial.print(x + 1); Serial.print(","); - Serial.print(memory[x]); - if (memoryband[x] == BAND_FM || memoryband[x] == BAND_OIRT) Serial.print("0"); + Serial.print(presets[x].frequency); + if (presets[x].memoryband == BAND_FM || presets[x].memoryband == BAND_OIRT) Serial.print("0"); Serial.print(","); - Serial.print(memorybw[x]); + Serial.print(presets[x].memorybw); Serial.print(","); - Serial.print(memoryms[x]); + Serial.print(presets[x].memoryms); Serial.print("\n"); } } else if (data_str.startsWith("S")) { @@ -241,10 +243,10 @@ void Communication() { if (error == 0) { error |= (1 << 7); memorypos = mempos; - memoryband[mempos] = memband; - memory[mempos] = memfreq; - memorybw[mempos] = membw; - memoryms[mempos] = memms; + presets[mempos].memoryband = memband; + presets[mempos].frequency = memfreq; + presets[mempos].memorybw = membw; + presets[mempos].memoryms = memms; EEPROM.writeByte(mempos + EE_PRESETS_BAND_START, memband); EEPROM.writeByte(mempos + EE_PRESET_BW_START, membw); diff --git a/src/comms.h b/src/comms.h index 9fb22dc..68cffef 100644 --- a/src/comms.h +++ b/src/comms.h @@ -17,7 +17,6 @@ extern bool BWreset; extern bool direction; extern bool externaltune; extern bool fullsearchrds; -extern bool memoryms[]; extern bool menu; extern bool RDSSPYTCP; extern bool RDSSPYUSB; @@ -44,8 +43,6 @@ extern byte EQset; extern byte iMSEQ; extern byte iMSset; extern byte language; -extern byte memoryband[]; -extern byte memorybw[]; extern byte memorypos; extern byte subnetclient; extern char buff[16]; @@ -99,7 +96,6 @@ extern unsigned int frequency_SW; extern unsigned int frequencyold; extern unsigned int LWHighEdgeSet; extern unsigned int LWLowEdgeSet; -extern unsigned int memory[]; extern unsigned int MWHighEdgeSet; extern unsigned int MWLowEdgeSet; extern unsigned int scanner_end; diff --git a/src/constants.h b/src/constants.h index 0e820b8..190ab28 100644 --- a/src/constants.h +++ b/src/constants.h @@ -295,6 +295,16 @@ static const char* const FreqFont[] = {"Classic", "Roubenstil", "Motoya", "Aura2 static const char* const Theme[] = {"Essence", "Cyan", "Crimson", "Monochrome", "Volcano", "Dendro", "Sakura", "Whiteout", "Tangerine", "Ocean", "Indigo", "Maroon", "GoldBrite"}; static const char* const Skin[] = {"Essential", "NightSky"}; +// Memory channel database +typedef struct { + byte memorybw; + byte memoryband; + bool memoryms; + unsigned int frequency; + char RDSPI[5]; + char RDSPS[9]; +} mem; + // FM band: before BAND_GAP; AM band: after BAND_GAP enum RADIO_BAND { BAND_OIRT = 0, BAND_FM, BAND_GAP, BAND_LW, BAND_MW, BAND_SW