diff --git a/TEF6686_ESP32.ino b/TEF6686_ESP32.ino index 06a8789..d34839e 100644 --- a/TEF6686_ESP32.ino +++ b/TEF6686_ESP32.ino @@ -3218,14 +3218,14 @@ void ShowAdvancedRDS() { tft.drawString("AF", 42, 45, GFXFF); hasafold = radio.rds.hasAF; } - if (millis() - afticker >= 500) { + if (millis() - afticker >= 100) { //500 if (xPos2 == 6) { if (millis() - aftickerhold >= 2000) { - xPos2 -= charWidth; + xPos2 -= 1;//charWidth; aftickerhold = millis(); } } else { - xPos2 -= charWidth; + xPos2 -= 1;//charWidth; aftickerhold = millis(); } if (xPos2 < -tft.textWidth(afstring) + (charWidth * 14)) xPos2 = 6; @@ -3245,14 +3245,14 @@ void ShowAdvancedRDS() { tft.drawString("EON", 148, 45, GFXFF); haseonold = radio.rds.hasEON; } - if (millis() - eonticker >= 500) { + if (millis() - eonticker >= 100) { //500 if (xPos3 == 6) { if (millis() - eontickerhold >= 2000) { - xPos3 -= charWidth; + xPos3 -= 1;//charWidth; eontickerhold = millis(); } } else { - xPos3 -= charWidth; + xPos3 -= 1;//charWidth; eontickerhold = millis(); } if (xPos3 < -tft.textWidth(eonstring) + (charWidth * 14)) xPos3 = 6; @@ -3272,14 +3272,14 @@ void ShowAdvancedRDS() { tft.drawString("RT+", 116, 45, GFXFF); hasrtplusold = radio.rds.hasRDSplus; } - if (millis() - rtplusticker >= 350) { + if (millis() - rtplusticker >= 100) { //350 if (xPos3 == 6) { if (millis() - rtplustickerhold >= 2000) { - xPos4 -= charWidth; + xPos4 -= 1;//charWidth; rtplustickerhold = millis(); } } else { - xPos4 -= charWidth; + xPos4 -= 1;//charWidth; rtplustickerhold = millis(); } if (xPos4 < -tft.textWidth(rtplusstring) + (charWidth * 14)) xPos4 = 6; @@ -3565,14 +3565,14 @@ void showPS() { void showRadioText() { if (radio.rds.hasRT && RDSstatus) { - if (millis() - rtticker >= 350) { + if (millis() - rtticker >= 100) { // 350 if (xPos == 6) { if (millis() - rttickerhold >= 2000) { - xPos -= charWidth; + xPos -= 1;//= charWidth; rttickerhold = millis(); } } else { - xPos -= charWidth; + xPos -= 1;//= charWidth; rttickerhold = millis(); } @@ -3779,10 +3779,10 @@ void ShowAFEON() { } if (af_counterold != radio.af_counter) { - Serial.println(radio.af_counter); tft.fillRect(2, 53, 177, 165, BackgroundColor); for (byte i = 0; i < radio.af_counter; i++) { byte x = i - (afpagenr == 2 ? 33 : 0); + if (radio.af[i].checked) tft.setTextColor(TFT_GREEN); else if (!radio.af[i].afvalid) tft.setTextColor(TFT_RED); else tft.setTextColor(PrimaryColor); tft.drawRightString((radio.af[i].filler ? "(f) " : "") + String(radio.af[i].frequency / 100) + "." + String((radio.af[i].frequency % 100) / 10), 56 + (x > 10 ? 60 : 0) + (x > 21 ? 60 : 0), 48 + (15 * x) - (x > 10 ? 165 : 0) - (x > 21 ? 165 : 0), GFXFF); if (i == 32 + (afpagenr == 2 ? 33 : 0)) i = 254; } @@ -3834,6 +3834,14 @@ void ShowAFEON() { } void BuildAFScreen() { + if (!afscreen && RDSstatus) { + tft.drawRoundRect(20, 30, 274, 170, 5, ActiveColor); + tft.fillRoundRect(22, 32, 270, 166, 5, BackgroundColor); + tft.setFreeFont(FONT14); + tft.setTextColor(ActiveColor); + tft.drawCentreString(myLanguage[language][34], 155, 90, GFXFF); + radio.TestAFEON(); + } afscreen = true; advancedRDS = false; if (theme == 0) { @@ -4306,8 +4314,8 @@ void ShowFreq(int mode) { if (wifi) { Udp.beginPacket(remoteip, 9030); - Udp.print("from = TEF tuner; freq = "); - if (band != BAND_FM) Udp.print(String(frequency_AM) + "000; ClearRDS = 1"); else Udp.print(String(frequency) + "0000; ClearRDS = 1"); + Udp.print("from=TEF tuner;freq="); + if (band != BAND_FM) Udp.print(String(frequency_AM) + "000;ClearRDS=1"); else Udp.print(String(frequency) + "0000;ClearRDS=1"); Udp.endPacket(); } } @@ -4393,7 +4401,7 @@ void ShowSignalLevel() { } if (wifi) { Udp.beginPacket(remoteip, 9030); - Udp.print("from = TEF tuner; RcvLevel = "); + Udp.print("from=TEF tuner;RcvLevel="); Udp.print(SStatus / 10); Udp.endPacket(); } @@ -4550,7 +4558,7 @@ void ShowBW() { BWreset = false; if (wifi) { Udp.beginPacket(remoteip, 9030); - Udp.print("from = TEF tuner; Bandwidth = "); + Udp.print("from=TEF tuner;Bandwidth="); Udp.print(BW * 1000); Udp.endPacket(); } @@ -4767,6 +4775,7 @@ void updateEQ() { } void updateSWMIBand() { + tft.setFreeFont(FONT7); switch (SWMIBandPos) { case SW_MI_BAND_11M: case SW_MI_BAND_13M: @@ -5061,14 +5070,14 @@ void Communication() { Udp.read(packetBuffer, packetSize); Udp.endPacket(); String packet = String(packetBuffer); - if (packetBuffer == "from = StationList; freq = ?; bandwidth = ? ") { + if (packetBuffer == "from=StationList;freq=?;bandwidth=?") { ShowFreq(0); Udp.beginPacket(remoteip, 9030); - Udp.print("from = TEF tuner; Bandwidth = "); + Udp.print("from=TEF tuner;Bandwidth="); Udp.print(BW * 1000); Udp.endPacket(); } else { - int symPos = packet.indexOf("freq = "); + int symPos = packet.indexOf("freq="); String stlfreq = packet.substring(symPos + 5, packetSize); if ((stlfreq.toInt()) / 10000 > 6500 && (stlfreq.toInt()) / 10000 < 10800) { if (band != BAND_FM) { @@ -5128,9 +5137,9 @@ void Communication() { SelectBand(); } XDRGTKTCP = true; - RemoteClient.print("o1, 0\n"); + RemoteClient.print("o1,0\n"); store = true; - } else if (RDSSPYTCP == false && XDRGTKTCP == false && data_str.length() < 5 && data_str == ("*R ? F")) + } else if (RDSSPYTCP == false && XDRGTKTCP == false && data_str.length() < 5 && data_str == ("*D*R?F")) { RDSSPYTCP = true; } else if (RDSSPYTCP == true) { @@ -5157,7 +5166,7 @@ void Communication() { { String data_str = Serial.readStringUntil('\n'); int data = data_str.toInt(); - if (data_str.length() > 1 && data_str == ("*D * R ? F")) RDSSPYUSB = true; + if (data_str.length() > 1 && data_str == ("*D*R?F")) RDSSPYUSB = true; int symPos = data_str.indexOf("*F"); if (symPos >= 5) { String freq = data_str.substring(0, symPos); @@ -5664,8 +5673,8 @@ void TuneUp() { frequency_SW = frequency_AM; } radio.clearRDS(fullsearchrds); - if (RDSSPYUSB == true) Serial.print("G : \r\nRESET------ -\r\n\r\n"); - if (RDSSPYTCP == true) RemoteClient.print("G : \r\nRESET------ -\r\n\r\n"); + if (RDSSPYUSB == true) Serial.print("G:\r\nRESET-------\r\n\r\n"); + if (RDSSPYTCP == true) RemoteClient.print("G:\r\nRESET-------\r\n\r\n"); } void TuneDown() { @@ -5745,8 +5754,8 @@ void TuneDown() { frequency_SW = frequency_AM; } radio.clearRDS(fullsearchrds); - if (RDSSPYUSB == true) Serial.print("G : \r\nRESET------ -\r\n\r\n"); - if (RDSSPYTCP == true) RemoteClient.print("G : \r\nRESET------ -\r\n\r\n"); + if (RDSSPYUSB == true) Serial.print("G:\r\nRESET-------\r\n\r\n"); + if (RDSSPYTCP == true) RemoteClient.print("G:\r\nRESET-------\r\n\r\n"); } void EdgeBeeper() { @@ -5770,8 +5779,8 @@ void Seek(bool mode) { store = true; } else { seek = true; - if (RDSSPYUSB == true) Serial.print("G : \r\nRESET------ -\r\n\r\n"); - if (RDSSPYTCP == true) RemoteClient.print("G : \r\nRESET------ -\r\n\r\n"); + if (RDSSPYUSB == true) Serial.print("G:\r\nRESET-------\r\n\r\n"); + if (RDSSPYTCP == true) RemoteClient.print("G:\r\nRESET-------\r\n\r\n"); } } } diff --git a/src/TEF6686.cpp b/src/TEF6686.cpp index 50578aa..ac5941f 100644 --- a/src/TEF6686.cpp +++ b/src/TEF6686.cpp @@ -7,8 +7,50 @@ unsigned long rdstimer = 0; unsigned long bitStartTime = 0; bool lastBitState = false; -uint16_t TEF6686::TestAF() { +void TEF6686::TestAFEON() { + uint16_t status; + uint16_t rdsStat; + uint16_t dummy1; + uint16_t dummy2; + uint8_t dummy3; + int16_t aflevel; + uint16_t afusn; + uint16_t afwam; + int16_t afoffset; + byte timing; + if (af_counter != 0) { + devTEF_Audio_Set_Mute(1); + for (int x = 0; x < af_counter; x++) { + timing = 0; + devTEF_Set_Cmd(TEF_FM, Cmd_Tune_To, 7, 3, af[x].frequency); + while (timing == 0 && !bitRead(timing, 15)) { + devTEF_Radio_Get_Quality_Status(&status, &aflevel, &afusn, &afwam, &afoffset, &dummy1, &dummy2, &dummy3); + timing = lowByte(status); + } + if (afoffset > -125 || afoffset < 125) { + devTEF_Set_Cmd(TEF_FM, Cmd_Tune_To, 7, 4, af[x].frequency); + delay(200); + devTEF_Radio_Get_RDS_Status(&rdsStat, &rds.rdsA, &rds.rdsB, &rds.rdsC, &rds.rdsD, &rds.rdsErr); + if (rdsStat & (1 << 9)) { + if (rds.rdsA == rds.correctPI) { + af[x].checked = true; + af[x].afvalid = true; + } else { + af[x].checked = false; + af[x].afvalid = false; + } + } else { + af[x].checked = false; + } + } + } + } + devTEF_Set_Cmd(TEF_FM, Cmd_Tune_To, 7, 4, currentfreq); + if (!mute) devTEF_Audio_Set_Mute(0); +} + +uint16_t TEF6686::TestAF() { if (af_counter != 0) { uint16_t status; uint16_t rdsStat; @@ -56,17 +98,22 @@ uint16_t TEF6686::TestAF() { devTEF_Set_Cmd(TEF_FM, Cmd_Tune_To, 7, 4, af[highestIndex].frequency); delay(200); devTEF_Radio_Get_RDS_Status(&rdsStat, &rds.rdsA, &rds.rdsB, &rds.rdsC, &rds.rdsD, &rds.rdsErr); - if ((rdsStat & (1 << 9)) && rds.rdsA == rds.correctPI) { - currentfreq = af[highestIndex].frequency; - for (byte y = 0; y < 50; y++) { - af[y].frequency = 0; - af[y].score = -32767; - af[y].afvalid = true; - af[y].filler = false; - af_counter = 0; + if (rdsStat & (1 << 9)) { + if (rds.rdsA == rds.correctPI) { + currentfreq = af[highestIndex].frequency; + for (byte y = 0; y < 50; y++) { + af[y].frequency = 0; + af[y].score = -32767; + af[y].afvalid = true; + af[y].filler = false; + af[y].checked = false; + } + af_counter = 0; // Reset af_counter only once after the loop. + } else { + af[highestIndex].afvalid = false; + devTEF_Set_Cmd(TEF_FM, Cmd_Tune_To, 7, 4, currentfreq); } } else { - af[highestIndex].afvalid = false; devTEF_Set_Cmd(TEF_FM, Cmd_Tune_To, 7, 4, currentfreq); } } @@ -337,8 +384,8 @@ void TEF6686::readRDS(bool showrdserrors) if (rdsReady) { // We have all data to decode... let's go... //PI decoder - if (rds.correct) rds.correctPI = rds.rdsA; - + if (rds.correct) rds.correctPI = rds.rdsA; + if (rds.region != 1 && (!rds.rdsAerror || rds.pierrors)) { if (rds.rdsA != piold) { piold = rds.rdsA; @@ -509,12 +556,15 @@ void TEF6686::readRDS(bool showrdserrors) uint16_t temp = af[j].frequency; bool temp2 = af[j].filler; bool temp3 = af[j].afvalid; + bool temp4 = af[j].checked; af[j].frequency = af[j + 1].frequency; af[j].filler = af[j + 1].filler; af[j].afvalid = af[j + 1].afvalid; + af[j].checked = af[j + 1].checked; af[j + 1].frequency = temp; af[j + 1].filler = temp2; af[j + 1].afvalid = temp3; + af[j + 1].checked = temp4; } } } @@ -802,6 +852,7 @@ void TEF6686::clearRDS (bool fullsearchrds) af[i].score = -32767; af[i].filler = false; af[i].afvalid = true; + af[i].checked = false; } for (i = 0; i < 20; i++) { @@ -810,6 +861,7 @@ void TEF6686::clearRDS (bool fullsearchrds) eon[i].mappedfreq = 0; eon[i].mappedfreq2 = 0; eon[i].mappedfreq3 = 0; + eon[i].checked = false; for (int y = 0; y < 9; y++) { eon_buffer[i][y] = 0; eon_buffer2[i][y] = 0; diff --git a/src/TEF6686.h b/src/TEF6686.h index 2e2fb49..12843a6 100644 --- a/src/TEF6686.h +++ b/src/TEF6686.h @@ -147,6 +147,7 @@ typedef struct _af_ { int16_t score; bool filler; bool afvalid; + bool checked; } af_; typedef struct _eon_ { @@ -156,14 +157,16 @@ typedef struct _eon_ { uint16_t pi; char picode[6]; String ps; + bool eonvalid; + bool checked; } eon_; typedef struct _logbook_ { - char picode[6]; - uint16_t frequency; - int16_t SignalLevel; - String stationName; - String DateTime; + char picode[6]; + uint16_t frequency; + int16_t SignalLevel; + String stationName; + String DateTime; } logbook_; class TEF6686 { @@ -171,8 +174,9 @@ class TEF6686 { af_ af[50]; eon_ eon[20]; rds_ rds; - logbook_ logbook[22]; - uint16_t TestAF(); + logbook_ logbook[22]; + uint16_t TestAF(); + void TestAFEON(); void readRDS(bool showrdserrors); void SetFreq(uint16_t frequency); void SetFreqAM(uint16_t frequency); @@ -205,7 +209,7 @@ class TEF6686 { void setAMAttenuation(uint16_t start); void setMute(); void setOffset(int8_t offset); - void setAMOffset(int8_t offset); + void setAMOffset(int8_t offset); void setFMSI(uint8_t mode); void setFMSI_Time(uint16_t attack, uint16_t decay); void setFMSI_Gain(uint16_t band1, uint16_t band2, uint16_t band3, uint16_t band4); @@ -216,7 +220,7 @@ class TEF6686 { void tone(uint16_t time, int16_t amplitude, uint16_t frequency); uint8_t af_counter; uint8_t eon_counter; - uint8_t logbook_counter; + uint8_t logbook_counter; uint8_t rdsblock; uint8_t rtplusblock; bool mute; @@ -234,14 +238,14 @@ class TEF6686 { bool rt_process; char rt_buffer[65]; char rt_buffer2[65]; - char rt_buffer32[33]; + char rt_buffer32[33]; bool useRTPlus = true; bool ABold; char stationTextBuffer[65]; uint16_t rdsBprevious; uint16_t rdsCprevious; uint16_t rdsDprevious; - uint16_t piold; + uint16_t piold; bool rtABold; wchar_t PStext[9] = L""; wchar_t EONPStext[20][9];