Fixed memoryleak

This commit is contained in:
Sjef Verhoeven PE5PVB
2024-04-03 14:36:06 +02:00
parent 44bab28043
commit efa35f65ef
3 changed files with 79 additions and 76 deletions
+64 -63
View File
@@ -90,7 +90,6 @@ bool RDSSPYUSB;
bool RDSstatus; bool RDSstatus;
bool RDSstatusold; bool RDSstatusold;
bool rdsstereoold; bool rdsstereoold;
bool resetFontOnNextCall;
bool rtcset; bool rtcset;
bool screenmute; bool screenmute;
bool screensavertriggered = false; bool screensavertriggered = false;
@@ -592,7 +591,7 @@ void setup() {
PSSprite.loadFont(FONT28); PSSprite.loadFont(FONT28);
PSSprite.setSwapBytes(true); PSSprite.setSwapBytes(true);
UpdateFonts(); UpdateFonts(0);
if (digitalRead(BWBUTTON) == LOW && digitalRead(ROTARY_BUTTON) == HIGH) { if (digitalRead(BWBUTTON) == LOW && digitalRead(ROTARY_BUTTON) == HIGH) {
if (rotarymode == 0) rotarymode = 1; else rotarymode = 0; if (rotarymode == 0) rotarymode = 1; else rotarymode = 0;
@@ -1958,13 +1957,7 @@ void ModeButtonPress() {
menuoption = ITEM1; menuoption = ITEM1;
menupage = INDEX; menupage = INDEX;
menuitem = 0; menuitem = 0;
if (language == LANGUAGE_CHS) { UpdateFonts(1);
FullLineSprite.loadFont(FONT16_CHS);
OneBigLineSprite.loadFont(FONT28_CHS);
} else {
FullLineSprite.loadFont(FONT16);
OneBigLineSprite.loadFont(FONT28);
}
BuildMenu(); BuildMenu();
menu = true; menu = true;
ScreensaverTimerSet(OFF); ScreensaverTimerSet(OFF);
@@ -2059,11 +2052,10 @@ void ModeButtonPress() {
Serial.end(); Serial.end();
if (wifi) remoteip = IPAddress (WiFi.localIP()[0], WiFi.localIP()[1], WiFi.localIP()[2], subnetclient); if (wifi) remoteip = IPAddress (WiFi.localIP()[0], WiFi.localIP()[1], WiFi.localIP()[2], subnetclient);
if (USBmode) Serial.begin(19200); else Serial.begin(115200); if (USBmode) Serial.begin(19200); else Serial.begin(115200);
RadiotextSprite.unloadFont();
RDSSprite.unloadFont(); UpdateFonts(0);
SquelchSprite.unloadFont(); FullLineSprite.unloadFont();
FrequencySprite.unloadFont(); OneBigLineSprite.unloadFont();
UpdateFonts();
BuildDisplay(); BuildDisplay();
ShowSignalLevel(); ShowSignalLevel();
ShowBW(); ShowBW();
@@ -2604,20 +2596,6 @@ void ShowFreq(int mode) {
if (!screenmute) { if (!screenmute) {
if (CurrentSkin == 1) FrequencySprite.pushImage (-57, -40, 320, 240, skin1_mainbackground); else FrequencySprite.fillSprite(BackgroundColor); if (CurrentSkin == 1) FrequencySprite.pushImage (-57, -40, 320, 240, skin1_mainbackground); else FrequencySprite.fillSprite(BackgroundColor);
FrequencySprite.setTextDatum(TR_DATUM);
FrequencySprite.setTextColor(FreqColor, FreqColorSmooth, false);
FrequencySprite.drawString(String(frequency_AM) + " ", 218, -6);
FrequencySprite.setTextColor(PrimaryColor, PrimaryColorSmooth, false);
FrequencySprite.setTextDatum(TL_DATUM);
FrequencySprite.loadFont(FONT16);
if (band == BAND_SW && showSWMIBand) {
DivdeSWMIBand();
updateSWMIBand();
}
if (CurrentSkin == 1) FrequencySprite.pushSprite(57, 40); else FrequencySprite.pushSprite(46, 46);
FrequencySprite.setTextDatum(TR_DATUM);
switch (freqfont) { switch (freqfont) {
case 0: FrequencySprite.loadFont(FREQFONT0); break; case 0: FrequencySprite.loadFont(FREQFONT0); break;
@@ -2627,6 +2605,22 @@ void ShowFreq(int mode) {
case 4: FrequencySprite.loadFont(FREQFONT4); break; case 4: FrequencySprite.loadFont(FREQFONT4); break;
case 5: FrequencySprite.loadFont(FREQFONT5); break; case 5: FrequencySprite.loadFont(FREQFONT5); break;
} }
FrequencySprite.setTextDatum(TR_DATUM);
FrequencySprite.setTextColor(FreqColor, FreqColorSmooth, false);
FrequencySprite.drawString(String(frequency_AM) + " ", 218, -6);
FrequencySprite.unloadFont();
FrequencySprite.setTextColor(PrimaryColor, PrimaryColorSmooth, false);
FrequencySprite.setTextDatum(TL_DATUM);
FrequencySprite.loadFont(FONT16);
if (band == BAND_SW && showSWMIBand) {
DivdeSWMIBand();
updateSWMIBand();
}
FrequencySprite.unloadFont();
if (CurrentSkin == 1) FrequencySprite.pushSprite(57, 40); else FrequencySprite.pushSprite(46, 46);
} }
freqold = frequency_AM; freqold = frequency_AM;
@@ -2644,6 +2638,17 @@ void ShowFreq(int mode) {
tftReplace(1, String(freqold / 100) + "." + (freqold % 100 < 10 ? "0" : "") + String(freqold % 100) + " MHz", String(freq / 100) + "." + (freq % 100 < 10 ? "0" : "") + String(freq % 100), 290, 201, BWAutoColor, BWAutoColorSmooth, BackgroundColor, 16); tftReplace(1, String(freqold / 100) + "." + (freqold % 100 < 10 ? "0" : "") + String(freqold % 100) + " MHz", String(freq / 100) + "." + (freq % 100 < 10 ? "0" : "") + String(freq % 100), 290, 201, BWAutoColor, BWAutoColorSmooth, BackgroundColor, 16);
freqold = freq; freqold = freq;
} else { } else {
switch (freqfont) {
case 0: FrequencySprite.loadFont(FREQFONT0); break;
case 1: FrequencySprite.loadFont(FREQFONT1); break;
case 2: FrequencySprite.loadFont(FREQFONT2); break;
case 3: FrequencySprite.loadFont(FREQFONT3); break;
case 4: FrequencySprite.loadFont(FREQFONT4); break;
case 5: FrequencySprite.loadFont(FREQFONT5); break;
}
FrequencySprite.setTextDatum(TR_DATUM);
if (mode == 0) { if (mode == 0) {
if (CurrentSkin == 1) FrequencySprite.pushImage (-55, -40, 320, 240, skin1_mainbackground); else FrequencySprite.fillSprite(BackgroundColor); if (CurrentSkin == 1) FrequencySprite.pushImage (-55, -40, 320, 240, skin1_mainbackground); else FrequencySprite.fillSprite(BackgroundColor);
FrequencySprite.setTextColor(FreqColor, FreqColorSmooth, false); FrequencySprite.setTextColor(FreqColor, FreqColorSmooth, false);
@@ -2654,6 +2659,7 @@ void ShowFreq(int mode) {
if (CurrentSkin == 1) FrequencySprite.pushImage (-55, -40, 320, 240, skin1_mainbackground); else FrequencySprite.fillSprite(BackgroundColor); if (CurrentSkin == 1) FrequencySprite.pushImage (-55, -40, 320, 240, skin1_mainbackground); else FrequencySprite.fillSprite(BackgroundColor);
if (CurrentSkin == 1) FrequencySprite.pushSprite(57, 40); else FrequencySprite.pushSprite(46, 46); if (CurrentSkin == 1) FrequencySprite.pushSprite(57, 40); else FrequencySprite.pushSprite(46, 46);
} }
FrequencySprite.unloadFont();
} }
} }
} }
@@ -3105,6 +3111,8 @@ void doSquelch() {
if (unit == 2) SquelchShow = round((float(Squelch) / 10.0 - 10.0 * log10(75) - 90.0) * 10.0) / 10; if (unit == 2) SquelchShow = round((float(Squelch) / 10.0 - 10.0 * log10(75) - 90.0) * 10.0) / 10;
if (Squelch > 920) Squelch = 920; if (Squelch > 920) Squelch = 920;
if (language == LANGUAGE_CHS) SquelchSprite.loadFont(FONT16_CHS); else SquelchSprite.loadFont(FONT16);
if (!XDRGTKUSB && !XDRGTKTCP && usesquelch) { if (!XDRGTKUSB && !XDRGTKTCP && usesquelch) {
if (!screenmute && usesquelch && !advancedRDS && !afscreen) { if (!screenmute && usesquelch && !advancedRDS && !afscreen) {
if (!menu && (Squelch > Squelchold + 2 || Squelch < Squelchold - 2)) { if (!menu && (Squelch > Squelchold + 2 || Squelch < Squelchold - 2)) {
@@ -3254,6 +3262,7 @@ void doSquelch() {
} }
} }
} }
SquelchSprite.unloadFont();
} }
void updateBW() { void updateBW() {
@@ -4104,14 +4113,7 @@ void tftReplace(int8_t offset, const String & textold, const String & text, int1
} }
if (fontsize == 48) selectedFont = FONT48; if (fontsize == 48) selectedFont = FONT48;
if (currentFont != selectedFont || resetFontOnNextCall) {
if (currentFont != nullptr) tft.unloadFont();
tft.loadFont(selectedFont); tft.loadFont(selectedFont);
currentFont = selectedFont;
resetFontOnNextCall = false;
}
tft.setTextColor(background, background, false); tft.setTextColor(background, background, false);
switch (offset) { switch (offset) {
@@ -4133,6 +4135,7 @@ void tftReplace(int8_t offset, const String & textold, const String & text, int1
modifiedText.replace("\n", " "); modifiedText.replace("\n", " ");
tft.drawString(modifiedText, x, y); tft.drawString(modifiedText, x, y);
tft.unloadFont();
} }
void tftPrint(int8_t offset, const String & text, int16_t x, int16_t y, int color, int smoothcolor, uint8_t fontsize) { void tftPrint(int8_t offset, const String & text, int16_t x, int16_t y, int color, int smoothcolor, uint8_t fontsize) {
@@ -4144,24 +4147,10 @@ void tftPrint(int8_t offset, const String & text, int16_t x, int16_t y, int colo
if (fontsize == 16) selectedFont = FONT16; if (fontsize == 16) selectedFont = FONT16;
if (fontsize == 28) selectedFont = FONT28; if (fontsize == 28) selectedFont = FONT28;
} }
if (fontsize == 48) selectedFont = FONT48;
if (fontsize == 52) {
switch (freqfont) {
case 0: selectedFont = FREQFONT0; break;
case 1: selectedFont = FREQFONT1; break;
case 2: selectedFont = FREQFONT2; break;
case 3: selectedFont = FREQFONT3; break;
case 4: selectedFont = FREQFONT4; break;
case 5: selectedFont = FREQFONT5; break;
}
}
if (currentFont != selectedFont || resetFontOnNextCall) { if (fontsize == 48) selectedFont = FONT48;
if (currentFont != nullptr) tft.unloadFont();
tft.loadFont(selectedFont); tft.loadFont(selectedFont);
currentFont = selectedFont;
resetFontOnNextCall = false;
}
tft.setTextColor(color, smoothcolor, (fontsize == 52 ? true : false)); tft.setTextColor(color, smoothcolor, (fontsize == 52 ? true : false));
@@ -4175,6 +4164,7 @@ void tftPrint(int8_t offset, const String & text, int16_t x, int16_t y, int colo
modifiedText.replace("\n", " "); modifiedText.replace("\n", " ");
tft.drawString(modifiedText, x, y, 1); tft.drawString(modifiedText, x, y, 1);
tft.unloadFont();
} }
void deepSleep() { void deepSleep() {
@@ -4186,27 +4176,38 @@ void deepSleep() {
esp_deep_sleep_start(); esp_deep_sleep_start();
} }
void UpdateFonts() { void UpdateFonts(bool mode) {
switch (mode) {
case 0: // Use in radio mode
RadiotextSprite.unloadFont();
RDSSprite.unloadFont();
if (language == LANGUAGE_CHS) { if (language == LANGUAGE_CHS) {
RadiotextSprite.loadFont(FONT16_CHS); RadiotextSprite.loadFont(FONT16_CHS);
RDSSprite.loadFont(FONT16_CHS); RDSSprite.loadFont(FONT16_CHS);
SquelchSprite.loadFont(FONT16_CHS);
FullLineSprite.loadFont(FONT16_CHS);
OneBigLineSprite.loadFont(FONT28_CHS);
} else { } else {
RadiotextSprite.loadFont(FONT16); RadiotextSprite.loadFont(FONT16);
RDSSprite.loadFont(FONT16); RDSSprite.loadFont(FONT16);
SquelchSprite.loadFont(FONT16); }
break;
case 1: // Use in menu mode
FullLineSprite.unloadFont();
OneBigLineSprite.unloadFont();
if (language == LANGUAGE_CHS) {
FullLineSprite.loadFont(FONT16_CHS);
OneBigLineSprite.loadFont(FONT28_CHS);
} else {
FullLineSprite.loadFont(FONT16); FullLineSprite.loadFont(FONT16);
OneBigLineSprite.loadFont(FONT28); OneBigLineSprite.loadFont(FONT28);
} }
break;
switch (freqfont) { case 2: // Unload all
case 0: FrequencySprite.loadFont(FREQFONT0); break; FullLineSprite.unloadFont();
case 1: FrequencySprite.loadFont(FREQFONT1); break; OneBigLineSprite.unloadFont();
case 2: FrequencySprite.loadFont(FREQFONT2); break; RadiotextSprite.unloadFont();
case 3: FrequencySprite.loadFont(FREQFONT3); break; RDSSprite.unloadFont();
case 4: FrequencySprite.loadFont(FREQFONT4); break; break;
case 5: FrequencySprite.loadFont(FREQFONT5); break;
} }
} }
+3 -1
View File
@@ -3940,6 +3940,7 @@ void DoMenu() {
tftPrint(0, "http://192.168.4.1", 155, 174, PrimaryColor, PrimaryColorSmooth, 16); tftPrint(0, "http://192.168.4.1", 155, 174, PrimaryColor, PrimaryColorSmooth, 16);
char key [9]; char key [9];
XDRGTK_key.toCharArray(key, 9); XDRGTK_key.toCharArray(key, 9);
UpdateFonts(3);
WiFiConnectParam XDRGTK_key_text("Set XDRGTK Password: (max 8 characters)"); WiFiConnectParam XDRGTK_key_text("Set XDRGTK Password: (max 8 characters)");
WiFiConnectParam XDRGTK_key_input("XDRGTK_key", "Password", key, 9); WiFiConnectParam XDRGTK_key_input("XDRGTK_key", "Password", key, 9);
wc.addParameter(&XDRGTK_key_text); wc.addParameter(&XDRGTK_key_text);
@@ -3948,6 +3949,7 @@ void DoMenu() {
XDRGTK_key = XDRGTK_key_input.getValue(); XDRGTK_key = XDRGTK_key_input.getValue();
EEPROM.writeString(EE_STRING_XDRGTK_KEY, XDRGTK_key); EEPROM.writeString(EE_STRING_XDRGTK_KEY, XDRGTK_key);
EEPROM.commit(); EEPROM.commit();
UpdateFonts(2);
wifi = true; wifi = true;
tryWiFi(); tryWiFi();
delay(2000); delay(2000);
@@ -3992,7 +3994,7 @@ void DoMenu() {
doTheme(); doTheme();
} }
menuopen = false; menuopen = false;
UpdateFonts(); UpdateFonts(1);
BuildMenu(); BuildMenu();
} }
} }
+1 -1
View File
@@ -212,7 +212,7 @@ extern void updateiMS();
extern void updateEQ(); extern void updateEQ();
extern void doTheme(); extern void doTheme();
extern void tryWiFi(); extern void tryWiFi();
extern void UpdateFonts(); extern void UpdateFonts(bool mode);
extern void tftPrint(int8_t offset, const String & text, int16_t x, int16_t y, int color, int smoothcolor, uint8_t fontsize); extern void tftPrint(int8_t offset, const String & text, int16_t x, int16_t y, int color, int smoothcolor, uint8_t fontsize);
#endif #endif