mirror of
https://github.com/dalathegreat/Battery-Emulator.git
synced 2025-10-05 10:49:42 +02:00
Merge pull request #391 from dalathegreat/bugfix/imiev-temperature
Triplets: Only update values that are sane
This commit is contained in:
commit
f56c79c45e
1 changed files with 14 additions and 6 deletions
|
@ -10,7 +10,7 @@
|
||||||
//Figure out if CAN messages need to be sent to keep the system happy?
|
//Figure out if CAN messages need to be sent to keep the system happy?
|
||||||
|
|
||||||
/* Do not change code below unless you are sure what you are doing */
|
/* Do not change code below unless you are sure what you are doing */
|
||||||
#define MAX_CELL_VOLTAGE 4100
|
#define MAX_CELL_VOLTAGE 4150
|
||||||
#define MIN_CELL_VOLTAGE 2750
|
#define MIN_CELL_VOLTAGE 2750
|
||||||
static uint8_t errorCode = 0; //stores if we have an error code active from battery control logic
|
static uint8_t errorCode = 0; //stores if we have an error code active from battery control logic
|
||||||
static uint8_t BMU_Detected = 0;
|
static uint8_t BMU_Detected = 0;
|
||||||
|
@ -71,7 +71,7 @@ void update_values_battery() { //This function maps all the values fetched via
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int m = sizeof(cell_voltages) / sizeof(cell_temperatures[0]);
|
static int m = sizeof(cell_temperatures) / sizeof(cell_temperatures[0]);
|
||||||
max_temp_cel = cell_temperatures[0]; // Initialize max with the first element of the array
|
max_temp_cel = cell_temperatures[0]; // Initialize max with the first element of the array
|
||||||
for (int i = 1; i < m; i++) {
|
for (int i = 1; i < m; i++) {
|
||||||
if (cell_temperatures[i] > max_temp_cel) {
|
if (cell_temperatures[i] > max_temp_cel) {
|
||||||
|
@ -92,13 +92,21 @@ void update_values_battery() { //This function maps all the values fetched via
|
||||||
datalayer.battery.status.cell_voltages_mV[i] = (uint16_t)(cell_voltages[i] * 1000);
|
datalayer.battery.status.cell_voltages_mV[i] = (uint16_t)(cell_voltages[i] * 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
datalayer.battery.status.cell_max_voltage_mV = (uint16_t)(max_volt_cel * 1000);
|
if (max_volt_cel > 2200) { // Only update cellvoltage when we have a value
|
||||||
|
datalayer.battery.status.cell_max_voltage_mV = (uint16_t)(max_volt_cel * 1000);
|
||||||
|
}
|
||||||
|
|
||||||
datalayer.battery.status.cell_min_voltage_mV = (uint16_t)(min_volt_cel * 1000);
|
if (min_volt_cel > 2200) { // Only update cellvoltage when we have a value
|
||||||
|
datalayer.battery.status.cell_min_voltage_mV = (uint16_t)(min_volt_cel * 1000);
|
||||||
|
}
|
||||||
|
|
||||||
datalayer.battery.status.temperature_min_dC = (int16_t)(min_temp_cel * 10);
|
if (min_temp_cel > -49) { // Only update temperature when we have a value
|
||||||
|
datalayer.battery.status.temperature_min_dC = (int16_t)(min_temp_cel * 10);
|
||||||
|
}
|
||||||
|
|
||||||
datalayer.battery.status.temperature_max_dC = (int16_t)(max_temp_cel * 10);
|
if (max_temp_cel > -49) { // Only update temperature when we have a value
|
||||||
|
datalayer.battery.status.temperature_max_dC = (int16_t)(max_temp_cel * 10);
|
||||||
|
}
|
||||||
|
|
||||||
//Check safeties
|
//Check safeties
|
||||||
if (datalayer.battery.status.cell_max_voltage_mV >= MAX_CELL_VOLTAGE) {
|
if (datalayer.battery.status.cell_max_voltage_mV >= MAX_CELL_VOLTAGE) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue