diff --git a/TEF6686_ESP32.ino b/TEF6686_ESP32.ino index 6c54887..d80c218 100644 --- a/TEF6686_ESP32.ino +++ b/TEF6686_ESP32.ino @@ -4780,15 +4780,7 @@ void cancelDXScan() { if (XDRGTKUSB || XDRGTKTCP) DataPrint("J0\n"); } -void endMenu() { - radio.clearRDS(fullsearchrds); - menu = false; - menuopen = false; - LowLevelInit = true; - submenu = false; - menuoption = ITEM1; - menupage = INDEX; - menuitem = 0; +void saveData() { EEPROM.writeByte(EE_BYTE_VOLSET, VolSet); EEPROM.writeUInt(EE_UINT16_CONVERTERSET, ConverterSet); EEPROM.writeUInt(EE_UINT16_FMLOWEDGESET, LowEdgeSet); @@ -4877,6 +4869,18 @@ void endMenu() { EEPROM.writeByte(EE_BYTE_CLOCKAMPM, clockampm); EEPROM.writeUInt(EE_UINT16_PICTLOCK, radio.rds.PICTlock); EEPROM.commit(); +} + +void endMenu() { + radio.clearRDS(fullsearchrds); + menu = false; + menuopen = false; + LowLevelInit = true; + submenu = false; + menuoption = ITEM1; + menupage = INDEX; + menuitem = 0; + saveData(); if (af == 2) radio.rds.afreg = true; else radio.rds.afreg = false; Serial.end(); if (wifi) remoteip = IPAddress (WiFi.localIP()[0], WiFi.localIP()[1], WiFi.localIP()[2], subnetclient); diff --git a/src/TEF6686.cpp b/src/TEF6686.cpp index 95dea54..8be16b3 100644 --- a/src/TEF6686.cpp +++ b/src/TEF6686.cpp @@ -15,7 +15,6 @@ uint16_t TEF6686::getBlockA(void) { return blockA; } - void TEF6686::TestAFEON() { uint16_t status; uint16_t dummy1; @@ -158,18 +157,10 @@ void TEF6686::init(byte TEF) { } } -bool TEF6686::getIdentification(uint16_t &device, uint16_t &hw_version, uint16_t &sw_version) { +void TEF6686::getIdentification(uint16_t &device, uint16_t &hw_version, uint16_t &sw_version) { devTEF_Radio_Get_Identification(&device, &hw_version, &sw_version); - return device; - return hw_version; - return sw_version; } -void TEF6686::setCoax(uint8_t mode) { - devTEF_Radio_Set_GPIO(mode); -} - - void TEF6686::power(bool mode) { devTEF_APPL_Set_OperationMode(mode); if (mode == 0) devTEF_Set_Cmd(TEF_FM, Cmd_Tune_To, 7, 1, 10000); @@ -355,36 +346,13 @@ void TEF6686::setStHiBlendOffset(uint8_t start) { } } -bool TEF6686::getProcessing(uint16_t &highcut, uint16_t &stereo, uint16_t &sthiblend, uint8_t &stband_1, uint8_t &stband_2, uint8_t &stband_3, uint8_t &stband_4) { - devTEF_Radio_Get_Processing_Status(&highcut, &stereo, &sthiblend, &stband_1, &stband_2, &stband_3, &stband_4); - return highcut; - return stereo; - return sthiblend; - return stband_1; - return stband_2; - return stband_3; - return stband_4; -} - -bool TEF6686::getStatus(int16_t &level, uint16_t &USN, uint16_t &WAM, int16_t &offset, uint16_t &bandwidth, uint16_t &modulation, int8_t &snr) { +void TEF6686::getStatus(int16_t &level, uint16_t &USN, uint16_t &WAM, int16_t &offset, uint16_t &bandwidth, uint16_t &modulation, int8_t &snr) { uint16_t status; devTEF_Radio_Get_Quality_Status(&status, &level, &USN, &WAM, &offset, &bandwidth, &modulation, &snr); - return level; - return USN; - return WAM; - return bandwidth; - return modulation; - return snr; } -bool TEF6686::getStatusAM(int16_t &level, uint16_t &noise, uint16_t &cochannel, int16_t &offset, uint16_t &bandwidth, uint16_t &modulation, int8_t &snr) { +void TEF6686::getStatusAM(int16_t &level, uint16_t &noise, uint16_t &cochannel, int16_t &offset, uint16_t &bandwidth, uint16_t &modulation, int8_t &snr) { devTEF_Radio_Get_Quality_Status_AM(&level, &noise, &cochannel, &offset, &bandwidth, &modulation, &snr); - return level; - return noise; - return cochannel; - return bandwidth; - return modulation; - return snr; } void TEF6686::readRDS(byte showrdserrors) { @@ -439,9 +407,9 @@ void TEF6686::readRDS(byte showrdserrors) { rds.picode[3] = rds.rdsA & 0xF; for (int i = 0; i < 4; i++) { if (rds.picode[i] < 10) { - rds.picode[i] += '0'; // Add ASCII offset for decimal digits + rds.picode[i] += '0'; } else { - rds.picode[i] += 'A' - 10; // Add ASCII offset for hexadecimal letters A-F + rds.picode[i] += 'A' - 10; } } } @@ -454,7 +422,7 @@ void TEF6686::readRDS(byte showrdserrors) { if (!errorfreepi) { if (((rds.rdsErr >> 14) & 0x03) > 1) rds.picode[5] = '?'; else rds.picode[5] = ' '; - if (((rds.rdsErr >> 14) & 0x03) > 0) rds.picode[4] = '?'; else rds.picode[4] = ' '; // Not sure, add a ? + if (((rds.rdsErr >> 14) & 0x03) > 0) rds.picode[4] = '?'; else rds.picode[4] = ' '; } else { rds.picode[4] = ' '; rds.picode[5] = ' '; @@ -543,29 +511,20 @@ void TEF6686::readRDS(byte showrdserrors) { // Adjust stationID based on specific conditions if (stationID > 21671) { - if ((stationID & 0xF00U) == 0) { - stationID = ((uint16_t)(0xA0 + ((stationID & 0xF000U) >> 12)) << 8) + lowByte(stationID); // C0DE -> ACDE - } else if (lowByte(stationID) == 0) { - stationID = 0xAF00 + uint8_t(highByte(stationID)); // CD00 -> AFCD - } + if ((stationID & 0xF00U) == 0) stationID = ((uint16_t)(0xA0 + ((stationID & 0xF000U) >> 12)) << 8) + lowByte(stationID); // C0DE -> ACDE + else if (lowByte(stationID) == 0) stationID = 0xAF00 + uint8_t(highByte(stationID)); // CD00 -> AFCD } // Check if the station has a fixed callsign for Canada // Here we are skipping the `isFixed` and directly checking if the station is in Canada if (!(rds.region == 3 && stationID == 0xAF00)) { // Example condition for a fixed callsign (AF00 is just an example) // Determine prefix: 'W' or 'K' for USA, 'C' for Canada - if (rds.region == 1 || rds.region == 2) { - rds.stationID[0] = (stationID > 21671) ? 'W' : 'K'; - } else if (rds.region == 3) { - rds.stationID[0] = 'C'; // Canadian stations start with 'C' - } + if (rds.region == 1 || rds.region == 2) rds.stationID[0] = (stationID > 21671) ? 'W' : 'K'; + else if (rds.region == 3) rds.stationID[0] = 'C'; // Canadian stations start with 'C' // Adjust stationID based on the region and PI code - if (stationID < 39247) { - stationID -= (stationID > 21671) ? 21672 : 4096; - } else { - stationID -= 4835; - } + if (stationID < 39247) stationID -= (stationID > 21671) ? 21672 : 4096; + else stationID -= 4835; // Decode the last 3 letters of the callsign rds.stationID[1] = char(stationID / 676 + 'A'); // Using 'A' for readability @@ -585,11 +544,8 @@ void TEF6686::readRDS(byte showrdserrors) { } // If any character is faulty, mark it as "Unknown" - if (faultyID) { - strcpy(rds.stationID, "Unknown"); - } else { - rds.stationID[7] = '?'; // If not faulty, append '?' - } + if (faultyID) strcpy(rds.stationID, "Unknown"); + else rds.stationID[7] = '?'; // If not faulty, append '?' rds.stationID[8] = '\0'; // Null terminate the callsign } @@ -1842,7 +1798,7 @@ void TEF6686::clearRDS (bool fullsearchrds) { void TEF6686::tone(uint16_t time, int16_t amplitude, uint16_t frequency) { devTEF_Audio_Set_Mute(0); devTEF_Radio_Set_Wavegen(1, amplitude, frequency); - delay (time); + delay(time); devTEF_Radio_Set_Wavegen(0, 0, 0); } @@ -1884,28 +1840,19 @@ String TEF6686::extractUTF8Substring(const String & utf8String, size_t start, si uint8_t currentByte = utf8String.charAt(utf8Index); uint8_t numBytes = 0; - if (currentByte < 0x80) { - numBytes = 1; - } else if ((currentByte >> 5) == 0x6) { - numBytes = 2; - } else if ((currentByte >> 4) == 0xE) { - numBytes = 3; - } else if ((currentByte >> 3) == 0x1E) { - numBytes = 4; - } + if (currentByte < 0x80) numBytes = 1; + else if ((currentByte >> 5) == 0x6) numBytes = 2; + else if ((currentByte >> 4) == 0xE) numBytes = 3; + else if ((currentByte >> 3) == 0x1E) numBytes = 4; - if (charIndex >= start) { - substring += utf8String.substring(utf8Index, utf8Index + numBytes); - } + if (charIndex >= start) substring += utf8String.substring(utf8Index, utf8Index + numBytes); utf8Index += numBytes; charIndex++; } if (under) { - while (substring.length() < length) { - substring += '_'; - } + while (substring.length() < length) substring += '_'; } return substring; @@ -2068,16 +2015,13 @@ String TEF6686::ucs2ToUtf8(const char* ucs2Input) { String utf8Output; size_t length = 0; - while (ucs2Input[length] != '\0' || ucs2Input[length + 1] != '\0') { - length += 2; - } + while (ucs2Input[length] != '\0' || ucs2Input[length + 1] != '\0') length += 2; for (size_t i = 0; i < length; i += 2) { uint16_t ucs2Char = ((uint8_t)ucs2Input[i] << 8) | (uint8_t)ucs2Input[i + 1]; - if (ucs2Char <= 0x7F) { - utf8Output += (char)ucs2Char; - } else if (ucs2Char <= 0x7FF) { + if (ucs2Char <= 0x7F) utf8Output += (char)ucs2Char; + else if (ucs2Char <= 0x7FF) { utf8Output += (char)(0xC0 | (ucs2Char >> 6)); utf8Output += (char)(0x80 | (ucs2Char & 0x3F)); } else { diff --git a/src/TEF6686.h b/src/TEF6686.h index 46e790f..2bfa2b1 100644 --- a/src/TEF6686.h +++ b/src/TEF6686.h @@ -12,9 +12,6 @@ extern const unsigned char tuner_init_tab4000[] PROGMEM; extern const unsigned char tuner_init_tab12000[] PROGMEM; extern const unsigned char tuner_init_tab55000[] PROGMEM; -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wunused-variable" - enum RDS_GROUPS { RDS_GROUP_0A, RDS_GROUP_0B, RDS_GROUP_1A, RDS_GROUP_1B, RDS_GROUP_2A, RDS_GROUP_2B, RDS_GROUP_3A, RDS_GROUP_3B, RDS_GROUP_4A, RDS_GROUP_4B, RDS_GROUP_5A, RDS_GROUP_5B, RDS_GROUP_6A, RDS_GROUP_6B, RDS_GROUP_7A, RDS_GROUP_7B, @@ -547,16 +544,15 @@ class TEF6686 { void SetFreq(uint16_t frequency); void SetFreqAM(uint16_t frequency); void SetFreqAIR(uint16_t frequency); - bool getProcessing(uint16_t &highcut, uint16_t &stereo, uint16_t &sthiblend, uint8_t &stband_1, uint8_t &stband_2, uint8_t &stband_3, uint8_t &stband_4); - bool getStatus(int16_t &level, uint16_t &USN, uint16_t &WAM, int16_t &offset, uint16_t &bandwidth, uint16_t &modulation, int8_t &snr); - bool getStatusAM(int16_t &level, uint16_t &noise, uint16_t &cochannel, int16_t &offset, uint16_t &bandwidth, uint16_t &modulation, int8_t &snr); - bool getIdentification(uint16_t &device, uint16_t &hw_version, uint16_t &sw_version); + void getProcessing(uint16_t &highcut, uint16_t &stereo, uint16_t &sthiblend, uint8_t &stband_1, uint8_t &stband_2, uint8_t &stband_3, uint8_t &stband_4); + void getStatus(int16_t &level, uint16_t &USN, uint16_t &WAM, int16_t &offset, uint16_t &bandwidth, uint16_t &modulation, int8_t &snr); + void getStatusAM(int16_t &level, uint16_t &noise, uint16_t &cochannel, int16_t &offset, uint16_t &bandwidth, uint16_t &modulation, int8_t &snr); + void getIdentification(uint16_t &device, uint16_t &hw_version, uint16_t &sw_version); void I2Sin(bool mode); void setSoftmuteFM(uint8_t mode); void setSoftmuteAM(uint8_t mode); void setMono(bool mono); bool getStereoStatus(); - void setCoax(uint8_t mode); void init(byte TEF); void clearRDS(bool fullsearchrds); void power(bool mode); diff --git a/src/Tuner_Drv_Lithio.cpp b/src/Tuner_Drv_Lithio.cpp index 51ee593..ddd4999 100644 --- a/src/Tuner_Drv_Lithio.cpp +++ b/src/Tuner_Drv_Lithio.cpp @@ -35,11 +35,11 @@ bool devTEF_Get_Cmd(TEF_MODULE module, uint8_t cmd, uint8_t *receive, uint16_t l return Tuner_ReadBuffer(receive, len); } -void devTEF_Radio_Tune_To (uint16_t frequency) { +void devTEF_Radio_Tune_To(uint16_t frequency) { devTEF_Set_Cmd(TEF_FM, Cmd_Tune_To, 7, 4, frequency); } -void devTEF_Radio_Tune_AM (uint16_t frequency) { +void devTEF_Radio_Tune_AM(uint16_t frequency) { devTEF_Set_Cmd(TEF_AM, Cmd_Tune_To, 7, 1, frequency); } @@ -192,7 +192,7 @@ void devTEF_Radio_Set_Softmute_Max_AM(uint8_t mode) { devTEF_Set_Cmd(TEF_AM, Cmd_Set_Softmute_Max, 7, uint16_t(mode), uint16_t(250)); } -bool devTEF_APPL_Get_Operation_Status (uint8_t *bootstatus) { +bool devTEF_APPL_Get_Operation_Status(uint8_t *bootstatus) { uint8_t buf[2]; uint16_t r = devTEF_Get_Cmd(TEF_APPL, Cmd_Get_Operation_Status, buf, sizeof(buf)); *bootstatus = Convert8bto16b(buf); @@ -300,11 +300,8 @@ void devTEF_Radio_Set_Wavegen(bool mode, int16_t amplitude, uint16_t freq) { } void devTEF_Radio_Set_I2S_Input(bool mode) { - if (mode) { - devTEF_Set_Cmd(TEF_AUDIO, Cmd_Set_Input, 5, 32); - } else { - devTEF_Set_Cmd(TEF_AUDIO, Cmd_Set_Input, 5, 0); - } + if (mode) devTEF_Set_Cmd(TEF_AUDIO, Cmd_Set_Input, 5, 32); + else devTEF_Set_Cmd(TEF_AUDIO, Cmd_Set_Input, 5, 0); } void devTEF_Radio_Set_GPIO(uint8_t mode) { diff --git a/src/comms.cpp b/src/comms.cpp index 75cbb9b..bda10aa 100644 --- a/src/comms.cpp +++ b/src/comms.cpp @@ -9,7 +9,7 @@ void Communication() { if (wifi) { int packetSize = Udp.parsePacket(); if (packetSize > 0) { - char packetBuffer[packetSize + 1]; // +1 for null terminator + char packetBuffer[packetSize + 1]; // +1 for null getStatus Udp.read(packetBuffer, packetSize); packetBuffer[packetSize] = '\0'; // Ensure valid string Udp.endPacket(); @@ -864,7 +864,7 @@ void XDRGTKRoutine() { DataPrint("W" + String(bwtemp) + "\n"); break; } case 'Y': { - VolSet = atoi(buff + 1); + VolSet = atoi(buff + 1) * 0.1; if (VolSet == 0) { radio.setMute(); if (!screenmute) tft.drawBitmap(249, 4, Speaker, 28, 24, PrimaryColor); @@ -873,11 +873,10 @@ void XDRGTKRoutine() { } else { radio.setUnMute(); if (!screenmute) tft.drawBitmap(249, 4, Speaker, 28, 24, GreyoutColor); - radio.setVolume(VolSet * 0.12); + radio.setVolume(VolSet); XDRMute = false; } DataPrint("Y" + String(VolSet) + "\n"); - VolSet *= 0.12; break; } case 'x': { DataPrint("OK\n"); @@ -892,29 +891,15 @@ void XDRGTKRoutine() { XDRGTKUSB = false; store = true; XDRMute = false; - if (XDRGTKMuteScreen) MuteScreen(0); + saveData(); + radio.setUnMute(); + MuteScreen(0); break; } case 'Z': { - byte ANT; - ANT = atol(buff + 1); - switch (ANT) { - case 0: - if (BAND_FM || BAND_OIRT) radio.setCoax(2); else radio.setCoax(0); - break; - - case 1: - if (BAND_FM || BAND_OIRT) radio.setCoax(3); else radio.setCoax(1); - break; - - case 2: - // Antenna C - break; - - case 3: - // Antenna D - break; - } - DataPrint("Z" + String(ANT) + "\n"); + // TEF does not do multiple antennas, just do a screen on/off, also more than 4 so no accidental switch + byte data = atoi(buff + 1); + DataPrint("Z" + String(data) + "\n"); + MuteScreen((data > 4) ? true : false); break; } } @@ -942,7 +927,7 @@ void passwordcrypt() { char letter = randomValue + 'a'; if (randomValue > 26) letter = (randomValue - 26); saltkey.setCharAt(generated, letter); - generated ++; + generated++; } salt = saltkey + XDRGTK_key; cryptedpassword = String(sha1(salt)); @@ -963,7 +948,7 @@ void tryWiFi() { webserver.on("/logo.png", handleLogo); webserver.begin(); NTPupdate(); - remoteip = IPAddress (WiFi.localIP()[0], WiFi.localIP()[1], WiFi.localIP()[2], subnetclient); + remoteip = IPAddress(WiFi.localIP()[0], WiFi.localIP()[1], WiFi.localIP()[2], subnetclient); if (!setupmode) tftPrint(ACENTER, textUI(57), 155, 128, InsignificantColor, InsignificantColorSmooth, 28); } else { if (!setupmode) tftPrint(ACENTER, textUI(56), 155, 128, SignificantColor, SignificantColorSmooth, 28); diff --git a/src/comms.h b/src/comms.h index 42947db..78eee57 100644 --- a/src/comms.h +++ b/src/comms.h @@ -162,4 +162,5 @@ extern void TuneUp(); extern void TuneDown(); extern void ShowTuneMode(); extern const char* textUI(uint16_t number); +extern void saveData(); #endif \ No newline at end of file