Fix negative value handling

This commit is contained in:
Daniel 2023-12-30 10:45:53 +02:00
parent 81df81acef
commit 5ba2a20f4e

View file

@ -126,7 +126,7 @@ String processor(const String& var) {
content += "</style>";
// Start a new block with a specific background color
content += "<div style='background-color: #303E47; padding: 10px; margin-bottom: 10px;'>";
content += "<div style='background-color: #303E47; padding: 10px; margin-bottom: 10px;border-radius: 50px'>";
// Display LED color
content += "<h4>LED color: ";
@ -159,7 +159,7 @@ String processor(const String& var) {
content += "</div>";
// Start a new block with a specific background color
content += "<div style='background-color: #2D3F2F; padding: 10px; margin-bottom: 10px;'>";
content += "<div style='background-color: #2D3F2F; padding: 10px; margin-bottom: 10px; border-radius: 50px'>";
// Display which components are used
content += "<h4 style='color: white;'>Inverter protocol: ";
@ -216,16 +216,35 @@ String processor(const String& var) {
content += "</div>";
// Start a new block with a specific background color
content += "<div style='background-color: #333; padding: 10px; margin-bottom: 10px;'>";
content += "<div style='background-color: #333; padding: 10px; margin-bottom: 10px; border-radius: 50px'>";
// Display battery statistics within this block
float socFloat = static_cast<float>(SOC) / 100.0; // Convert to float and divide by 100
float sohFloat = static_cast<float>(StateOfHealth) / 100.0; // Convert to float and divide by 100
float voltageFloat = static_cast<float>(battery_voltage) / 10.0; // Convert to float and divide by 10
float tempMaxFloat = static_cast<float>(temperature_max) / 10.0; // Convert to float and divide by 10
float tempMinFloat = static_cast<float>(temperature_min) / 10.0; // Convert to float and divide by 10
float currentFloat = 0;
if (battery_current > 32767) { //Handle negative values on this unsigned value
currentFloat = static_cast<float>(-(65535 - battery_current)) / 10.0; // Convert to float and divide by 10
} else {
currentFloat = static_cast<float>(battery_current) / 10.0; // Convert to float and divide by 10
}
float tempMaxFloat = 0;
float tempMinFloat = 0;
if (temperature_max > 32767) { //Handle negative values on this unsigned value
tempMaxFloat = static_cast<float>(-(65535 - temperature_max)) / 10.0; // Convert to float and divide by 10
} else {
tempMaxFloat = static_cast<float>(temperature_max) / 10.0; // Convert to float and divide by 10
}
if (temperature_min > 32767) { //Handle negative values on this unsigned value
tempMinFloat = static_cast<float>(-(65535 - temperature_min)) / 10.0; // Convert to float and divide by 10
} else {
tempMinFloat = static_cast<float>(temperature_min) / 10.0; // Convert to float and divide by 10
}
char socString[10];
char sohString[10];
char currentString[10];
char voltageString[10];
char tempMaxString[10];
char tempMinString[10];
@ -234,13 +253,14 @@ String processor(const String& var) {
dtostrf(socFloat, 6, 2, socString);
dtostrf(sohFloat, 6, 2, sohString);
dtostrf(voltageFloat, 6, 1, voltageString);
dtostrf(currentFloat, 6, 1, currentString);
dtostrf(tempMaxFloat, 6, 1, tempMaxString);
dtostrf(tempMinFloat, 6, 1, tempMinString);
content += "<h4 style='color: white;'>SOC: " + String(socString) + "</h4>";
content += "<h4 style='color: white;'>SOH: " + String(sohString) + "</h4>";
content += "<h4 style='color: white;'>Voltage: " + String(voltageString) + " V</h4>";
content += "<h4 style='color: white;'>Current: " + String(battery_current) + " A</h4>";
content += "<h4 style='color: white;'>Current: " + String(currentString) + " A</h4>";
content += "<h4 style='color: white;'>Power: " + String(stat_batt_power) + " W</h4>";
content += "<h4>Total capacity: " + String(capacity_Wh) + " Wh</h4>";
content += "<h4>Remaining capacity: " + String(remaining_capacity_Wh) + " Wh</h4>";