diff --git a/Core/Inc/vehicle_state.h b/Core/Inc/vehicle_state.h index 38868f4..c1ede77 100644 --- a/Core/Inc/vehicle_state.h +++ b/Core/Inc/vehicle_state.h @@ -133,7 +133,8 @@ typedef struct { float min_cell_volt; float max_cell_temp; - int soc; + int soc_ts; + int soc_lv; float ts_current; float ts_voltage_bat; diff --git a/Core/Src/vehicle.c b/Core/Src/vehicle.c index dd9c46d..6d15404 100644 --- a/Core/Src/vehicle.c +++ b/Core/Src/vehicle.c @@ -85,7 +85,7 @@ void ftcan_msg_received_cb(uint16_t id, size_t datalen, const uint8_t *data) { case CAN_ID_AMS_STATUS: vehicle_state.ts_state = data[0] & 0x7F; vehicle_state.sdc_closed = (data[0] & 0x80) >> 7; - vehicle_state.soc = data[1]; + vehicle_state.soc_ts = data[1]; ptr = &data[2]; vehicle_state.min_cell_volt = ftcan_unmarshal_unsigned(&ptr, 2) * CAN_AMS_STATUS_VOLTAGE_FACTOR; @@ -123,6 +123,7 @@ void ftcan_msg_received_cb(uint16_t id, size_t datalen, const uint8_t *data) { case CAN_ID_ABX_MISC: vehicle_state.distance_total = (data[3] | (data[4] << 8)) * CAN_ABX_MISC_DISTANCE_TOTAL_FACTOR; + vehicle_state.soc_lv = data[5]; break; case CAN_ID_AS_MISSION_FB: vehicle_state.active_mission = data[0] & 0b111; diff --git a/TouchGFX/gui/src/common/NamedField.cpp b/TouchGFX/gui/src/common/NamedField.cpp index 37dbe7e..e0cd146 100644 --- a/TouchGFX/gui/src/common/NamedField.cpp +++ b/TouchGFX/gui/src/common/NamedField.cpp @@ -264,8 +264,8 @@ NamedFieldDescription dataFieldDescs[] = { VEH_FIELD(min_cell_volt)}, [DF_MaxCellTemp] = {NamedFieldKind::Float, "TBAT", 2, 1, VEH_FIELD(max_cell_temp)}, - [DF_TSSoC] = {NamedFieldKind::Int, "TSSOC", 3, 0, VEH_FIELD(soc)}, - [DF_LVSoC] = {NamedFieldKind::Float, "LVSOC", 3, 0, get_zero}, + [DF_TSSoC] = {NamedFieldKind::Int, "TSSOC", 3, 0, VEH_FIELD(soc_ts)}, + [DF_LVSoC] = {NamedFieldKind::Int, "LVSOC", 3, 0, VEH_FIELD(soc_lv)}, [DF_TSCurrent] = {NamedFieldKind::Float, "ITS", 3, 0, VEH_FIELD(ts_current)}, [DF_TSVoltageBat] = {NamedFieldKind::Float, "TSVBAT", 3, 1, diff --git a/TouchGFX/gui/src/containers/DriverViewStatusItem.cpp b/TouchGFX/gui/src/containers/DriverViewStatusItem.cpp index 425504a..0f55204 100644 --- a/TouchGFX/gui/src/containers/DriverViewStatusItem.cpp +++ b/TouchGFX/gui/src/containers/DriverViewStatusItem.cpp @@ -60,8 +60,13 @@ void DriverViewStatusItem::update() { break; case DriverViewStatusType::LV: text.setTypedText(T_LV); - // TODO: Set color based on LV SoC - bg.setColor(COLOR_OFF); + if (vehicle_state.soc_lv < 10) { + bg.setColor(COLOR_ERROR); + } else if (vehicle_state.soc_lv < 30) { + bg.setColor(COLOR_WARNING); + } else { + bg.setColor(COLOR_OK); + } break; } text.invalidate(); diff --git a/TouchGFX/gui/src/driverview_screen/DriverViewPresenter.cpp b/TouchGFX/gui/src/driverview_screen/DriverViewPresenter.cpp index 215d18f..c7de6e0 100644 --- a/TouchGFX/gui/src/driverview_screen/DriverViewPresenter.cpp +++ b/TouchGFX/gui/src/driverview_screen/DriverViewPresenter.cpp @@ -23,7 +23,7 @@ void DriverViewPresenter::deactivate() {} void DriverViewPresenter::vehicleStateUpdated() { view.setTemps(vehicle_state.temps); - view.setTSSoC(vehicle_state.soc); + view.setTSSoC(vehicle_state.soc_ts); updateProgress(); updateErrorPopup();