From 2a3e8d71974ca8cd64a1f5750b18afa920183715 Mon Sep 17 00:00:00 2001 From: Sjef Verhoeven PE5PVB Date: Mon, 12 Feb 2024 23:17:46 +0100 Subject: [PATCH] Added coaxswitch via GPIO0 (XDRGTK) Optimised XDRGTK parsing Fix problem where PS/PTY/PI sometimes turned blue on correct RDS when switching from Adv. RDS to normal screen --- TEF6686_ESP32.ino | 1 - src/TEF6686.cpp | 5 +++++ src/TEF6686.h | 1 + src/Tuner_Drv_Lithio.cpp | 8 ++++++++ src/Tuner_Drv_Lithio.h | 3 ++- src/comms.cpp | 32 +++++++++++++++----------------- src/rds.cpp | 4 +++- 7 files changed, 34 insertions(+), 20 deletions(-) diff --git a/TEF6686_ESP32.ino b/TEF6686_ESP32.ino index be2aeb6..64dd5fe 100644 --- a/TEF6686_ESP32.ino +++ b/TEF6686_ESP32.ino @@ -2531,7 +2531,6 @@ void ShowFreq(int mode) { attachInterrupt(digitalPinToInterrupt(ROTARY_PIN_B), read_encoder, CHANGE); rdsreset = true; - RDSstatus = false; licold = 254; ECCold = 253; afmethodBold = false; diff --git a/src/TEF6686.cpp b/src/TEF6686.cpp index 36aecd6..b94714a 100644 --- a/src/TEF6686.cpp +++ b/src/TEF6686.cpp @@ -158,6 +158,11 @@ bool TEF6686::getIdentification(uint16_t &device, uint16_t &hw_version, uint16_t 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); diff --git a/src/TEF6686.h b/src/TEF6686.h index e6fa021..c1f5142 100644 --- a/src/TEF6686.h +++ b/src/TEF6686.h @@ -670,6 +670,7 @@ class TEF6686 { 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 ace82cf..ef3175b 100644 --- a/src/Tuner_Drv_Lithio.cpp +++ b/src/Tuner_Drv_Lithio.cpp @@ -297,4 +297,12 @@ bool devTEF_Radio_Set_I2S_Input(bool mode) { } else { return devTEF_Set_Cmd(TEF_AUDIO, Cmd_Set_Input, 5, 0); } +} + +bool devTEF_Radio_Set_GPIO(uint8_t mode) { + if (mode == 0) return devTEF_Set_Cmd(TEF_APPL, Cmd_Set_GPIO, 9, 0, 33, 2); + if (mode == 1) return devTEF_Set_Cmd(TEF_APPL, Cmd_Set_GPIO, 9, 0, 33, 3); + if (mode == 2) return devTEF_Set_Cmd(TEF_APPL, Cmd_Set_GPIO, 9, 0, 32, 2); + if (mode == 3) return devTEF_Set_Cmd(TEF_APPL, Cmd_Set_GPIO, 9, 0, 32, 3); + } \ No newline at end of file diff --git a/src/Tuner_Drv_Lithio.h b/src/Tuner_Drv_Lithio.h index 56dd4c3..7c964db 100644 --- a/src/Tuner_Drv_Lithio.h +++ b/src/Tuner_Drv_Lithio.h @@ -56,6 +56,7 @@ typedef enum { typedef enum { Cmd_Set_OperationMode = 1, + Cmd_Set_GPIO = 3, Cmd_Get_Operation_Status = 128, Cmd_Get_Identification = 130 } TEF_APPL_COMMAND; @@ -108,5 +109,5 @@ bool devTEF_Radio_Set_StHiBlend_Mph(uint8_t mode, uint16_t start, uint16_t slope bool devTEF_Radio_Set_NoisBlanker(uint8_t mode, uint16_t start); bool devTEF_Radio_Set_Wavegen(bool mode, int16_t amplitude, uint16_t freq); bool devTEF_Radio_Set_I2S_Input(bool mode); - +bool devTEF_Radio_Set_GPIO(uint8_t mode); #endif \ No newline at end of file diff --git a/src/comms.cpp b/src/comms.cpp index 5e25fdf..45ac02e 100644 --- a/src/comms.cpp +++ b/src/comms.cpp @@ -189,30 +189,29 @@ void Communication() { void XDRGTKRoutine() { if (XDRGTKUSB) { - if (Serial.available()) - { - buff[buff_pos] = Serial.read(); - if (buff[buff_pos] != '\n' && buff_pos != 16 - 1) - { - buff_pos++; + while (Serial.available() > 0) { + char c = Serial.read(); + if (buff_pos < 16 && c != '\n') { + buff[buff_pos++] = c; } else { - buff[buff_pos] = 0; + buff[buff_pos] = '\0'; buff_pos = 0; XDRGTKdata = true; + break; } } } - if (XDRGTKTCP) { - if (RemoteClient.available() > 0) { - buff[buff_pos] = RemoteClient.read(); - if (buff[buff_pos] != '\n' && buff_pos != 16 - 1) - { - buff_pos++; + if (XDRGTKTCP && RemoteClient.available() > 0) { + while (RemoteClient.available() > 0) { + char c = RemoteClient.read(); + if (buff_pos < 16 && c != '\n') { + buff[buff_pos++] = c; } else { - buff[buff_pos] = 0; + buff[buff_pos] = '\0'; buff_pos = 0; XDRGTKdata = true; + break; } } } @@ -393,7 +392,6 @@ void XDRGTKRoutine() { radio.SetFreq(frequency); } if (band == BAND_FM) DataPrint("T" + String((frequency + ConverterSet * 100) * 10) + "\n"); else DataPrint("T" + String(frequency_AM) + "\n"); - ShowFreq(0); radio.clearRDS(fullsearchrds); RDSstatus = false; @@ -528,11 +526,11 @@ void XDRGTKRoutine() { ANT = atol(buff + 1); switch (ANT) { case 0: - // Antenna A + if (BAND_FM || BAND_OIRT) radio.setCoax(2); else radio.setCoax(0); break; case 1: - // Antenna B + if (BAND_FM || BAND_OIRT) radio.setCoax(3); else radio.setCoax(1); break; case 2: diff --git a/src/rds.cpp b/src/rds.cpp index b8bfeca..c89f239 100644 --- a/src/rds.cpp +++ b/src/rds.cpp @@ -448,7 +448,7 @@ void readRds() { void ShowErrors() { uint8_t calc = 4; - if (RDSstatus) { + if (RDSstatus && !rdsreset) { if (!radio.rds.rdsAerror) calc--; if (!radio.rds.rdsBerror) calc--; if (!radio.rds.rdsCerror) calc--; @@ -457,6 +457,8 @@ void ShowErrors() { SAvg3 = (((SAvg3 * 9) + 5) / 10) + calc; calc = SAvg3 / 10; } + + rdsreset = false; if (calc != rdsqualityold || BWreset) { switch (calc) {