diff --git a/firmware/controllers/engine_cycle/spark_logic.cpp b/firmware/controllers/engine_cycle/spark_logic.cpp index fecb1e6d6d..18c35b72c7 100644 --- a/firmware/controllers/engine_cycle/spark_logic.cpp +++ b/firmware/controllers/engine_cycle/spark_logic.cpp @@ -63,11 +63,13 @@ static int getIgnitionPinForIndex(int cylinderIndex, ignition_mode_e ignitionMod static void prepareCylinderIgnitionSchedule(angle_t dwellAngleDuration, floatms_t sparkDwell, IgnitionEvent *event) { // todo: clean up this implementation? does not look too nice as is. + const int realCylinderNumber = getCylinderNumberAtIndex(event->cylinderIndex); + // let's save planned duration so that we can later compare it with reality event->sparkDwell = sparkDwell; // Compute the final ignition timing including all "late" adjustments - angle_t finalIgnitionTiming = engine->cylinders[event->cylinderNumber].getIgnitionTimingBtdc() + angle_t finalIgnitionTiming = engine->cylinders[realCylinderNumber].getIgnitionTimingBtdc() // Pull any extra timing for knock retard - engine->module()->getKnockRetard(); @@ -82,7 +84,7 @@ static void prepareCylinderIgnitionSchedule(angle_t dwellAngleDuration, floatms_ // maximumIgnitionTiming limits maximum advance finalIgnitionTiming = clampF(engineConfiguration->minimumIgnitionTiming, finalIgnitionTiming, engineConfiguration->maximumIgnitionTiming); - engine->outputChannels.ignitionAdvanceCyl[event->cylinderNumber] = finalIgnitionTiming; + engine->outputChannels.ignitionAdvanceCyl[realCylinderNumber] = finalIgnitionTiming; angle_t sparkAngle = // Negate because timing *before* TDC, and we schedule *after* TDC diff --git a/unit_tests/tests/ignition_injection/test_odd_firing_engine.cpp b/unit_tests/tests/ignition_injection/test_odd_firing_engine.cpp index cba511a8ef..0287bb69b2 100644 --- a/unit_tests/tests/ignition_injection/test_odd_firing_engine.cpp +++ b/unit_tests/tests/ignition_injection/test_odd_firing_engine.cpp @@ -31,7 +31,7 @@ TEST(OddFireRunningMode, hd) { eth.setTriggerType(trigger_type_e::TT_ONE); // end of configuration - // send fake crank signal events so that trigger handler schedules actuators + // send fake crank signal events so that ignition events are updated eth.fireTriggerEvents2(2 /* count */ , 60 /* ms */); LimpState limitedSparkState = getLimpManager()->allowIgnition(); ASSERT_TRUE(limitedSparkState.value); @@ -46,4 +46,7 @@ TEST(OddFireRunningMode, hd) { angle_t expectedAngle7 = -180 + cylinderOne - timing; eth.assertEvent5("spark down#5", 5, (void*)fireSparkAndPrepareNextSchedule, eth.angleToTimeUs(expectedAngle7)); + + EXPECT_EQ(engine->ignitionEvents.elements[0].sparkAngle, 18); + EXPECT_EQ(engine->ignitionEvents.elements[1].sparkAngle, 198); }