improve tcharge error handling (#1328)

This commit is contained in:
Matthew Kennedy 2020-04-19 12:02:40 -07:00 committed by GitHub
parent 71e7fb7e50
commit fefaa54c92
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 18 additions and 5 deletions

View File

@ -37,14 +37,27 @@ baroCorr_Map3D_t baroCorrMap("baro");
// http://rusefi.com/math/t_charge.html
/***panel:Charge Temperature*/
temperature_t getTCharge(int rpm, float tps DECLARE_ENGINE_PARAMETER_SUFFIX) {
const auto [cltValid, coolantTemp] = Sensor::get(SensorType::Clt);
const auto [iatValid, airTemp] = Sensor::get(SensorType::Iat);
if (!cltValid || !iatValid) {
warning(CUSTOM_ERR_NAN_TCHARGE, "getTCharge invalid iat/clt");
const auto clt = Sensor::get(SensorType::Clt);
const auto iat = Sensor::get(SensorType::Iat);
float airTemp = 0;
// Without either valid, return 0C. It's wrong, but it'll pretend to be nice and dense, so at least you won't go lean.
if (!iat && !clt) {
return 0;
} else if (!clt && iat) {
// Intake temperature will almost always be colder (richer) than CLT - use that
return airTemp;
} else if (!iat && clt) {
// Without valid intake temperature, assume intake temp is 0C, and interpolate anyway
airTemp = 0;
} else {
// All is well - use real air temp
airTemp = iat.Value;
}
float coolantTemp = clt.Value;
DISPLAY_STATE(Engine)
if ((engine->engineState.sd.DISPLAY_IF(isTChargeAirModel) = (CONFIG(tChargeMode) == TCHARGE_MODE_AIR_INTERP))) {