Battery indicator optimised
This commit is contained in:
+42
-49
@@ -163,6 +163,7 @@ char buff[16];
|
|||||||
char programTypePrevious[18];
|
char programTypePrevious[18];
|
||||||
char radioIdPrevious[6];
|
char radioIdPrevious[6];
|
||||||
const uint8_t* currentFont = nullptr;
|
const uint8_t* currentFont = nullptr;
|
||||||
|
float vPerold;
|
||||||
int ActiveColor;
|
int ActiveColor;
|
||||||
int ActiveColorSmooth;
|
int ActiveColorSmooth;
|
||||||
int AGC;
|
int AGC;
|
||||||
@@ -226,10 +227,7 @@ int16_t SStatus;
|
|||||||
int8_t LevelOffset;
|
int8_t LevelOffset;
|
||||||
int8_t LowLevelSet;
|
int8_t LowLevelSet;
|
||||||
int8_t VolSet;
|
int8_t VolSet;
|
||||||
int vref = 1056;
|
|
||||||
float batteryV;
|
|
||||||
float batteryVold;
|
float batteryVold;
|
||||||
float batteryPold;
|
|
||||||
IPAddress remoteip;
|
IPAddress remoteip;
|
||||||
String afstringold;
|
String afstringold;
|
||||||
String cryptedpassword;
|
String cryptedpassword;
|
||||||
@@ -3543,58 +3541,53 @@ void ShowRSSI() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ShowBattery() {
|
void ShowBattery() {
|
||||||
if (millis() >= batupdatetimer + TIMER_BAT_TIMER) {
|
if (!wifi) {
|
||||||
batupdatetimer = millis();
|
if (millis() >= batupdatetimer + TIMER_BAT_TIMER) {
|
||||||
} else {
|
batupdatetimer = millis();
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint16_t v = analogRead(BATTERY_PIN);
|
|
||||||
|
|
||||||
battery = map(constrain(v, BAT_LEVEL_EMPTY, BAT_LEVEL_FULL), BAT_LEVEL_EMPTY, BAT_LEVEL_FULL, 0, BAT_LEVEL_STAGE);
|
|
||||||
if (batteryold != battery) {
|
|
||||||
if (batterydetect) {
|
|
||||||
if (battery == 0) {
|
|
||||||
tft.drawRect(300, 8, 12, 20, BarSignificantColor);
|
|
||||||
tft.fillRect(303, 4, 6, 4, BarSignificantColor);
|
|
||||||
tft.fillRect(302, 10, 8, 16, BackgroundColor);
|
|
||||||
tft.fillRect(302, 26 - (battery * 4), 8, battery * 4, BarInsignificantColor);
|
|
||||||
} else {
|
|
||||||
tft.drawRect(300, 8, 12, 20, ActiveColor);
|
|
||||||
tft.fillRect(303, 4, 6, 4, ActiveColor);
|
|
||||||
tft.fillRect(302, 10, 8, 16, BackgroundColor);
|
|
||||||
tft.fillRect(302, 26 - (battery * 4), 8, battery * 4, BarInsignificantColor);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
tft.drawRect(300, 8, 12, 20, GreyoutColor);
|
return;
|
||||||
tft.fillRect(303, 4, 6, 4, GreyoutColor);
|
|
||||||
tft.fillRect(302, 10, 8, 16, BackgroundColor);
|
|
||||||
}
|
}
|
||||||
batteryold = battery;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!advancedRDS && !afscreen) {
|
uint16_t v = analogRead(BATTERY_PIN);
|
||||||
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);
|
battery = map(constrain(v, BAT_LEVEL_EMPTY, BAT_LEVEL_FULL), BAT_LEVEL_EMPTY, BAT_LEVEL_FULL, 0, BAT_LEVEL_STAGE);
|
||||||
|
if (batteryold != battery) {
|
||||||
|
if (batterydetect) {
|
||||||
|
if (battery == 0) {
|
||||||
|
tft.drawRect(300, 8, 12, 20, BarSignificantColor);
|
||||||
|
tft.fillRect(303, 4, 6, 4, BarSignificantColor);
|
||||||
|
tft.fillRect(302, 10, 8, 16, BackgroundColor);
|
||||||
|
tft.fillRect(302, 26 - (battery * 4), 8, battery * 4, BarInsignificantColor);
|
||||||
|
} else {
|
||||||
|
tft.drawRect(300, 8, 12, 20, ActiveColor);
|
||||||
|
tft.fillRect(303, 4, 6, 4, ActiveColor);
|
||||||
|
tft.fillRect(302, 10, 8, 16, BackgroundColor);
|
||||||
|
tft.fillRect(302, 26 - (battery * 4), 8, battery * 4, BarInsignificantColor);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
tft.drawRect(300, 8, 12, 20, GreyoutColor);
|
||||||
|
tft.fillRect(303, 4, 6, 4, GreyoutColor);
|
||||||
|
tft.fillRect(302, 10, 8, 16, BackgroundColor);
|
||||||
|
}
|
||||||
|
batteryold = battery;
|
||||||
|
}
|
||||||
|
|
||||||
tftPrint(-1, String(batteryV, 1), 213, 163, BatteryValueColor, BatteryValueColorSmooth, FONT16);
|
if (!advancedRDS && !afscreen && batterydetect) {
|
||||||
tftPrint(-1, "V", 232, 163, BatteryValueColor, BatteryValueColorSmooth, FONT16);
|
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;
|
batteryVold = batteryV;
|
||||||
} else if (batteryoptions == BATTERY_PERCENT) {
|
if (batteryoptions == BATTERY_VALUE) {
|
||||||
float vPer = 0.0;
|
tftReplace(-1, String(batteryVold, 1) + "V", String(batteryV, 1) + "V", 213, 163, BatteryValueColor, BatteryValueColorSmooth, FONT16);
|
||||||
vPer = (batteryPold - BATTERY_LOW_VALUE) / (BATTERY_FULL_VALUE - BATTERY_LOW_VALUE);
|
} else if (batteryoptions == BATTERY_PERCENT) {
|
||||||
if (vPer >= 1) vPer = 1;
|
float vPer = 0.0;
|
||||||
tftPrint(-1, String(vPer * 100, 0), 213, 163, BackgroundColor, BackgroundColor, FONT16);
|
vPer = (batteryV - BATTERY_LOW_VALUE) / (BATTERY_FULL_VALUE - BATTERY_LOW_VALUE);
|
||||||
|
vPer = constrain(vPer, 0.0, 1.0);
|
||||||
vPer = (batteryV - BATTERY_LOW_VALUE) / (BATTERY_FULL_VALUE - BATTERY_LOW_VALUE);
|
vPer *= 100.0;
|
||||||
if (vPer >= 1) vPer = 1;
|
Serial.println(vPer);
|
||||||
tftPrint(-1, String(vPer * 100, 0), 213, 163, BatteryValueColor, BatteryValueColorSmooth, FONT16);
|
tftReplace(-1, String(vPerold, 0) + "%", String(vPer, 0) + "%", 213, 163, BatteryValueColor, BatteryValueColorSmooth, FONT16);
|
||||||
tftPrint(-1, "%", 230, 163, BatteryValueColor, BatteryValueColorSmooth, FONT16);
|
vPerold = vPer;
|
||||||
batteryPold = batteryV;
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -458,6 +458,7 @@ void BuildDisplay() {
|
|||||||
SNRold = 254;
|
SNRold = 254;
|
||||||
af_counterold = 254;
|
af_counterold = 254;
|
||||||
batteryold = 6;
|
batteryold = 6;
|
||||||
|
batteryVold = 0;
|
||||||
strcpy(programTypePrevious, "0");
|
strcpy(programTypePrevious, "0");
|
||||||
strcpy(radioIdPrevious, "0");
|
strcpy(radioIdPrevious, "0");
|
||||||
programServicePrevious = "0";
|
programServicePrevious = "0";
|
||||||
|
|||||||
@@ -86,6 +86,7 @@ extern byte touchrotating;
|
|||||||
extern byte unit;
|
extern byte unit;
|
||||||
extern char programTypePrevious[18];
|
extern char programTypePrevious[18];
|
||||||
extern char radioIdPrevious[6];
|
extern char radioIdPrevious[6];
|
||||||
|
extern float batteryVold;
|
||||||
extern int ActiveColor;
|
extern int ActiveColor;
|
||||||
extern int ActiveColorSmooth;
|
extern int ActiveColorSmooth;
|
||||||
extern int AMLevelOffset;
|
extern int AMLevelOffset;
|
||||||
|
|||||||
Reference in New Issue
Block a user