From 296f83ea4d2a5a9992005aa9f449c691fbf01136 Mon Sep 17 00:00:00 2001 From: rusefillc Date: Sat, 16 Oct 2021 23:17:45 -0400 Subject: [PATCH] refactoring --- .../algo/airmass/speed_density_airmass.cpp | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/firmware/controllers/algo/airmass/speed_density_airmass.cpp b/firmware/controllers/algo/airmass/speed_density_airmass.cpp index b4916d3145..db467d7280 100644 --- a/firmware/controllers/algo/airmass/speed_density_airmass.cpp +++ b/firmware/controllers/algo/airmass/speed_density_airmass.cpp @@ -34,13 +34,17 @@ AirmassResult SpeedDensityAirmass::getAirmass(int rpm) { } float SpeedDensityAirmass::getMap(int rpm) const { - float fallbackMap; - if (CONFIG(enableMapEstimationTableFallback)) { - // if the map estimation table is enabled, estimate map based on the TPS and RPM - fallbackMap = m_mapEstimationTable->getValue(rpm, TPS_2_BYTE_PACKING_MULT * Sensor::getOrZero(SensorType::Tps1)); + SensorResult map = Sensor::get(SensorType::Map); + if (map) { + return map.Value; } else { - fallbackMap = CONFIG(failedMapFallback); - } + float fallbackMap; + if (CONFIG(enableMapEstimationTableFallback)) { + // if the map estimation table is enabled, estimate map based on the TPS and RPM + fallbackMap = m_mapEstimationTable->getValue(rpm, TPS_2_BYTE_PACKING_MULT * Sensor::getOrZero(SensorType::Tps1)); + } else { + fallbackMap = CONFIG(failedMapFallback); + } #if EFI_TUNER_STUDIO if (CONFIG(debugMode) == DBG_MAP) { @@ -48,5 +52,6 @@ float SpeedDensityAirmass::getMap(int rpm) const { } #endif // EFI_TUNER_STUDIO - return Sensor::get(SensorType::Map).value_or(fallbackMap); + return fallbackMap; + } }