From 46b7567195cef9d2266d3bc053d74efb2464810a Mon Sep 17 00:00:00 2001 From: Matthew Kennedy Date: Mon, 20 Jul 2020 00:04:05 -0700 Subject: [PATCH 1/3] put wall wetting inside --- firmware/controllers/algo/engine.h | 1 - firmware/controllers/algo/event_registry.h | 3 +++ .../engine_cycle/main_trigger_callback.cpp | 3 +-- unit_tests/tests/test_fuel_wall_wetting.cpp | 14 ++++++++------ 4 files changed, 12 insertions(+), 9 deletions(-) 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_cycle/main_trigger_callback.cpp b/firmware/controllers/engine_cycle/main_trigger_callback.cpp index ea43db5c0d..420852ca6f 100644 --- a/firmware/controllers/engine_cycle/main_trigger_callback.cpp +++ b/firmware/controllers/engine_cycle/main_trigger_callback.cpp @@ -180,8 +180,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); } From a1d39b8de6b9249d69a3603d41d725dfd4869576 Mon Sep 17 00:00:00 2001 From: Matthew Kennedy Date: Mon, 20 Jul 2020 00:55:45 -0700 Subject: [PATCH 2/3] more spots --- firmware/console/binary/tunerstudio.cpp | 2 +- firmware/console/status_loop.cpp | 5 +++-- firmware/controllers/engine_controller.cpp | 4 ++-- 3 files changed, 6 insertions(+), 5 deletions(-) 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..6dc6995335 100644 --- a/firmware/console/status_loop.cpp +++ b/firmware/console/status_loop.cpp @@ -562,11 +562,12 @@ 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(); // 164 tsOutputChannels->iatCorrection = ENGINE(engineState.running.intakeTemperatureCoefficient); // 168 - tsOutputChannels->wallFuelCorrection = ENGINE(wallFuel[0]).wallFuelCorrection; + tsOutputChannels->wallFuelCorrection = wallFuel.wallFuelCorrection; // 184 tsOutputChannels->cltCorrection = ENGINE(engineState.running.coolantTemperatureCoefficient); // 188 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(); } } From 0f0d18afc81384f87ce9c5ad4585ea55ef897cf8 Mon Sep 17 00:00:00 2001 From: Matthew Kennedy Date: Mon, 20 Jul 2020 01:03:13 -0700 Subject: [PATCH 3/3] s --- firmware/console/status_loop.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/firmware/console/status_loop.cpp b/firmware/console/status_loop.cpp index 6dc6995335..c6539cd435 100644 --- a/firmware/console/status_loop.cpp +++ b/firmware/console/status_loop.cpp @@ -564,10 +564,11 @@ void updateTunerStudioState(TunerStudioOutputChannels *tsOutputChannels DECLARE_ // 160 const auto& wallFuel = ENGINE(injectionEvents.elements[0].wallFuel); tsOutputChannels->wallFuelAmount = wallFuel.getWallFuel(); - // 164 - tsOutputChannels->iatCorrection = ENGINE(engineState.running.intakeTemperatureCoefficient); // 168 tsOutputChannels->wallFuelCorrection = wallFuel.wallFuelCorrection; + + // 164 + tsOutputChannels->iatCorrection = ENGINE(engineState.running.intakeTemperatureCoefficient); // 184 tsOutputChannels->cltCorrection = ENGINE(engineState.running.coolantTemperatureCoefficient); // 188