diff --git a/firmware/controllers/algo/fuel_math.cpp b/firmware/controllers/algo/fuel_math.cpp index 02b2e6b88c..2eda621de7 100644 --- a/firmware/controllers/algo/fuel_math.cpp +++ b/firmware/controllers/algo/fuel_math.cpp @@ -172,16 +172,11 @@ float getInjectionDurationForAirmass(float airMass, float afr DECLARE_ENGINE_PAR static SpeedDensityAirmass sdAirmass(veMap); static MafAirmass mafAirmass(veMap); -AirmassResult getAirmass(int rpm DECLARE_ENGINE_PARAMETER_SUFFIX) { +AirmassModelBase* getAirmassModel(DECLARE_ENGINE_PARAMETER_SIGNATURE) { switch (CONFIG(fuelAlgorithm)) { - case LM_SPEED_DENSITY: - return sdAirmass.getAirmass(rpm); - //return getSpeedDensityAirmass(PASS_ENGINE_PARAMETER_SIGNATURE); - case LM_REAL_MAF: { - return mafAirmass.getAirmass(rpm); - } default: - firmwareError(CUSTOM_ERR_ASSERT, "Fuel mode %d is not airmass mode", CONFIG(fuelAlgorithm)); - return {}; + case LM_SPEED_DENSITY: return &sdAirmass; + case LM_REAL_MAF: return &mafAirmass; + default: return nullptr; } } @@ -200,13 +195,14 @@ floatms_t getBaseFuel(int rpm DECLARE_ENGINE_PARAMETER_SUFFIX) { if ((CONFIG(fuelAlgorithm) == LM_SPEED_DENSITY) || (engineConfiguration->fuelAlgorithm == LM_REAL_MAF)) { // airmass modes - get airmass first, then convert to fuel - auto airmass = getAirmass(rpm PASS_ENGINE_PARAMETER_SUFFIX); + auto model = getAirmassModel(PASS_ENGINE_PARAMETER_SIGNATURE); + efiAssert(CUSTOM_ERR_ASSERT, model != nullptr, "Invalid airmass mode", 0.0f); + + auto airmass = model->getAirmass(rpm); // The airmass mode will tell us how to look up AFR - use the provided Y axis value float targetAfr = afrMap.getValue(rpm, airmass.EngineLoadPercent); - // TODO: surface airmass.EngineLoadPercent to tunerstudio for proper display - // Plop some state for others to read ENGINE(engineState.targetAFR) = targetAfr; ENGINE(engineState.sd.airMassInOneCylinder) = airmass.CylinderAirmass;