From 7f0e07d9c7f24928bf6c36014e083c84d42a41b7 Mon Sep 17 00:00:00 2001 From: Matthew Kennedy Date: Sat, 18 Apr 2020 12:53:04 -0700 Subject: [PATCH] new clt/iat: OBD and CAN dash (#1317) * corrections * CAN consumers * can consume * obd, lcd * Revert "corrections" This reverts commit 0003b270ce8344f7eefe7dbb87a9de7cffc5b8a8. * iat --- firmware/controllers/can/can_dash.cpp | 22 ++++++++++++------- firmware/controllers/can/can_verbose.cpp | 4 ++-- firmware/controllers/can/obd2.cpp | 4 ++-- firmware/controllers/core/fsio_impl.cpp | 2 +- .../controllers/gauges/lcd_controller.cpp | 2 +- 5 files changed, 20 insertions(+), 14 deletions(-) diff --git a/firmware/controllers/can/can_dash.cpp b/firmware/controllers/can/can_dash.cpp index c9c418e310..955f3e6fc7 100644 --- a/firmware/controllers/can/can_dash.cpp +++ b/firmware/controllers/can/can_dash.cpp @@ -14,6 +14,7 @@ #include "can_dash.h" #include "can_msg_tx.h" +#include "sensor.h" #include "allsensors.h" #include "vehicle_speed.h" @@ -63,7 +64,7 @@ void canDashboardBMW(void) { { CanTxMessage msg(CAN_BMW_E46_DME2); - msg.setShortValue((int) ((getCoolantTemperature() + 48.373) / 0.75), 1); + msg.setShortValue((int) ((Sensor::get(SensorType::Clt).value_or(0) + 48.373) / 0.75), 1); } } @@ -98,7 +99,8 @@ void canMazdaRX8(void) { { CanTxMessage msg(CAN_MAZDA_RX_STATUS_2); - msg[0] = (uint8_t)(getCoolantTemperature() + 69); //temp gauge //~170 is red, ~165 last bar, 152 centre, 90 first bar, 92 second bar + auto clt = Sensor::get(SensorType::Clt); + msg[0] = (uint8_t)(clt.value_or(0) + 69); //temp gauge //~170 is red, ~165 last bar, 152 centre, 90 first bar, 92 second bar msg[1] = ((int16_t)(engine->engineState.vssEventCounter*(engineConfiguration->vehicleSpeedCoef*0.277*2.58))) & 0xff; msg[2] = 0x00; // unknown msg[3] = 0x00; //unknown @@ -108,8 +110,10 @@ void canMazdaRX8(void) { if ((GET_RPM()>0) && (engine->sensors.vBatt<13)) { msg.setBit(6, 6); // battery light } - if (getCoolantTemperature() > 105) { - msg.setBit(6, 1); // coolant light, 101 - red zone, light means its get too hot + if (!clt.Valid || clt.Value > 105) { + // coolant light, 101 - red zone, light means its get too hot + // Also turn on the light in case of sensor failure + msg.setBit(6, 1); } //oil pressure warning lamp bit is 7 msg[7] = 0x00; //unused @@ -120,7 +124,7 @@ void canDashboardFiat(void) { { //Fiat Dashboard CanTxMessage msg(CAN_FIAT_MOTOR_INFO); - msg.setShortValue((int) (getCoolantTemperature() - 40), 3); //Coolant Temp + msg.setShortValue((int) (Sensor::get(SensorType::Clt).value_or(0) - 40), 3); //Coolant Temp msg.setShortValue(GET_RPM() / 32, 6); //RPM } } @@ -132,14 +136,16 @@ void canDashboardVAG(void) { msg.setShortValue(GET_RPM() * 4, 2); //RPM } + float clt = Sensor::get(SensorType::Clt).value_or(0); + { CanTxMessage msg(CAN_VAG_CLT); - msg.setShortValue((int) ((getCoolantTemperature() + 48.373) / 0.75), 1); //Coolant Temp + msg.setShortValue((int) ((clt + 48.373) / 0.75), 1); //Coolant Temp } { CanTxMessage msg(CAN_VAG_CLT_V2); - msg.setShortValue((int) ((getCoolantTemperature() + 48.373) / 0.75), 4); //Coolant Temp + msg.setShortValue((int) ((clt + 48.373) / 0.75), 4); //Coolant Temp } { @@ -163,7 +169,7 @@ void canDashboardW202(void) { { CanTxMessage msg(W202_STAT_2); //dlc 7 - msg[0] = (int)(getCoolantTemperature()+40); // CLT - 0x80 ~ 80C + msg[0] = (int)(Sensor::get(SensorType::Clt).value_or(0) + 40); // CLT - 0x80 ~ 80C msg[1] = 0x3D; // TBD msg[2] = 0x63; // Const msg[3] = 0x41; // Const diff --git a/firmware/controllers/can/can_verbose.cpp b/firmware/controllers/can/can_verbose.cpp index 627671e5a6..de82bbc82a 100644 --- a/firmware/controllers/can/can_verbose.cpp +++ b/firmware/controllers/can/can_verbose.cpp @@ -99,8 +99,8 @@ struct Sensors1 { static void populateFrame(Sensors1& msg) { msg.map = getMap(); - msg.clt = getCoolantTemperature() + PACK_ADD_TEMPERATURE; - msg.iat = getIntakeAirTemperature() + PACK_ADD_TEMPERATURE; + msg.clt = Sensor::get(SensorType::Clt).value_or(0) + PACK_ADD_TEMPERATURE; + msg.iat = Sensor::get(SensorType::Iat).value_or(0) + PACK_ADD_TEMPERATURE; // todo: does aux temp even work? msg.aux1 = 0 + PACK_ADD_TEMPERATURE; diff --git a/firmware/controllers/can/obd2.cpp b/firmware/controllers/can/obd2.cpp index d7d88042b5..e9446a098a 100644 --- a/firmware/controllers/can/obd2.cpp +++ b/firmware/controllers/can/obd2.cpp @@ -136,7 +136,7 @@ static void handleGetDataRequest(const CANRxFrame& rx) { break; case PID_COOLANT_TEMP: scheduleMsg(&logger, "Got CLT request"); - obdSendValue(1, pid, 1, getCoolantTemperature() + 40.0f); + obdSendValue(1, pid, 1, Sensor::get(SensorType::Clt).value_or(0) + 40.0f); break; case PID_INTAKE_MAP: scheduleMsg(&logger, "Got MAP request"); @@ -159,7 +159,7 @@ static void handleGetDataRequest(const CANRxFrame& rx) { } case PID_INTAKE_TEMP: scheduleMsg(&logger, "Got IAT request"); - obdSendValue(1, pid, 1, getIntakeAirTemperature() + 40.0f); + obdSendValue(1, pid, 1, Sensor::get(SensorType::Iat).value_or(0) + 40.0f); break; case PID_INTAKE_MAF: scheduleMsg(&logger, "Got MAF request"); diff --git a/firmware/controllers/core/fsio_impl.cpp b/firmware/controllers/core/fsio_impl.cpp index 06652b7c11..7bf260de94 100644 --- a/firmware/controllers/core/fsio_impl.cpp +++ b/firmware/controllers/core/fsio_impl.cpp @@ -125,7 +125,7 @@ float getEngineValue(le_action_e action DECLARE_ENGINE_PARAMETER_SUFFIX) { case LE_METHOD_IS_COOLANT_BROKEN: return !Sensor::get(SensorType::Clt).Valid; case LE_METHOD_INTAKE_AIR: - return getIntakeAirTemperature(); + return Sensor::get(SensorType::Iat).value_or(0); case LE_METHOD_RPM: return engine->rpmCalculator.getRpm(); case LE_METHOD_MAF: diff --git a/firmware/controllers/gauges/lcd_controller.cpp b/firmware/controllers/gauges/lcd_controller.cpp index 7c45d9e73b..d3480fba4f 100644 --- a/firmware/controllers/gauges/lcd_controller.cpp +++ b/firmware/controllers/gauges/lcd_controller.cpp @@ -171,7 +171,7 @@ static void showLine(lcd_line_e line, int screenY) { #endif return; case LL_CLT_TEMPERATURE: - lcdPrintf("Coolant %.2f", getCoolantTemperature()); + lcdPrintf("Coolant %.2f", Sensor::get(SensorType::Clt).value_or(0)); return; case LL_IAT_TEMPERATURE: lcdPrintf("Intake Air %.2f", getIntakeAirTemperature());