diff --git a/firmware/console/binary/tunerstudio.cpp b/firmware/console/binary/tunerstudio.cpp index ebe0970982..b05a22c134 100644 --- a/firmware/console/binary/tunerstudio.cpp +++ b/firmware/console/binary/tunerstudio.cpp @@ -276,7 +276,7 @@ static const void * getStructAddr(int structId) { case LDS_ENGINE_STATE_INDEX: return static_cast(&engine->engineState); case LDS_FUEL_TRIM_STATE_INDEX: - return static_cast(&engine->wallFuel[0]); + return static_cast(&engine->injectionEvents.elements[0].wallFuel); case LDS_TRIGGER_CENTRAL_STATE_INDEX: return static_cast(&engine->triggerCentral); case LDS_TRIGGER_STATE_STATE_INDEX: diff --git a/firmware/console/status_loop.cpp b/firmware/console/status_loop.cpp index 0b678d1985..c6539cd435 100644 --- a/firmware/console/status_loop.cpp +++ b/firmware/console/status_loop.cpp @@ -562,11 +562,13 @@ void updateTunerStudioState(TunerStudioOutputChannels *tsOutputChannels DECLARE_ // 148 tsOutputChannels->fuelTankLevel = engine->sensors.fuelTankLevel; // 160 - tsOutputChannels->wallFuelAmount = ENGINE(wallFuel[0]).getWallFuel(); + const auto& wallFuel = ENGINE(injectionEvents.elements[0].wallFuel); + tsOutputChannels->wallFuelAmount = wallFuel.getWallFuel(); + // 168 + tsOutputChannels->wallFuelCorrection = wallFuel.wallFuelCorrection; + // 164 tsOutputChannels->iatCorrection = ENGINE(engineState.running.intakeTemperatureCoefficient); - // 168 - tsOutputChannels->wallFuelCorrection = ENGINE(wallFuel[0]).wallFuelCorrection; // 184 tsOutputChannels->cltCorrection = ENGINE(engineState.running.coolantTemperatureCoefficient); // 188 diff --git a/firmware/controllers/algo/engine.h b/firmware/controllers/algo/engine.h index 8614e2580b..6ec879af4e 100644 --- a/firmware/controllers/algo/engine.h +++ b/firmware/controllers/algo/engine.h @@ -140,7 +140,6 @@ public: IgnitionEventList ignitionEvents; #endif /* EFI_ENGINE_CONTROL */ - WallFuel wallFuel[INJECTION_PIN_COUNT]; bool needToStopEngine(efitick_t nowNt) const; bool etbAutoTune = false; /** diff --git a/firmware/controllers/algo/event_registry.h b/firmware/controllers/algo/event_registry.h index 0284b7d9c6..6c1ec660b5 100644 --- a/firmware/controllers/algo/event_registry.h +++ b/firmware/controllers/algo/event_registry.h @@ -12,6 +12,7 @@ #include "scheduler.h" #include "fl_stack.h" #include "trigger_structure.h" +#include "accel_enrichment.h" #define MAX_INJECTION_OUTPUT_COUNT INJECTION_PIN_COUNT #define MAX_WIRES_COUNT 2 @@ -42,6 +43,8 @@ public: * TODO: make watchdog decrement relevant counter */ bool isScheduled = false; + + WallFuel wallFuel; }; diff --git a/firmware/controllers/engine_controller.cpp b/firmware/controllers/engine_controller.cpp index 6246a560b1..3d60580522 100644 --- a/firmware/controllers/engine_controller.cpp +++ b/firmware/controllers/engine_controller.cpp @@ -208,9 +208,9 @@ static void resetAccel(void) { engine->engineLoadAccelEnrichment.resetAE(); engine->tpsAccelEnrichment.resetAE(); - for (unsigned int i = 0; i < sizeof(engine->wallFuel) / sizeof(engine->wallFuel[0]); i++) + for (unsigned int i = 0; i < efi::size(engine->injectionEvents.elements); i++) { - engine->wallFuel[i].resetWF(); + engine->injectionEvents.elements[i].wallFuel.resetWF(); } } diff --git a/firmware/controllers/engine_cycle/main_trigger_callback.cpp b/firmware/controllers/engine_cycle/main_trigger_callback.cpp index 1877f312f0..bcbcfd044a 100644 --- a/firmware/controllers/engine_cycle/main_trigger_callback.cpp +++ b/firmware/controllers/engine_cycle/main_trigger_callback.cpp @@ -188,8 +188,7 @@ void handleFuelInjectionEvent(int injEventIndex, InjectionEvent *event, * x2 or /2? */ - size_t injectorIndex = event->outputs[0]->injectorIndex; - const floatms_t injectionDuration = ENGINE(wallFuel[injectorIndex]).adjust(ENGINE(injectionDuration) PASS_ENGINE_PARAMETER_SUFFIX); + const floatms_t injectionDuration = event->wallFuel.adjust(ENGINE(injectionDuration) PASS_ENGINE_PARAMETER_SUFFIX); #if EFI_PRINTF_FUEL_DETAILS if (printFuelDebug) { printf("fuel index=%d injectionDuration=%.2fms adjusted=%.2fms\n", diff --git a/unit_tests/tests/test_fuel_wall_wetting.cpp b/unit_tests/tests/test_fuel_wall_wetting.cpp index aa7e1bf548..54acc45c17 100644 --- a/unit_tests/tests/test_fuel_wall_wetting.cpp +++ b/unit_tests/tests/test_fuel_wall_wetting.cpp @@ -17,9 +17,11 @@ TEST(fuel, testWallWettingEnrichmentMath) { engine->rpmCalculator.setRpmValue(3000 PASS_ENGINE_PARAMETER_SUFFIX); + WallFuel wallFuel; + // each invocation of 'adjust' changes WallWetting internal state - ASSERT_NEAR(16.6666, ENGINE(wallFuel[0]).adjust(10.0 PASS_ENGINE_PARAMETER_SUFFIX), EPS4D); - ASSERT_NEAR(16.198, ENGINE(wallFuel[0]).adjust(10.0 PASS_ENGINE_PARAMETER_SUFFIX), EPS4D); + ASSERT_NEAR(16.6666, wallFuel.adjust(10.0 PASS_ENGINE_PARAMETER_SUFFIX), EPS4D); + ASSERT_NEAR(16.198, wallFuel.adjust(10.0 PASS_ENGINE_PARAMETER_SUFFIX), EPS4D); } TEST(fuel, testWallWettingEnrichmentScheduling) { @@ -38,11 +40,11 @@ TEST(fuel, testWallWettingEnrichmentScheduling) { int expectedInvocationCounter = 1; for (int i = 0; i < 4; i++) { - ASSERT_EQ(expectedInvocationCounter, ENGINE(wallFuel[i]).invocationCounter); + ASSERT_EQ(expectedInvocationCounter, ENGINE(injectionEvents.elements[i]).wallFuel.invocationCounter); } // Cylinder 5 doesn't exist - shouldn't have been called! - ASSERT_EQ(0, ENGINE(wallFuel[5]).invocationCounter); + ASSERT_EQ(0, ENGINE(injectionEvents.elements[5]).wallFuel.invocationCounter); eth.engine.periodicFastCallback(PASS_ENGINE_PARAMETER_SIGNATURE); eth.engine.periodicFastCallback(PASS_ENGINE_PARAMETER_SIGNATURE); @@ -50,9 +52,9 @@ TEST(fuel, testWallWettingEnrichmentScheduling) { // still same 1 per cylinder - wall wetting is NOT invoked from 'periodicFastCallback' for (int i = 0; i < 4; i++) { - ASSERT_EQ(expectedInvocationCounter, ENGINE(wallFuel[i]).invocationCounter); + ASSERT_EQ(expectedInvocationCounter, ENGINE(injectionEvents.elements[i]).wallFuel.invocationCounter); } // Cylinder 5 doesn't exist - shouldn't have been called! - ASSERT_EQ(0, ENGINE(wallFuel[5]).invocationCounter); + ASSERT_EQ(0, ENGINE(injectionEvents.elements[5]).wallFuel.invocationCounter); }