diff --git a/firmware/controllers/trigger/decoders/trigger_structure.cpp b/firmware/controllers/trigger/decoders/trigger_structure.cpp index 8279c5e948..425384ae63 100644 --- a/firmware/controllers/trigger/decoders/trigger_structure.cpp +++ b/firmware/controllers/trigger/decoders/trigger_structure.cpp @@ -366,7 +366,7 @@ void TriggerWaveform::setTriggerSynchronizationGap3(int gapIndex, float syncRati /** * this method is only used on initialization */ -uint16_t TriggerWaveform::findAngleIndex(TriggerFormDetails *details, float target) const { +uint16_t TriggerWaveform::findAngleIndex(TriggerFormDetails *details, angle_t targetAngle) const { size_t engineCycleEventCount = getLength(); efiAssert(CUSTOM_ERR_ASSERT, engineCycleEventCount != 0 && engineCycleEventCount <= 0xFFFF, "engineCycleEventCount", 0); @@ -382,9 +382,9 @@ uint16_t TriggerWaveform::findAngleIndex(TriggerFormDetails *details, float targ int middle = (left + right) / 2; angle_t eventAngle = details->eventAngles[middle]; - if (eventAngle < target) { + if (eventAngle < targetAngle) { left = middle + 1; - } else if (eventAngle > target) { + } else if (eventAngle > targetAngle) { right = middle - 1; } else { // Values are equal diff --git a/firmware/controllers/trigger/decoders/trigger_structure.h b/firmware/controllers/trigger/decoders/trigger_structure.h index 2db031b45e..835aafa87f 100644 --- a/firmware/controllers/trigger/decoders/trigger_structure.h +++ b/firmware/controllers/trigger/decoders/trigger_structure.h @@ -276,10 +276,11 @@ public: const trigger_config_s& triggerConfig ); + uint16_t findAngleIndex(TriggerFormDetails *details, angle_t angle) const; + private: trigger_shape_helper h; - uint16_t findAngleIndex(TriggerFormDetails *details, float angle) const; /** * Working buffer for 'wave' instance diff --git a/unit_tests/tests/trigger/test_symmetrical_crank.cpp b/unit_tests/tests/trigger/test_symmetrical_crank.cpp index 3bb70b2f3b..5ba576706e 100644 --- a/unit_tests/tests/trigger/test_symmetrical_crank.cpp +++ b/unit_tests/tests/trigger/test_symmetrical_crank.cpp @@ -14,6 +14,18 @@ static void postFourEvents(EngineTestHelper *eth, float mult) { eth->fireRise(mult * 16); } +TEST(engine, testAngleLogicInSymmetricalCrankIssue2980) { + WITH_ENGINE_TEST_HELPER(MAZDA_MIATA_2003); + + TriggerFormDetails *triggerForm = &ENGINE(triggerCentral.triggerFormDetails); + + TriggerWaveform * form = &ENGINE(triggerCentral.triggerShape); + + ASSERT_EQ(form->findAngleIndex(triggerForm, 10), 1); + ASSERT_EQ(form->findAngleIndex(triggerForm, 310), 5); + ASSERT_EQ(form->findAngleIndex(triggerForm, 710), 15); +} + TEST(engine, testSymmetricalCrank) { WITH_ENGINE_TEST_HELPER(MAZDA_MIATA_2003);