Battery indicator optimised

This commit is contained in:
Sjef Verhoeven PE5PVB
2023-08-04 21:01:17 +02:00
parent 1e78088dc0
commit 2ad43d12fb
3 changed files with 44 additions and 49 deletions
+14 -21
View File
@@ -163,6 +163,7 @@ char buff[16];
char programTypePrevious[18];
char radioIdPrevious[6];
const uint8_t* currentFont = nullptr;
float vPerold;
int ActiveColor;
int ActiveColorSmooth;
int AGC;
@@ -226,10 +227,7 @@ int16_t SStatus;
int8_t LevelOffset;
int8_t LowLevelSet;
int8_t VolSet;
int vref = 1056;
float batteryV;
float batteryVold;
float batteryPold;
IPAddress remoteip;
String afstringold;
String cryptedpassword;
@@ -3543,6 +3541,7 @@ void ShowRSSI() {
}
void ShowBattery() {
if (!wifi) {
if (millis() >= batupdatetimer + TIMER_BAT_TIMER) {
batupdatetimer = millis();
} else {
@@ -3573,28 +3572,22 @@ void ShowBattery() {
batteryold = battery;
}
if (!advancedRDS && !afscreen) {
if (batteryoptions > BATTERY_NONE) {
batteryV = ((float)v / 4095.0) * 2.0 * 3.3 * (vref / 1000.0);
if (batteryoptions == BATTERY_VALUE) {
if (batteryV < BATTERY_LOW_VALUE) return;
tftPrint(-1, String(batteryVold, 1), 213, 163, BackgroundColor, BackgroundColor, FONT16);
tftPrint(-1, String(batteryV, 1), 213, 163, BatteryValueColor, BatteryValueColorSmooth, FONT16);
tftPrint(-1, "V", 232, 163, BatteryValueColor, BatteryValueColorSmooth, FONT16);
if (!advancedRDS && !afscreen && 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)) {
batteryVold = batteryV;
if (batteryoptions == BATTERY_VALUE) {
tftReplace(-1, String(batteryVold, 1) + "V", String(batteryV, 1) + "V", 213, 163, BatteryValueColor, BatteryValueColorSmooth, FONT16);
} else if (batteryoptions == BATTERY_PERCENT) {
float vPer = 0.0;
vPer = (batteryPold - BATTERY_LOW_VALUE) / (BATTERY_FULL_VALUE - BATTERY_LOW_VALUE);
if (vPer >= 1) vPer = 1;
tftPrint(-1, String(vPer * 100, 0), 213, 163, BackgroundColor, BackgroundColor, FONT16);
vPer = (batteryV - BATTERY_LOW_VALUE) / (BATTERY_FULL_VALUE - BATTERY_LOW_VALUE);
if (vPer >= 1) vPer = 1;
tftPrint(-1, String(vPer * 100, 0), 213, 163, BatteryValueColor, BatteryValueColorSmooth, FONT16);
tftPrint(-1, "%", 230, 163, BatteryValueColor, BatteryValueColorSmooth, FONT16);
batteryPold = batteryV;
vPer = constrain(vPer, 0.0, 1.0);
vPer *= 100.0;
Serial.println(vPer);
tftReplace(-1, String(vPerold, 0) + "%", String(vPer, 0) + "%", 213, 163, BatteryValueColor, BatteryValueColorSmooth, FONT16);
vPerold = vPer;
}
}
}
}
+1
View File
@@ -458,6 +458,7 @@ void BuildDisplay() {
SNRold = 254;
af_counterold = 254;
batteryold = 6;
batteryVold = 0;
strcpy(programTypePrevious, "0");
strcpy(radioIdPrevious, "0");
programServicePrevious = "0";
+1
View File
@@ -86,6 +86,7 @@ extern byte touchrotating;
extern byte unit;
extern char programTypePrevious[18];
extern char radioIdPrevious[6];
extern float batteryVold;
extern int ActiveColor;
extern int ActiveColorSmooth;
extern int AMLevelOffset;