Code optimalisation

This commit is contained in:
Sjef Verhoeven PE5PVB
2024-05-26 01:42:32 +02:00
parent 15cc9ec89a
commit d04e05607d
3 changed files with 45 additions and 34 deletions
+15 -15
View File
@@ -527,10 +527,7 @@ void setup() {
MWHighEdgeSet = mwstepsize == false ? FREQ_MW_HIGH_EDGE_MAX_9K : FREQ_MW_HIGH_EDGE_MAX_10K; MWHighEdgeSet = mwstepsize == false ? FREQ_MW_HIGH_EDGE_MAX_9K : FREQ_MW_HIGH_EDGE_MAX_10K;
SWLowEdgeSet = FREQ_SW_LOW_EDGE_MIN; SWLowEdgeSet = FREQ_SW_LOW_EDGE_MIN;
SWHighEdgeSet = FREQ_SW_HIGH_EDGE_MAX; SWHighEdgeSet = FREQ_SW_HIGH_EDGE_MAX;
if (LowEdgeOIRTSet < FREQ_FM_OIRT_START || LowEdgeOIRTSet > FREQ_FM_OIRT_END) LowEdgeOIRTSet = FREQ_FM_OIRT_START; LowEdgeOIRTSet = FREQ_FM_OIRT_START;
if (HighEdgeOIRTSet < FREQ_FM_OIRT_START || HighEdgeOIRTSet > FREQ_FM_OIRT_END) HighEdgeOIRTSet = FREQ_FM_OIRT_END;
LowEdgeOIRTSet = LowEdgeOIRTSet;
HighEdgeOIRTSet = FREQ_FM_OIRT_END; HighEdgeOIRTSet = FREQ_FM_OIRT_END;
for (int i = 0; i < EE_PRESETS_CNT; i++) presets[i].band = EEPROM.readByte(i + EE_PRESETS_BAND_START); for (int i = 0; i < EE_PRESETS_CNT; i++) presets[i].band = EEPROM.readByte(i + EE_PRESETS_BAND_START);
@@ -547,14 +544,12 @@ void setup() {
} }
} }
btStop();
if (USBmode) Serial.begin(19200); else Serial.begin(115200); if (USBmode) Serial.begin(19200); else Serial.begin(115200);
if (iMSset == 1 && EQset == 1) iMSEQ = 2; if (iMSset && EQset) iMSEQ = 2;
if (iMSset == 0 && EQset == 1) iMSEQ = 3; if (!iMSset && EQset) iMSEQ = 3;
if (iMSset == 1 && EQset == 0) iMSEQ = 4; if (iMSset && !EQset) iMSEQ = 4;
if (iMSset == 0 && EQset == 0) iMSEQ = 1; if (!iMSset && !EQset) iMSEQ = 1;
switch (band) { switch (band) {
case BAND_LW: case BAND_LW:
@@ -578,8 +573,6 @@ void setup() {
break; break;
} }
if (IsStationEmpty()) memoryposstatus = MEM_DARK; else memoryposstatus = MEM_NORMAL;
tft.init(); tft.init();
tft.initDMA(); tft.initDMA();
@@ -799,17 +792,19 @@ void setup() {
Wire.endTransmission(); Wire.endTransmission();
} }
SelectBand();
if (tunemode == TUNE_MEM) DoMemoryPosTune(); if (tunemode == TUNE_MEM) DoMemoryPosTune();
SelectBand();
setupmode = false; setupmode = false;
if (edgebeep) radio.tone(50, -5, 2000); if (edgebeep) radio.tone(50, -5, 2000);
radio.I2Sin(false);
if (!usesquelch) radio.setUnMute(); if (!usesquelch) radio.setUnMute();
if (screensaverset) { if (screensaverset) {
ScreensaverTimerInit(); ScreensaverTimerInit();
ScreensaverTimerSet(screensaverOptions[screensaverset]); ScreensaverTimerSet(screensaverOptions[screensaverset]);
} }
tottimer = millis(); tottimer = millis();
} }
@@ -820,7 +815,6 @@ void loop() {
unsigned long totprobe = tot * 60000; unsigned long totprobe = tot * 60000;
if (millis() >= tottimer + totprobe) deepSleep(); if (millis() >= tottimer + totprobe) deepSleep();
} }
if (digitalRead(BANDBUTTON) == LOW ) BANDBUTTONPress();
if (scandxmode) { if (scandxmode) {
if (millis() >= scantimer + (scanhold * 1000)) { if (millis() >= scantimer + (scanhold * 1000)) {
@@ -1073,6 +1067,12 @@ void loop() {
} }
} }
if (digitalRead(BANDBUTTON) == LOW) {
tottimer = millis();
if (screensavertriggered && !touchrotating) WakeToSleep(REVERSE);
BANDBUTTONPress();
}
if (digitalRead(ROTARY_BUTTON) == LOW) { if (digitalRead(ROTARY_BUTTON) == LOW) {
tottimer = millis(); tottimer = millis();
if (screensavertriggered && !touchrotating) WakeToSleep(REVERSE); if (screensavertriggered && !touchrotating) WakeToSleep(REVERSE);
+17 -6
View File
@@ -47,12 +47,16 @@ void ShowAdvancedRDS() {
} }
if (ptynold != radio.rds.PTYN || rdsreset) { if (ptynold != radio.rds.PTYN || rdsreset) {
if (!screenmute) tftPrint(-1, "PTYN N/A", 216, 109, BackgroundColor, BackgroundColor, 16); if (!screenmute) {
if (!screenmute) tftPrint(-1, ptynold, 216, 109, BackgroundColor, BackgroundColor, 16); if (ptynold != "PTYN N/A") {
tftPrint(-1, "PTYN N/A", 216, 109, BackgroundColor, BackgroundColor, 16);
tftPrint(-1, ptynold, 216, 109, BackgroundColor, BackgroundColor, 16);
}
if (radio.rds.PTYN.length() == 0) radio.rds.PTYN = "PTYN N/A"; if (radio.rds.PTYN.length() == 0) radio.rds.PTYN = "PTYN N/A";
if (!screenmute) tftPrint(-1, String(radio.rds.PTYN), 216, 109, RDSColor, RDSColorSmooth, 16); tftPrint(-1, String(radio.rds.PTYN), 216, 109, RDSColor, RDSColorSmooth, 16);
ptynold = radio.rds.PTYN; ptynold = radio.rds.PTYN;
} }
}
if (licold != radio.rds.LIC || rdsreset) { if (licold != radio.rds.LIC || rdsreset) {
if (!screenmute) { if (!screenmute) {
@@ -60,9 +64,9 @@ void ShowAdvancedRDS() {
tftPrint(-1, LIColdString, 242, 208, BackgroundColor, BackgroundColor, 16); tftPrint(-1, LIColdString, 242, 208, BackgroundColor, BackgroundColor, 16);
if (radio.rds.hasLIC) tftPrint(-1, (radio.rds.LICtext.length() == 0 ? myLanguage[language][73] : radio.rds.LICtext), 242, 208, RDSColor, RDSColorSmooth, 16); else tftPrint(-1, "N/A", 242, 208, RDSColor, RDSColorSmooth, 16); if (radio.rds.hasLIC) tftPrint(-1, (radio.rds.LICtext.length() == 0 ? myLanguage[language][73] : radio.rds.LICtext), 242, 208, RDSColor, RDSColorSmooth, 16); else tftPrint(-1, "N/A", 242, 208, RDSColor, RDSColorSmooth, 16);
if (radio.rds.LICtext.length() == 0) LIColdString = myLanguage[language][73]; else LIColdString = radio.rds.LICtext; if (radio.rds.LICtext.length() == 0) LIColdString = myLanguage[language][73]; else LIColdString = radio.rds.LICtext;
}
licold = radio.rds.LIC; licold = radio.rds.LIC;
} }
}
String pinstring = String(radio.rds.pinDay) + " " + String(radio.rds.pinHour) + ":" + (radio.rds.pinMin < 10 ? "0" : "") + String(radio.rds.pinMin); String pinstring = String(radio.rds.pinDay) + " " + String(radio.rds.pinHour) + ":" + (radio.rds.pinMin < 10 ? "0" : "") + String(radio.rds.pinMin);
if (pinstringold != pinstring) { if (pinstringold != pinstring) {
@@ -306,6 +310,7 @@ void readRds() {
radio.readRDS(showrdserrors); radio.readRDS(showrdserrors);
RDSstatus = radio.rds.hasRDS; RDSstatus = radio.rds.hasRDS;
ShowRDSLogo(RDSstatus); ShowRDSLogo(RDSstatus);
if (!screenmute && !afscreen) { if (!screenmute && !afscreen) {
if (!RDSstatus) { if (!RDSstatus) {
if (radio.rds.correctPI != 0 && !dropout) { if (radio.rds.correctPI != 0 && !dropout) {
@@ -329,10 +334,11 @@ void readRds() {
} }
} }
if (!radio.rds.hasLongPS) {
PSSprite.fillSprite(BackgroundColor); PSSprite.fillSprite(BackgroundColor);
PSSprite.setTextColor(RDSDropoutColor, RDSDropoutColorSmooth, false); PSSprite.setTextColor(RDSDropoutColor, RDSDropoutColorSmooth, false);
PSSprite.drawString(PSold, 0, 0); PSSprite.drawString(PSold, 0, 0);
if (!radio.rds.hasLongPS) {
if (advancedRDS) { if (advancedRDS) {
PSSprite.pushSprite(36, 74); PSSprite.pushSprite(36, 74);
} else { } else {
@@ -384,10 +390,11 @@ void readRds() {
} }
} }
if (!radio.rds.hasLongPS) {
PSSprite.fillSprite(BackgroundColor); PSSprite.fillSprite(BackgroundColor);
PSSprite.setTextColor(RDSColor, RDSColorSmooth, false); PSSprite.setTextColor(RDSColor, RDSColorSmooth, false);
PSSprite.drawString(PSold, 0, 0); PSSprite.drawString(PSold, 0, 0);
if (!radio.rds.hasLongPS) {
if (advancedRDS) { if (advancedRDS) {
PSSprite.pushSprite(36, 74); PSSprite.pushSprite(36, 74);
} else { } else {
@@ -580,6 +587,7 @@ void showPI() {
if (RDSSPYUSB) Serial.print("G:\r\nRESET-------\r\n\r\n"); if (RDSSPYUSB) Serial.print("G:\r\nRESET-------\r\n\r\n");
if (RDSSPYTCP) RemoteClient.print("G:\r\nRESET-------\r\n\r\n"); if (RDSSPYTCP) RemoteClient.print("G:\r\nRESET-------\r\n\r\n");
} }
if (!screenmute) { if (!screenmute) {
if (advancedRDS) { if (advancedRDS) {
if (region == REGION_EU) { if (region == REGION_EU) {
@@ -628,6 +636,7 @@ void showPI() {
stationIDold = radio.rds.stationIDtext; stationIDold = radio.rds.stationIDtext;
stationStateold = radio.rds.stationStatetext; stationStateold = radio.rds.stationStatetext;
} }
if (wifi) { if (wifi) {
Udp.beginPacket(remoteip, 9030); Udp.beginPacket(remoteip, 9030);
Udp.print("from=TEF_tuner " + String(stationlistid, DEC) + ";PI=" + String(radio.rds.picode, 4)); Udp.print("from=TEF_tuner " + String(stationlistid, DEC) + ";PI=" + String(radio.rds.picode, 4));
@@ -654,6 +663,7 @@ void showPTY() {
} }
} }
PTYold = radio.rds.stationType; PTYold = radio.rds.stationType;
if (wifi) { if (wifi) {
Udp.beginPacket(remoteip, 9030); Udp.beginPacket(remoteip, 9030);
Udp.print("from=TEF_tuner " + String(stationlistid, DEC) + ";PTY="); Udp.print("from=TEF_tuner " + String(stationlistid, DEC) + ";PTY=");
@@ -822,6 +832,7 @@ void showRadioText() {
} }
} }
} }
if (radio.rds.hasRT) { if (radio.rds.hasRT) {
if (!advancedRDS) { if (!advancedRDS) {
if (radio.rds.rtAB) { if (radio.rds.rtAB) {