Optmisize battery readout

- Percentage/voltage was not visible when switching to advanced RDS/AF
- Percentage value was blinking
- Corrected voltage calculation
- Optimised battery routine.
This commit is contained in:
Sjef Verhoeven PE5PVB
2023-08-09 15:01:26 +02:00
parent d32805f8bf
commit e78055ba4a
3 changed files with 17 additions and 16 deletions
+11 -16
View File
@@ -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;
}
}
}
+5
View File
@@ -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";
+1
View File
@@ -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;