diff --git a/README.md b/README.md index e311a59..2283438 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ The version in the repository is an ongoing development. It could and will contain bugs. To make sure you use the latest fully tested firmware, check the releases! # TEF6686_ESP32 -Advanced Tuner software for NXP TEF668x tuners with ESP32 board\ +Advanced Tuner software for NXP TEF668x tuners with ESP32 board More information: https://www.pe5pvb.nl/tef6686/ ## TFT_eSPI diff --git a/include/TEF6686.h b/include/TEF6686.h index 27e7a89..eca2731 100644 --- a/include/TEF6686.h +++ b/include/TEF6686.h @@ -461,7 +461,7 @@ typedef struct _rds_ { uint32_t dabaffreq; byte aid_counter; byte fastps; - Detector ECC; + Detector ECC{0}; bool rdsAerror; bool rdsBerror; bool rdsCerror; diff --git a/include/globals.h b/include/globals.h index 3507a94..83bb894 100644 --- a/include/globals.h +++ b/include/globals.h @@ -13,6 +13,7 @@ #include "WiFiConnect.h" #include "WiFiConnectParam.h" #include "ESP32Time.h" +#include "scrolling_text.h" #define ROTARY_PIN_A 34 #define ROTARY_PIN_B 36 @@ -245,9 +246,6 @@ extern int XDRBWset; extern int XDRBWsetold; extern int xPos; extern int xPos2; -extern int xPos3; -extern int xPos4; -extern int xPos5; extern int16_t OStatus; extern int16_t SAvg; extern int16_t SAvg2; @@ -396,4 +394,8 @@ extern WiFiConnect wc; extern WiFiServer Server; extern WiFiClient RemoteClient; extern WiFiUDP Udp; -extern WebServer webserver; \ No newline at end of file +extern WebServer webserver; + +extern ScrollingTextDisplay rtplusDisplay; +extern ScrollingTextDisplay eonDisplay; +extern ScrollingTextDisplay eccDisplay; \ No newline at end of file diff --git a/include/scrolling_text.h b/include/scrolling_text.h new file mode 100644 index 0000000..3520c24 --- /dev/null +++ b/include/scrolling_text.h @@ -0,0 +1,86 @@ +#pragma once + +#include +#include + +class ScrollingTextDisplay { +private: + TFT_eSprite* sprite; + int yPos; + int maxWidth; + uint16_t backgroundColor; + int xPos; + int textWidth; + unsigned long lastTick; + unsigned long holdTick; + bool isScrolling; + + static const unsigned long SCROLL_INTERVAL = 5; + static const unsigned long HOLD_DURATION = 2000; + +public: + ScrollingTextDisplay(TFT_eSprite* spr, int y, int maxW, uint16_t bgColor) + : sprite(spr), yPos(y), maxWidth(maxW), backgroundColor(bgColor), + xPos(0), textWidth(0), lastTick(0), holdTick(0), isScrolling(false) {} + + // Update the display with new text + void update(const String& text, int width, bool status, uint16_t activeColor, uint16_t activeSmooth, uint16_t dropoutColor, uint16_t dropoutSmooth) { + textWidth = width; + + if (textWidth < maxWidth) { + xPos = 0; + isScrolling = false; + drawText(text, status, activeColor, activeSmooth, dropoutColor, dropoutSmooth); + } else { + isScrolling = true; + if (millis() - lastTick >= SCROLL_INTERVAL) { + if (xPos < -textWidth) xPos = 0; + + if (xPos == 0) { + if (millis() - holdTick >= HOLD_DURATION) { + xPos--; + holdTick = millis(); + } + } else { + xPos--; + holdTick = millis(); + } + + drawScrollingText(text, status, activeColor, activeSmooth, dropoutColor, dropoutSmooth); + lastTick = millis(); + } + } + } + + void reset() { + xPos = 0; + holdTick = millis(); + lastTick = millis(); + } + + void setYPosition(int y) { + yPos = y; + } + + bool getIsScrolling() const { + return isScrolling; + } + +private: + void drawText(const String& text, bool status, uint16_t activeColor, uint16_t activeSmooth, uint16_t dropoutColor, uint16_t dropoutSmooth) { + sprite->fillSprite(backgroundColor); + if (status) sprite->setTextColor(activeColor, activeSmooth, false); + else sprite->setTextColor(dropoutColor, dropoutSmooth, false); + sprite->drawString(text, xPos, 2); + sprite->pushSprite(35, yPos); + } + + void drawScrollingText(const String& text, bool status, uint16_t activeColor, uint16_t activeSmooth, uint16_t dropoutColor, uint16_t dropoutSmooth) { + sprite->fillSprite(backgroundColor); + if (status) sprite->setTextColor(activeColor, activeSmooth, false); + else sprite->setTextColor(dropoutColor, dropoutSmooth, false); + sprite->drawString(text, xPos, 2); + sprite->drawString(text, xPos + textWidth, 2); + sprite->pushSprite(35, yPos); + } +}; \ No newline at end of file diff --git a/maxapp.csv b/maxapp.csv new file mode 100644 index 0000000..6bf9656 --- /dev/null +++ b/maxapp.csv @@ -0,0 +1,4 @@ +# Name, Type, SubType, Offset, Size, Flags +nvs, data, nvs, 0x9000, 0x5000, +factory, app, factory,, 0x30E000, +spiffs, data, spiffs,,0xE0000, \ No newline at end of file diff --git a/platformio.ini b/platformio.ini index 2d4aa78..a2cc547 100644 --- a/platformio.ini +++ b/platformio.ini @@ -13,7 +13,7 @@ platform = espressif32 upload_speed = 921600 board = esp32dev framework = arduino -board_build.partitions = huge_app.csv +board_build.partitions = maxapp.csv build_flags = -Wall -Wextra diff --git a/src/globals.cpp b/src/globals.cpp index f55670c..63b954d 100644 --- a/src/globals.cpp +++ b/src/globals.cpp @@ -226,9 +226,6 @@ int XDRBWset; int XDRBWsetold; int xPos; int xPos2; -int xPos3; -int xPos4; -int xPos5; int16_t OStatus; int16_t SAvg; int16_t SAvg2; @@ -377,4 +374,8 @@ WiFiConnect wc; WiFiServer Server(7373); WiFiClient RemoteClient; WiFiUDP Udp; -WebServer webserver(80); \ No newline at end of file +WebServer webserver(80); + +ScrollingTextDisplay rtplusDisplay(&RDSSprite, 146, 165, BackgroundColor); +ScrollingTextDisplay eonDisplay(&RDSSprite, 172, 165, BackgroundColor); +ScrollingTextDisplay eccDisplay(&RDSSprite, 199, 270, BackgroundColor); \ No newline at end of file diff --git a/src/gui.cpp b/src/gui.cpp index 0caac56..5b2fe67 100644 --- a/src/gui.cpp +++ b/src/gui.cpp @@ -609,10 +609,9 @@ void BuildAFScreen() { dropout = false; rdsreset = true; xPos = 0; - xPos2 = 0; - xPos3 = 0; - xPos4 = 0; - xPos5 = 0; + rtplusDisplay.reset(); + eonDisplay.reset(); + eccDisplay.reset(); for (byte i = 0; i < 20; i++) { mappedfreqold[i] = 0; mappedfreqold2[i] = 0; @@ -2994,10 +2993,10 @@ void BuildAdvancedRDS() { rdsreset = true; ShowMemoryPos(); xPos = 0; + rtplusDisplay.reset(); + eonDisplay.reset(); + eccDisplay.reset(); xPos2 = 0; - xPos3 = 0; - xPos4 = 0; - xPos5 = 0; } void BuildDisplay() { @@ -3114,10 +3113,10 @@ void BuildDisplay() { BWreset = true; dropout = false; xPos = 0; + rtplusDisplay.reset(); + eonDisplay.reset(); + eccDisplay.reset(); xPos2 = 0; - xPos3 = 0; - xPos4 = 0; - xPos5 = 0; MPold = 99; USold = 99; } diff --git a/src/rds.cpp b/src/rds.cpp index ef9d5da..17d53b7 100644 --- a/src/rds.cpp +++ b/src/rds.cpp @@ -66,32 +66,7 @@ void ShowAdvancedRDS() { eccstringWidth = RDSSprite.textWidth(ECCString); } - if (eccstringWidth < 270) { - xPos2 = 0; - RDSSprite.fillSprite(BackgroundColor); - if (RDSstatus) RDSSprite.setTextColor(RDSColor, RDSColorSmooth, false); else RDSSprite.setTextColor(RDSDropoutColor, RDSDropoutColorSmooth, false); - RDSSprite.drawString(ECCString, xPos2, 2); - RDSSprite.pushSprite(35, 199); - } else { - if (millis() - eccticker >= 5) { - if (xPos2 < -eccstringWidth) xPos2 = 0; - if (xPos2 == 0) { - if (millis() - ecctickerhold >= 2000) { - xPos2--; - ecctickerhold = millis(); - } - } else { - xPos2--; - ecctickerhold = millis(); - } - RDSSprite.fillSprite(BackgroundColor); - if (RDSstatus) RDSSprite.setTextColor(RDSColor, RDSColorSmooth, false); else RDSSprite.setTextColor(RDSDropoutColor, RDSDropoutColorSmooth, false); - RDSSprite.drawString(ECCString, xPos2, 2); - RDSSprite.drawString(ECCString, xPos2 + eccstringWidth, 2); - RDSSprite.pushSprite(35, 199); - eccticker = millis(); - } - } + eccDisplay.update(ECCString, eccstringWidth, RDSstatus, RDSColor, RDSColorSmooth, RDSDropoutColor, RDSDropoutColorSmooth); } ECColdString = ECCString; @@ -118,32 +93,7 @@ void ShowAdvancedRDS() { eonstringold = eonstring; } - if (eonstringWidth < 165) { - xPos3 = 0; - RDSSprite.fillSprite(BackgroundColor); - if (RDSstatus) RDSSprite.setTextColor(RDSColor, RDSColorSmooth, false); else RDSSprite.setTextColor(RDSDropoutColor, RDSDropoutColorSmooth, false); - RDSSprite.drawString(eonstring, xPos3, 2); - RDSSprite.pushSprite(35, 172); - } else { - if (millis() - eonticker >= 5) { - if (xPos3 < -eonstringWidth) xPos3 = 0; - if (xPos3 == 0) { - if (millis() - eontickerhold >= 2000) { - xPos3--; - eontickerhold = millis(); - } - } else { - xPos3--; - eontickerhold = millis(); - } - RDSSprite.fillSprite(BackgroundColor); - if (RDSstatus) RDSSprite.setTextColor(RDSColor, RDSColorSmooth, false); else RDSSprite.setTextColor(RDSDropoutColor, RDSDropoutColorSmooth, false); - RDSSprite.drawString(eonstring, xPos3, 2); - RDSSprite.drawString(eonstring, xPos3 + eonstringWidth, 2); - RDSSprite.pushSprite(35, 172); - eonticker = millis(); - } - } + eonDisplay.update(eonstring, eonstringWidth, RDSstatus, RDSColor, RDSColorSmooth, RDSDropoutColor, RDSDropoutColorSmooth); String rtplusstring; if (radio.rds.hasRTplus.get()) rtplusstring = (radio.rds.rdsplusTag1 != 169 ? String(textUI(radio.rds.rdsplusTag1)) + ": " + String(radio.rds.RTContent1) : "") + (radio.rds.rdsplusTag2 != 169 ? " - " + String(textUI(radio.rds.rdsplusTag2)) + ": " + String(radio.rds.RTContent2) : "") + " "; else rtplusstring = textUI(89); @@ -158,32 +108,7 @@ void ShowAdvancedRDS() { rtplusstringold = rtplusstring; } - if (rtplusstringWidth < 165) { - xPos4 = 0; - RDSSprite.fillSprite(BackgroundColor); - if (RDSstatus) RDSSprite.setTextColor(RDSColor, RDSColorSmooth, false); else RDSSprite.setTextColor(RDSDropoutColor, RDSDropoutColorSmooth, false); - RDSSprite.drawString(rtplusstring, xPos4, 2); - RDSSprite.pushSprite(35, 146); - } else { - if (millis() - rtplusticker >= 5) { - if (xPos4 < -rtplusstringWidth) xPos4 = 0; - if (xPos4 == 0) { - if (millis() - rtplustickerhold >= 2000) { - xPos4 --; - rtplustickerhold = millis(); - } - } else { - xPos4 --; - rtplustickerhold = millis(); - } - RDSSprite.fillSprite(BackgroundColor); - if (RDSstatus) RDSSprite.setTextColor(RDSColor, RDSColorSmooth, false); else RDSSprite.setTextColor(RDSDropoutColor, RDSDropoutColorSmooth, false); - RDSSprite.drawString(rtplusstring, xPos4, 2); - RDSSprite.drawString(rtplusstring, xPos4 + rtplusstringWidth, 2); - RDSSprite.pushSprite(35, 146); - rtplusticker = millis(); - } - } + rtplusDisplay.update(rtplusstring, rtplusstringWidth, RDSstatus, RDSColor, RDSColorSmooth, RDSDropoutColor, RDSDropoutColorSmooth); if (TPold != radio.rds.TP) { if (!screenmute) { @@ -547,30 +472,30 @@ void showPS() { // Handle scrolling logic for long PS if (PSSprite.textWidth(trimTrailingSpaces(radio.rds.stationNameLong)) < 150) { - xPos5 = 0; + xPos2 = 0; PSSprite.fillSprite(BackgroundColor); PSSprite.setTextColor(RDSstatus ? RDSColor : RDSDropoutColor, RDSstatus ? RDSColorSmooth : RDSDropoutColorSmooth, false); - PSSprite.drawString(stationNameLongString, xPos5, 2); + PSSprite.drawString(stationNameLongString, xPos2, 2); } else { if (millis() - pslongticker >= 5) { - if (xPos5 == 0 && millis() - pslongtickerhold < 2000) { + if (xPos2 == 0 && millis() - pslongtickerhold < 2000) { // Hold at position 0 } else { - xPos5--; + xPos2--; pslongtickerhold = millis(); } - if (xPos5 < -PSLongWidth) xPos5 = 0; + if (xPos2 < -PSLongWidth) xPos2 = 0; pslongticker = millis(); } PSSprite.fillSprite(BackgroundColor); PSSprite.setTextColor(RDSstatus ? RDSColor : RDSDropoutColor, RDSstatus ? RDSColorSmooth : RDSDropoutColorSmooth, false); - PSSprite.drawString(stationNameLongString, xPos5 + 8, 2); - PSSprite.drawString(stationNameLongString, xPos5 + PSLongWidth, 2); + PSSprite.drawString(stationNameLongString, xPos2 + 8, 2); + PSSprite.drawString(stationNameLongString, xPos2 + PSLongWidth, 2); } } else { - xPos5 = 0; + xPos2 = 0; PSSprite.fillSprite(BackgroundColor); for (int i = 0; i < 7; i++) {