mirror of
https://github.com/dalathegreat/Battery-Emulator.git
synced 2025-10-03 17:59:27 +02:00
Add color. Make memory safe
This commit is contained in:
parent
5ba2a20f4e
commit
e9aa9652ba
3 changed files with 38 additions and 28 deletions
|
@ -490,6 +490,7 @@ void handle_LED_state() {
|
||||||
|
|
||||||
// BMS in fault state overrides everything
|
// BMS in fault state overrides everything
|
||||||
if (bms_status == FAULT) {
|
if (bms_status == FAULT) {
|
||||||
|
LEDcolor = RED;
|
||||||
pixels.setPixelColor(0, pixels.Color(255, 0, 0)); // Red LED full brightness
|
pixels.setPixelColor(0, pixels.Color(255, 0, 0)); // Red LED full brightness
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -159,7 +159,7 @@ String processor(const String& var) {
|
||||||
content += "</div>";
|
content += "</div>";
|
||||||
|
|
||||||
// Start a new block with a specific background color
|
// Start a new block with a specific background color
|
||||||
content += "<div style='background-color: #2D3F2F; padding: 10px; margin-bottom: 10px; border-radius: 50px'>";
|
content += "<div style='background-color: #333; padding: 10px; margin-bottom: 10px; border-radius: 50px'>";
|
||||||
|
|
||||||
// Display which components are used
|
// Display which components are used
|
||||||
content += "<h4 style='color: white;'>Inverter protocol: ";
|
content += "<h4 style='color: white;'>Inverter protocol: ";
|
||||||
|
@ -215,8 +215,27 @@ String processor(const String& var) {
|
||||||
// Close the block
|
// Close the block
|
||||||
content += "</div>";
|
content += "</div>";
|
||||||
|
|
||||||
// Start a new block with a specific background color
|
// Start a new block with a specific background color. Color changes depending on BMS status
|
||||||
content += "<div style='background-color: #333; padding: 10px; margin-bottom: 10px; border-radius: 50px'>";
|
switch (LEDcolor) {
|
||||||
|
case GREEN:
|
||||||
|
content += "<div style='background-color: #2D3F2F; padding: 10px; margin-bottom: 10px; border-radius: 50px'>";
|
||||||
|
break;
|
||||||
|
case YELLOW:
|
||||||
|
content += "<div style='background-color: #F5CC00; padding: 10px; margin-bottom: 10px; border-radius: 50px'>";
|
||||||
|
break;
|
||||||
|
case BLUE:
|
||||||
|
content += "<div style='background-color: #2B35AF; padding: 10px; margin-bottom: 10px; border-radius: 50px'>";
|
||||||
|
break;
|
||||||
|
case RED:
|
||||||
|
content += "<div style='background-color: #A70107; padding: 10px; margin-bottom: 10px; border-radius: 50px'>";
|
||||||
|
break;
|
||||||
|
case TEST_ALL_COLORS: //Blue in test mode
|
||||||
|
content += "<div style='background-color: #2B35AF; padding: 10px; margin-bottom: 10px; border-radius: 50px'>";
|
||||||
|
break;
|
||||||
|
default: //Some new color, make background green
|
||||||
|
content += "<div style='background-color: #2D3F2F; padding: 10px; margin-bottom: 10px; border-radius: 50px'>";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
// Display battery statistics within this block
|
// Display battery statistics within this block
|
||||||
float socFloat = static_cast<float>(SOC) / 100.0; // Convert to float and divide by 100
|
float socFloat = static_cast<float>(SOC) / 100.0; // Convert to float and divide by 100
|
||||||
|
@ -228,7 +247,12 @@ String processor(const String& var) {
|
||||||
} else {
|
} else {
|
||||||
currentFloat = static_cast<float>(battery_current) / 10.0; // Convert to float and divide by 10
|
currentFloat = static_cast<float>(battery_current) / 10.0; // Convert to float and divide by 10
|
||||||
}
|
}
|
||||||
|
float powerFloat = 0;
|
||||||
|
if (stat_batt_power > 32767) { //Handle negative values on this unsigned value
|
||||||
|
powerFloat = static_cast<float>(-(65535 - stat_batt_power));
|
||||||
|
} else {
|
||||||
|
powerFloat = static_cast<float>(stat_batt_power);
|
||||||
|
}
|
||||||
float tempMaxFloat = 0;
|
float tempMaxFloat = 0;
|
||||||
float tempMinFloat = 0;
|
float tempMinFloat = 0;
|
||||||
if (temperature_max > 32767) { //Handle negative values on this unsigned value
|
if (temperature_max > 32767) { //Handle negative values on this unsigned value
|
||||||
|
@ -241,35 +265,19 @@ String processor(const String& var) {
|
||||||
} else {
|
} else {
|
||||||
tempMinFloat = static_cast<float>(temperature_min) / 10.0; // Convert to float and divide by 10
|
tempMinFloat = static_cast<float>(temperature_min) / 10.0; // Convert to float and divide by 10
|
||||||
}
|
}
|
||||||
|
content += "<h4 style='color: white;'>SOC: " + String(socFloat, 2) + "</h4>";
|
||||||
char socString[10];
|
content += "<h4 style='color: white;'>SOH: " + String(sohFloat, 2) + "</h4>";
|
||||||
char sohString[10];
|
content += "<h4 style='color: white;'>Voltage: " + String(voltageFloat, 1) + " V</h4>";
|
||||||
char currentString[10];
|
content += "<h4 style='color: white;'>Current: " + String(currentFloat, 1) + " A</h4>";
|
||||||
char voltageString[10];
|
content += "<h4 style='color: white;'>Power: " + String(powerFloat, 0) + " W</h4>";
|
||||||
char tempMaxString[10];
|
|
||||||
char tempMinString[10];
|
|
||||||
|
|
||||||
// Format decimals
|
|
||||||
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(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>Total capacity: " + String(capacity_Wh) + " Wh</h4>";
|
||||||
content += "<h4>Remaining capacity: " + String(remaining_capacity_Wh) + " Wh</h4>";
|
content += "<h4>Remaining capacity: " + String(remaining_capacity_Wh) + " Wh</h4>";
|
||||||
content += "<h4>Max discharge power: " + String(max_target_discharge_power) + " W</h4>";
|
content += "<h4>Max discharge power: " + String(max_target_discharge_power) + " W</h4>";
|
||||||
content += "<h4>Max charge power: " + String(max_target_charge_power) + " W</h4>";
|
content += "<h4>Max charge power: " + String(max_target_charge_power) + " W</h4>";
|
||||||
content += "<h4>Cell max: " + String(cell_max_voltage) + " mV</h4>";
|
content += "<h4>Cell max: " + String(cell_max_voltage) + " mV</h4>";
|
||||||
content += "<h4>Cell min: " + String(cell_min_voltage) + " mV</h4>";
|
content += "<h4>Cell min: " + String(cell_min_voltage) + " mV</h4>";
|
||||||
content += "<h4>Temperature max: " + String(tempMaxString) + " C</h4>";
|
content += "<h4>Temperature max: " + String(tempMaxFloat, 1) + " C</h4>";
|
||||||
content += "<h4>Temperature min: " + String(tempMinString) + " C</h4>";
|
content += "<h4>Temperature min: " + String(tempMinFloat, 1) + " C</h4>";
|
||||||
if (bms_status == 3) {
|
if (bms_status == 3) {
|
||||||
content += "<h4>BMS Status: OK </h4>";
|
content += "<h4>BMS Status: OK </h4>";
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -25,7 +25,8 @@ extern uint16_t temperature_max; //C+1, Goes thru convert2unsignedint16 funct
|
||||||
extern uint16_t cell_max_voltage; //mV, 0-4350
|
extern uint16_t cell_max_voltage; //mV, 0-4350
|
||||||
extern uint16_t cell_min_voltage; //mV, 0-4350
|
extern uint16_t cell_min_voltage; //mV, 0-4350
|
||||||
extern uint8_t LEDcolor; //Enum, 0-10
|
extern uint8_t LEDcolor; //Enum, 0-10
|
||||||
extern bool batteryAllowsContactorClosing; //Bool, 1=true, 0=false
|
extern bool batteryAllowsContactorClosing; //Bool, 1=true, 0=false
|
||||||
|
extern bool inverterAllowsContactorClosing; //Bool, 1=true, 0=false
|
||||||
|
|
||||||
extern const char* ssid;
|
extern const char* ssid;
|
||||||
extern const char* password;
|
extern const char* password;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue