diff --git a/TEF6686_ESP32.ino b/TEF6686_ESP32.ino index 90eefef..65fa238 100644 --- a/TEF6686_ESP32.ino +++ b/TEF6686_ESP32.ino @@ -661,7 +661,8 @@ void loop() { if (!menu && !afscreen) { - if (af && dropout) { + if (af && dropout && millis() >= aftimer + 1000) { + aftimer = millis(); frequency = radio.TestAF(); if (freqold != frequency) { ShowFreq(0); @@ -2973,21 +2974,15 @@ void ShowBattery() { } if (!wifi && batterydetect) { - float batteryV = ((float)v / 4095.0) * 2.0 * 3.3 * (1056 / 1000.0); - batteryV = constrain(batteryV, 0.0, 5.0); - if (round(batteryV * 100.0) != round(batteryVold * 100.0)) { - if (batteryoptions == BATTERY_VALUE) { - tftReplace(-1, String(batteryVold, 1) + "V", String(batteryV, 1) + "V", 279, 9, BatteryValueColor, BatteryValueColorSmooth, 16); - batteryVold = batteryV; - } else if (batteryoptions == BATTERY_PERCENT) { - float vPer = 0.0; - vPer = (batteryV - BATTERY_LOW_VALUE) / (BATTERY_FULL_VALUE - BATTERY_LOW_VALUE); - vPer = constrain(vPer, 0.0, 1.0); - vPer *= 100.0; - Serial.println(vPer); - tftReplace(-1, String(vPerold, 0) + "%", String(vPer, 0) + "%", 279, 9, BatteryValueColor, BatteryValueColorSmooth, 16); - vPerold = vPer; - } + float batteryV = constrain((((float)v / 4095.0) * 3.3 * (1100 / 1000.0) * 2.0), 0.0, 5.0); + float vPer = constrain((batteryV - BATTERY_LOW_VALUE) / (BATTERY_FULL_VALUE - BATTERY_LOW_VALUE), 0.0, 1.0) * 100; + + if (abs(batteryV - batteryVold) > 0.05 && batteryoptions == BATTERY_VALUE) { + tftReplace(-1, String(batteryVold, 1) + "V", String(batteryV, 1) + "V", 279, 9, BatteryValueColor, BatteryValueColorSmooth, 16); + batteryVold = batteryV; + } else if (int(vPer) != int(vPerold) && batteryoptions == BATTERY_PERCENT && abs(vPer - vPerold) > 0.5) { + tftReplace(-1, String(vPerold, 0) + "%", String(vPer, 0) + "%", 279, 9, BatteryValueColor, BatteryValueColorSmooth, 16); + vPerold = vPer; } } } diff --git a/src/gui.cpp b/src/gui.cpp index eab22bf..252823c 100644 --- a/src/gui.cpp +++ b/src/gui.cpp @@ -341,6 +341,8 @@ void BuildAFScreen() { SStatusold = 2000; rssiold = 2000; batteryold = 6; + batteryVold = 0; + vPerold = 0; af_counterold = 254; strcpy(radioIdPrevious, "0"); programServicePrevious = "0"; @@ -602,6 +604,8 @@ void BuildAdvancedRDS() { rssiold = 2000; rdsblockold = 33; batteryold = 6; + batteryVold = 0; + vPerold = 0; strcpy(programTypePrevious, "0"); strcpy(radioIdPrevious, "0"); @@ -743,6 +747,7 @@ void BuildDisplay() { af_counterold = 254; batteryold = 6; batteryVold = 0; + vPerold = 0; strcpy(programTypePrevious, "0"); strcpy(radioIdPrevious, "0"); programServicePrevious = "0"; diff --git a/src/gui.h b/src/gui.h index e93b9f1..bbd8555 100644 --- a/src/gui.h +++ b/src/gui.h @@ -107,6 +107,7 @@ extern byte unit; extern char programTypePrevious[18]; extern char radioIdPrevious[6]; extern float batteryVold; +extern float vPerold; extern int ActiveColor; extern int ActiveColorSmooth; extern int AMLevelOffset;