diff --git a/firmware/controllers/core/EfiWave.h b/firmware/controllers/core/EfiWave.h index 46dab8d5e1..d22e5f59d6 100644 --- a/firmware/controllers/core/EfiWave.h +++ b/firmware/controllers/core/EfiWave.h @@ -47,7 +47,7 @@ public: int getChannelState(int channelIndex, int phaseIndex) const; int findAngleMatch(float angle, int size) const; - int waveIndertionAngle(float angle, int size) const; + int findInsertionAngle(float angle, int size) const; /** * Number of signal wires diff --git a/firmware/controllers/trigger/trigger_structure.cpp b/firmware/controllers/trigger/trigger_structure.cpp index 2c3f1d5551..b036b1f0f1 100644 --- a/firmware/controllers/trigger/trigger_structure.cpp +++ b/firmware/controllers/trigger/trigger_structure.cpp @@ -146,7 +146,10 @@ int multi_wave_s::getChannelState(int channelIndex, int phaseIndex) const { return waves[channelIndex].pinStates[phaseIndex]; } -int multi_wave_s::waveIndertionAngle(float angle, int size) const { +/** + * returns the index at which given value would need to be inserted into sorted array + */ +int multi_wave_s::findInsertionAngle(float angle, int size) const { for (int i = size - 1; i >= 0; i--) { if (angle > switchTimes[i]) return i + 1; @@ -388,24 +391,27 @@ void TriggerShape::addEvent2(angle_t angle, trigger_wheel_e const waveIndex, tri return; } - int index = wave.waveIndertionAngle(angle, size); + int index = wave.findInsertionAngle(angle, size); - // shifting existing data + /** + * todo: it would be nice to be able to provide trigger angles without sorting them externally + * The idea here is to shift existing data - including handling high vs low state of the signals + */ // todo: does this logic actually work? I think it does not! due to broken state handling +/* for (int i = size - 1; i >= index; i--) { for (int j = 0; j < PWM_PHASE_MAX_WAVE_PER_PWM; j++) { wave.waves[j].pinStates[i + 1] = wave.getChannelState(j, index); } wave.setSwitchTime(i + 1, wave.getSwitchTime(i)); } - +*/ isFrontEvent[index] = TV_RISE == stateParam; if (index != size) { firmwareError(ERROR_TRIGGER_DRAMA, "are we ever here?"); } -// int index = size; size++; for (int i = 0; i < PWM_PHASE_MAX_WAVE_PER_PWM; i++) { diff --git a/unit_tests/test_fuel_map.cpp b/unit_tests/test_fuel_map.cpp index 24877d6dd0..e9cde7d199 100644 --- a/unit_tests/test_fuel_map.cpp +++ b/unit_tests/test_fuel_map.cpp @@ -157,8 +157,8 @@ static void confgiureFordAspireTriggerShape(TriggerShape * s DECLARE_ENGINE_PARA assertEqualsM("expecting not found", -1, s->wave.findAngleMatch(53 / 720.0, s->getSize())); assertEquals(7, s->wave.findAngleMatch(588.045 / 720.0, s->getSize())); - assertEqualsM("expecting 0", 0, s->wave.waveIndertionAngle(23.747 / 720.0, s->getSize())); - assertEqualsM("expecting 1", 1, s->wave.waveIndertionAngle(63.747 / 720.0, s->getSize())); + assertEqualsM("expecting 0", 0, s->wave.findInsertionAngle(23.747 / 720.0, s->getSize())); + assertEqualsM("expecting 1", 1, s->wave.findInsertionAngle(63.747 / 720.0, s->getSize())); } void testAngleResolver(void) { diff --git a/unit_tests/triggers.txt b/unit_tests/triggers.txt index 6bca3876bd..5a95fcf7f8 100644 --- a/unit_tests/triggers.txt +++ b/unit_tests/triggers.txt @@ -2411,7 +2411,7 @@ event 182 1001 541.00 event 183 1000 542.00 event 184 1001 543.00 event 185 0 544.00 -TRIGGERTYPE 39 32 TT_DODGE_NEON_1995_ONLY_CRANK 0.00 +TRIGGERTYPE 39 32 TT_DODGE_NEON_1995_ONLY_CRANK 279.00 # duty 0.80 0.00 event 0 1 0.00 event 1 0 4.00