small refactorings

This commit is contained in:
2026-01-06 19:58:51 +01:00
parent 70cbed7570
commit 0ceb8047e8
4 changed files with 45 additions and 67 deletions

View File

@@ -11,7 +11,7 @@ void Communication() {
if (packetSize > 0) {
char packetBuffer[packetSize + 1];
Udp.read(packetBuffer, packetSize);
packetBuffer[packetSize] = '\0'; // Ensure valid string
packetBuffer[packetSize] = '\0';
Udp.endPacket();
String packet = String(packetBuffer);
@@ -28,23 +28,24 @@ void Communication() {
char command = packet.charAt(1);
switch (command) {
case 'U':
case 'D':
case 'D': {
tunemode = TUNE_MAN;
ShowTuneMode();
if (command == 'U') TuneUp(); else TuneDown();
ShowFreq(0);
break;
}
case '>':
case '<':
case '<': {
if (command == '>') direction = true; else direction = false;
Seek(direction);
ShowFreq(0);
break;
}
case 'T':
uint16_t freqtemp;
freqtemp = packet.substring(2).toInt();
case 'T': {
uint16_t freqtemp = packet.substring(2).toInt();
if (BAND_FM) freqtemp -= ConverterSet * 1000;
if (seek) seek = false;
radio.clearRDS(fullsearchrds);
@@ -74,11 +75,12 @@ void Communication() {
}
ShowFreq(0);
break;
}
case 'S': if (!scandxmode) startFMDXScan(); break;
case 'E': if (scandxmode) cancelDXScan(); break;
case 'S': {if (!scandxmode) startFMDXScan(); break;}
case 'E': {if (scandxmode) cancelDXScan(); break;}
case 'R': radio.clearRDS(fullsearchrds); break;
case 'R': {radio.clearRDS(fullsearchrds); break;}
}
return;
}
@@ -168,8 +170,6 @@ void Communication() {
passwordcrypt();
RemoteClient.print(saltkey + "\n");
}
} else {
if (Server.hasClient()) Server.available().stop();
}
if (wificonnected && !RemoteClient.connected()) {
@@ -195,9 +195,7 @@ void Communication() {
RemoteClient.print("o1,0\n");
RemoteClient.print("G" + String(!EQset) + String(!iMSset) + "\n");
store = true;
} else {
RemoteClient.print("a0\n");
}
} else RemoteClient.print("a0\n");
}
}

View File

@@ -1035,8 +1035,8 @@ void setup() {
if (TEF != 102 && TEF != 205) SetTunerPatch();
radio.init(TEF);
uint16_t device, hw, sw;
uint16_t device, hw, sw;
radio.getIdentification(&device, &hw, &sw);
if (TEF != (highByte(hw) * 100 + highByte(sw))) SetTunerPatch();
@@ -1088,7 +1088,7 @@ void setup() {
Udp.stop();
tft.fillRect(184, 230, 16, 6, SignificantColor);
}
delay(1500);
delay(1000);
radio.setVolume(VolSet);
radio.setOffset(LevelOffset);
@@ -1389,11 +1389,8 @@ void loop() {
tftPrint(ALEFT, "100", 160, 144, ActiveColor, ActiveColorSmooth, 16);
tftPrint(ACENTER, "A", 7, 128, ActiveColor, ActiveColorSmooth, 16);
for (byte segments = 0; segments < 94; segments++) {
if (segments > 54) {
if (((segments - 53) % 10) == 0) tft.fillRect(16 + (2 * segments), 141, 2, 2, BarSignificantColor);
} else {
if (((segments + 1) % 6) == 0) tft.fillRect(16 + (2 * segments), 141, 2, 2, ModBarInsignificantColor);
}
if (segments > 54 && (((segments - 53) % 10) == 0)) tft.fillRect(16 + (2 * segments), 141, 2, 2, BarSignificantColor);
else if(((segments + 1) % 6) == 0) tft.fillRect(16 + (2 * segments), 141, 2, 2, ModBarInsignificantColor);
}
}
if (radio.rds.region == 0) tftPrint(ALEFT, "PI", 212, 193, ActiveColor, ActiveColorSmooth, 16);
@@ -2654,14 +2651,12 @@ void KeyUp() {
case TUNE_MAN:
TuneUp();
break;
case TUNE_AUTO:
direction = true;
seek = true;
seekinit = true;
Seek(direction);
break;
case TUNE_MEM:
memorypos++;
if (memorypos > EE_PRESETS_CNT - 1) memorypos = 0;
@@ -2816,7 +2811,6 @@ void DoMemoryPosTune() {
#endif
radio.clearRDS(fullsearchrds);
// Process empty stations
if (IsStationEmpty()) {
memoryposstatus = MEM_DARK;
return;
@@ -3725,9 +3719,9 @@ void TuneUp() {
}
}
if (stepsize == 1) temp = 1;
if (stepsize == 2) temp = 10;
if (stepsize == 3) temp = 100;
if (stepsize == 4) temp = 1000;
else if (stepsize == 2) temp = 10;
else if (stepsize == 3) temp = 100;
else if (stepsize == 4) temp = 1000;
if (rotaryaccelerate && rotarycounter > 2) temp *= 2;
if (band == BAND_FM) {
@@ -3817,9 +3811,9 @@ void TuneDown() {
}
}
if (stepsize == 1) temp = 1;
if (stepsize == 2) temp = 10;
if (stepsize == 3) temp = 100;
if (stepsize == 4) temp = 1000;
else if (stepsize == 2) temp = 10;
else if (stepsize == 3) temp = 100;
else if (stepsize == 4) temp = 1000;
if (rotaryaccelerate && rotarycounter > 2) temp *= 2;
if (band == BAND_FM) {
@@ -3919,12 +3913,10 @@ void read_encoder() {
if (millis() - rotarytimer >= 15) {
rotarycounteraccelerator = 2; // Steady fast
rotarycounter = 0;
}
if (millis() - rotarytimer >= 30) {
} else if (millis() - rotarytimer >= 30) {
rotarycounteraccelerator = 4;
rotarycounter = 0;
}
if (millis() - rotarytimer >= 45) {
} else if (millis() - rotarytimer >= 45) {
rotarycounteraccelerator = 6; // Quick flicks
rotarycounter = 0;
}
@@ -3999,7 +3991,7 @@ void MuteScreen(bool setting) {
void DefaultSettings() {
EEPROM.writeByte(EE_BYTE_CHECKBYTE, EE_CHECKBYTE_VALUE);
EEPROM.writeUInt(EE_UINT16_FREQUENCY_FM, 10000);
EEPROM.writeUInt(EE_UINT16_FREQUENCY_FM, 9500);
EEPROM.writeUInt(EE_UINT16_FREQUENCY_OIRT, FREQ_FM_OIRT_START);
EEPROM.writeByte(EE_BYTE_VOLSET, 0);
EEPROM.writeUInt(EE_UINT16_CONVERTERSET, 0);
@@ -4143,10 +4135,10 @@ void tftReplace(int8_t offset, const String & textold, const String & text, int1
const uint8_t *selectedFont = nullptr;
if (language == LANGUAGE_CHS) {
if (fontsize == 16) selectedFont = FONT16_CHS;
if (fontsize == 28) selectedFont = FONT28_CHS;
else if (fontsize == 28) selectedFont = FONT28_CHS;
} else {
if (fontsize == 16) selectedFont = FONT16;
if (fontsize == 28) selectedFont = FONT28;
else if (fontsize == 28) selectedFont = FONT28;
}
if (fontsize == 48) selectedFont = FONT48;
@@ -4179,10 +4171,10 @@ void tftPrint(int8_t offset, const String & text, int16_t x, int16_t y, int colo
const uint8_t *selectedFont = nullptr;
if (language == LANGUAGE_CHS) {
if (fontsize == 16) selectedFont = FONT16_CHS;
if (fontsize == 28) selectedFont = FONT28_CHS;
else if (fontsize == 28) selectedFont = FONT28_CHS;
} else {
if (fontsize == 16) selectedFont = FONT16;
if (fontsize == 28) selectedFont = FONT28;
else if (fontsize == 28) selectedFont = FONT28;
}
if (fontsize == 48) selectedFont = FONT48;
@@ -4224,7 +4216,6 @@ void UpdateFonts(byte mode) {
OneBigLineSprite.loadFont(FONT28);
}
break;
case 1:
FullLineSprite.unloadFont();
OneBigLineSprite.unloadFont();

View File

@@ -14,8 +14,8 @@ void doTouchEvent(uint16_t x, uint16_t y) {
ModeButtonPress();
return;
}
if (menuopen) { // Menu navigation
if (x > 18 && x < 78 && y > 150 && y < 190) KeyDown(); // ---------------
if (menuopen) {
if (x > 18 && x < 78 && y > 150 && y < 190) KeyDown();
if (x > 240 && x < 300 && y > 150 && y < 190) KeyUp();
if ((x > 240 && x < 300 && y > 40 && y < 80) || (x > 130 && x < 190 && y > 150 && y < 190)) {
touchrepeat = false;
@@ -93,18 +93,18 @@ void doTouchEvent(uint16_t x, uint16_t y) {
}
}
if (!menu && !BWtune) { // All pages except menu
if (x > 30 && x < 65 && y > 0 && y < 30 && band < BAND_GAP) { // ---------------------
doStereoToggle(); // Stereo toggle
if (!menu && !BWtune) {
if (x > 30 && x < 65 && y > 0 && y < 30 && band < BAND_GAP) {
doStereoToggle();
return;
} else if (x > 155 && x < 250 && y > 0 && y < 30) {
BuildBWSelector(); // Set bandwidth
BuildBWSelector();
BWtune = true;
return;
}
}
if (BWtune) { // BW menu
if (BWtune) {
if (y > 35 && y < 65) {
if (x > 7 && x < 77) BWtemp = 1;
if (x > 87 && x < 157) BWtemp = 2;
@@ -177,26 +177,26 @@ void doTouchEvent(uint16_t x, uint16_t y) {
return;
}
if (!BWtune && !menu && !advancedRDS && !seek && !afscreen) { // Normal radio mode
if (x > 0 && x < 320 && y > 180 && y < 240 && band < BAND_GAP) { // -----------------
if (!BWtune && !menu && !advancedRDS && !seek && !afscreen) {
if (x > 0 && x < 320 && y > 180 && y < 240 && band < BAND_GAP) {
leave = true;
BuildAdvancedRDS(); // Switch to Advanced RDS View
BuildAdvancedRDS();
return;
} else if (x > 60 && x < 240 && y > 40 && y < 100) {
doBandToggle(); // Toggle bands
doBandToggle();
return;
} else if (x > 0 && x < 30 && y > 25 && y < 90) {
doTuneMode(); // Toggle tune mode
doTuneMode();
return;
} else if (x > 250 && x < 320 && y > 50 && y < 80) {
toggleiMSEQ(); // Toggle iMQ/EQ
toggleiMSEQ();
}
}
if (!BWtune && !menu && advancedRDS && !seek && !afscreen) { // Advanced RDS mode
if (x > 0 && x < 320 && y > 120 && y < 170) { // -----------------
if (!BWtune && !menu && advancedRDS && !seek && !afscreen) {
if (x > 0 && x < 320 && y > 120 && y < 170) {
leave = true;
BuildDisplay(); // Switch to normal radio view
BuildDisplay();
SelectBand();
return;
} else if (x > 0 && x < 320 && y > 180 && y < 240) {

View File

@@ -1,11 +0,0 @@
This directory is intended for PlatformIO Test Runner and project tests.
Unit Testing is a software testing method by which individual units of
source code, sets of one or more MCU program modules together with associated
control data, usage procedures, and operating procedures, are tested to
determine whether they are fit for use. Unit testing finds problems early
in the development cycle.
More information about PlatformIO Unit Testing:
- https://docs.platformio.org/en/latest/advanced/unit-testing/index.html