diff --git a/firmware/controllers/algo/airmass/airmass.cpp b/firmware/controllers/algo/airmass/airmass.cpp index 53710516a5..79d0f8a45b 100644 --- a/firmware/controllers/algo/airmass/airmass.cpp +++ b/firmware/controllers/algo/airmass/airmass.cpp @@ -3,7 +3,7 @@ #include "airmass.h" #include "idle_thread.h" -AirmassVeModelBase::AirmassVeModelBase(const ValueProvider3D& veTable) : m_veTable(&veTable) {} +AirmassVeModelBase::AirmassVeModelBase(const ValueProvider3D* veTable) : m_veTable(veTable) {} static float getVeLoadAxis(ve_override_e mode, float passedLoad) { switch(mode) { @@ -20,7 +20,7 @@ float AirmassVeModelBase::getVe(float rpm, float load, bool postState) const { // Override the load value if necessary load = getVeLoadAxis(engineConfiguration->veOverrideMode, load); - percent_t ve = m_veTable->getValue(rpm, load); + percent_t ve = m_veTable ? m_veTable->getValue(rpm, load) : getVeImpl(rpm, load); #if EFI_IDLE_CONTROL auto tps = Sensor::get(SensorType::Tps1); diff --git a/firmware/controllers/algo/airmass/airmass.h b/firmware/controllers/algo/airmass/airmass.h index 0bb1add5a5..9001b0ac79 100644 --- a/firmware/controllers/algo/airmass/airmass.h +++ b/firmware/controllers/algo/airmass/airmass.h @@ -14,11 +14,13 @@ struct AirmassModelBase { class AirmassVeModelBase : public AirmassModelBase { public: - explicit AirmassVeModelBase(const ValueProvider3D& veTable); + explicit AirmassVeModelBase(const ValueProvider3D* veTable); // Retrieve the user-calibrated volumetric efficiency from the table float getVe(float rpm, percent_t load, bool postState) const; + virtual float getVeImpl(float /*rpm*/, percent_t /*load*/) const { return 0.0f; } + private: const ValueProvider3D* const m_veTable; }; diff --git a/firmware/controllers/algo/airmass/alphan_airmass.h b/firmware/controllers/algo/airmass/alphan_airmass.h index 027d1d3146..e015443942 100644 --- a/firmware/controllers/algo/airmass/alphan_airmass.h +++ b/firmware/controllers/algo/airmass/alphan_airmass.h @@ -4,7 +4,7 @@ class AlphaNAirmass : public SpeedDensityBase { public: - explicit AlphaNAirmass(const ValueProvider3D& veTable) : SpeedDensityBase(veTable) {} + explicit AlphaNAirmass(const ValueProvider3D* veTable) : SpeedDensityBase(veTable) {} AirmassResult getAirmass(float rpm, bool postState) override; }; diff --git a/firmware/controllers/algo/airmass/maf_airmass.h b/firmware/controllers/algo/airmass/maf_airmass.h index 599016ea45..29fa754b45 100644 --- a/firmware/controllers/algo/airmass/maf_airmass.h +++ b/firmware/controllers/algo/airmass/maf_airmass.h @@ -4,7 +4,7 @@ class MafAirmass final : public AirmassVeModelBase { public: - explicit MafAirmass(const ValueProvider3D& veTable) : AirmassVeModelBase(veTable) {} + explicit MafAirmass(const ValueProvider3D* veTable = nullptr) : AirmassVeModelBase(veTable) {} AirmassResult getAirmass(float rpm, bool postState) override; diff --git a/firmware/controllers/algo/airmass/speed_density_airmass.h b/firmware/controllers/algo/airmass/speed_density_airmass.h index c75c1052ff..d18b8f6b67 100644 --- a/firmware/controllers/algo/airmass/speed_density_airmass.h +++ b/firmware/controllers/algo/airmass/speed_density_airmass.h @@ -4,7 +4,7 @@ class SpeedDensityAirmass : public SpeedDensityBase { public: - explicit SpeedDensityAirmass(const ValueProvider3D& veTable, const ValueProvider3D& mapEstimationTable) + explicit SpeedDensityAirmass(const ValueProvider3D* veTable, const ValueProvider3D& mapEstimationTable) : SpeedDensityBase(veTable) , m_mapEstimationTable(&mapEstimationTable) {} diff --git a/firmware/controllers/algo/airmass/speed_density_base.h b/firmware/controllers/algo/airmass/speed_density_base.h index c41dfd31e3..5346c4eec3 100644 --- a/firmware/controllers/algo/airmass/speed_density_base.h +++ b/firmware/controllers/algo/airmass/speed_density_base.h @@ -18,7 +18,7 @@ mass_t idealGasLaw(float volume, float pressure, float temperature); class SpeedDensityBase : public AirmassVeModelBase { protected: - explicit SpeedDensityBase(const ValueProvider3D& veTable) : AirmassVeModelBase(veTable) {} + explicit SpeedDensityBase(const ValueProvider3D* veTable) : AirmassVeModelBase(veTable) {} public: static mass_t getAirmassImpl(float ve, float manifoldPressure, float temperature); diff --git a/firmware/controllers/algo/fuel_math.cpp b/firmware/controllers/algo/fuel_math.cpp index 1d9a1ec39b..866581afc9 100644 --- a/firmware/controllers/algo/fuel_math.cpp +++ b/firmware/controllers/algo/fuel_math.cpp @@ -141,9 +141,9 @@ float getRunningFuel(float baseFuel) { return runningFuel; } -static SpeedDensityAirmass sdAirmass(veMap, mapEstimationTable); -static MafAirmass mafAirmass(veMap); -static AlphaNAirmass alphaNAirmass(veMap); +static SpeedDensityAirmass sdAirmass(&veMap, mapEstimationTable); +static MafAirmass mafAirmass(&veMap); +static AlphaNAirmass alphaNAirmass(&veMap); AirmassModelBase* getAirmassModel(engine_load_mode_e mode) { switch (mode) { diff --git a/unit_tests/mocks.cpp b/unit_tests/mocks.cpp index 7ec72a1a0f..fdad1cd67a 100644 --- a/unit_tests/mocks.cpp +++ b/unit_tests/mocks.cpp @@ -24,7 +24,7 @@ MockOutputPin::~MockOutputPin() { } MockExecutor::MockExecutor() { } MockExecutor::~MockExecutor() { } -MockAirmass::MockAirmass() : AirmassVeModelBase(veTable) { } +MockAirmass::MockAirmass() : AirmassVeModelBase(&veTable) { } MockAirmass::~MockAirmass() { } MockInjectorModel2::MockInjectorModel2() { } diff --git a/unit_tests/tests/ignition_injection/test_fuel_math.cpp b/unit_tests/tests/ignition_injection/test_fuel_math.cpp index 161bc909cd..c5b245ac91 100644 --- a/unit_tests/tests/ignition_injection/test_fuel_math.cpp +++ b/unit_tests/tests/ignition_injection/test_fuel_math.cpp @@ -143,7 +143,7 @@ TEST(AirmassModes, VeOverride) { } struct DummyAirmassModel : public AirmassVeModelBase { - DummyAirmassModel(const ValueProvider3D& veTable) : AirmassVeModelBase(veTable) {} + DummyAirmassModel(const ValueProvider3D* veTable) : AirmassVeModelBase(veTable) {} AirmassResult getAirmass(float rpm, bool postState) override { // Default load value 10, will be overriden @@ -154,7 +154,7 @@ TEST(AirmassModes, VeOverride) { }; EngineTestHelper eth(engine_type_e::TEST_ENGINE); - DummyAirmassModel dut(veTable); + DummyAirmassModel dut(&veTable); // Use default mode - will call with 10 dut.getAirmass(0, true);