diff --git a/firmware/controllers/algo/advance_map.cpp b/firmware/controllers/algo/advance_map.cpp index b2a5fb7fb2..db7fbbd5ca 100644 --- a/firmware/controllers/algo/advance_map.cpp +++ b/firmware/controllers/algo/advance_map.cpp @@ -50,7 +50,7 @@ float getAdvance(int rpm, float engineLoad DECLARE_ENGINE_PARAMETER_S) { } else { angle = getBaseAdvance(rpm, engineLoad); } - return fixAngle(engineConfiguration, angle - engineConfiguration->ignitionOffset); + return fixAngle(angle - engineConfiguration->ignitionOffset PASS_ENGINE_PARAMETER); } void prepareTimingMap(void) { diff --git a/firmware/controllers/math/engine_math.cpp b/firmware/controllers/math/engine_math.cpp index 7bb8b76dd5..ade46933e4 100644 --- a/firmware/controllers/math/engine_math.cpp +++ b/firmware/controllers/math/engine_math.cpp @@ -52,7 +52,7 @@ float getCrankshaftRevolutionTimeMs(int rpm) { * @brief Shifts angle into the [0..720) range * TODO: should be 'crankAngleRange' range? */ -float fixAngle(engine_configuration_s const *engineConfiguration, float angle) { +float fixAngle(float angle DECLARE_ENGINE_PARAMETER_S) { efiAssert(engineConfiguration->engineCycle!=0, "engine cycle", NAN); // I guess this implementation would be faster than 'angle % 720' while (angle < 0) @@ -286,7 +286,7 @@ int getEngineCycleEventCount(engine_configuration_s const *engineConfiguration, void findTriggerPosition(trigger_shape_s * s, event_trigger_position_s *position, float angleOffset DECLARE_ENGINE_PARAMETER_S) { - angleOffset = fixAngle(engineConfiguration, angleOffset + engineConfiguration->globalTriggerAngleOffset); + angleOffset = fixAngle(angleOffset + engineConfiguration->globalTriggerAngleOffset PASS_ENGINE_PARAMETER); int engineCycleEventCount = getEngineCycleEventCount(engineConfiguration, s); @@ -363,7 +363,7 @@ void prepareOutputSignals(Engine *engine) { engine_configuration2_s *engineConfiguration2 = engine->engineConfiguration2; // todo: move this reset into decoder - engineConfiguration2->triggerShape.calculateTriggerSynchPoint(engineConfiguration, &engineConfiguration->triggerConfig); + engineConfiguration2->triggerShape.calculateTriggerSynchPoint(engineConfiguration, &engineConfiguration->triggerConfig, engine); trigger_shape_s * ts = &engineConfiguration2->triggerShape; diff --git a/firmware/controllers/math/engine_math.h b/firmware/controllers/math/engine_math.h index 1b8f06284a..fdd08243fd 100644 --- a/firmware/controllers/math/engine_math.h +++ b/firmware/controllers/math/engine_math.h @@ -31,7 +31,7 @@ extern "C" { #endif /* __cplusplus */ -float fixAngle(engine_configuration_s const *engineConfiguration, float angle); +float fixAngle(float angle DECLARE_ENGINE_PARAMETER_S); /** * So that's how 'inline' syntax for both GCC and IAR diff --git a/firmware/controllers/trigger/main_trigger_callback.cpp b/firmware/controllers/trigger/main_trigger_callback.cpp index a9d21b67b1..49b1447f7b 100644 --- a/firmware/controllers/trigger/main_trigger_callback.cpp +++ b/firmware/controllers/trigger/main_trigger_callback.cpp @@ -348,7 +348,7 @@ void mainTriggerCallback(trigger_event_e ckpSignalType, uint32_t eventIndex, Eng float dwellAngle = dwellMs / getOneDegreeTimeMs(rpm); - initializeIgnitionActions(fixAngle(engineConfiguration, -advance), dwellAngle, engine->engineConfiguration2, + initializeIgnitionActions(fixAngle(-advance PASS_ENGINE_PARAMETER), dwellAngle, engine->engineConfiguration2, &engine->engineConfiguration2->ignitionEvents[revolutionIndex] PASS_ENGINE_PARAMETER); } diff --git a/firmware/controllers/trigger/trigger_structure.cpp b/firmware/controllers/trigger/trigger_structure.cpp index 20ae6d1364..90025d6fdf 100644 --- a/firmware/controllers/trigger/trigger_structure.cpp +++ b/firmware/controllers/trigger/trigger_structure.cpp @@ -55,11 +55,11 @@ int trigger_shape_s::getTriggerShapeSynchPointIndex() { // todo: clean-up! int getEngineCycleEventCount2(operation_mode_e mode, trigger_shape_s * s); -void trigger_shape_s::calculateTriggerSynchPoint(engine_configuration_s const*engineConfiguration, trigger_config_s const*triggerConfig) { - setTriggerShapeSynchPointIndex(engineConfiguration, findTriggerZeroEventIndex(this, triggerConfig)); +void trigger_shape_s::calculateTriggerSynchPoint(engine_configuration_s *engineConfiguration, trigger_config_s const*triggerConfig, Engine *engine) { + setTriggerShapeSynchPointIndex(engineConfiguration, findTriggerZeroEventIndex(this, triggerConfig), engine); } -void trigger_shape_s::setTriggerShapeSynchPointIndex(engine_configuration_s const *engineConfiguration, int triggerShapeSynchPointIndex) { +void trigger_shape_s::setTriggerShapeSynchPointIndex(engine_configuration_s *engineConfiguration, int triggerShapeSynchPointIndex, Engine *engine) { this->triggerShapeSynchPointIndex = triggerShapeSynchPointIndex; int engineCycleEventCount = getEngineCycleEventCount2(operationMode, this); @@ -71,7 +71,7 @@ void trigger_shape_s::setTriggerShapeSynchPointIndex(engine_configuration_s cons // explicit check for zero to avoid issues where logical zero is not exactly zero due to float nature eventAngles[i] = 0; } else { - eventAngles[i] = fixAngle(engineConfiguration, getAngle((triggerShapeSynchPointIndex + i) % engineCycleEventCount) - firstAngle); + eventAngles[i] = fixAngle(getAngle((triggerShapeSynchPointIndex + i) % engineCycleEventCount) - firstAngle PASS_ENGINE_PARAMETER); } } } diff --git a/firmware/controllers/trigger/trigger_structure.h b/firmware/controllers/trigger/trigger_structure.h index 8cd21d8053..6013c5d57b 100644 --- a/firmware/controllers/trigger/trigger_structure.h +++ b/firmware/controllers/trigger/trigger_structure.h @@ -26,6 +26,8 @@ public: single_wave_s waves[TRIGGER_CHANNEL_COUNT]; }; +class Engine; + class trigger_shape_s { public: trigger_shape_s(); @@ -83,9 +85,9 @@ public: int getTriggerShapeSynchPointIndex(); - void calculateTriggerSynchPoint(engine_configuration_s const *engineConfiguration, trigger_config_s const*triggerConfig); + void calculateTriggerSynchPoint(engine_configuration_s *engineConfiguration, trigger_config_s const*triggerConfig, Engine *engine); - void setTriggerShapeSynchPointIndex(engine_configuration_s const *engineConfiguration, int triggerShapeSynchPointIndex); + void setTriggerShapeSynchPointIndex(engine_configuration_s *engineConfiguration, int triggerShapeSynchPointIndex, Engine *engine); /** * These angles are in event coordinates - with synchronization point located at angle zero. * These values are pre-calculated for performance reasons. diff --git a/firmware/emulation/wave_analyzer.cpp b/firmware/emulation/wave_analyzer.cpp index ec2281b7df..62c9966017 100644 --- a/firmware/emulation/wave_analyzer.cpp +++ b/firmware/emulation/wave_analyzer.cpp @@ -234,7 +234,7 @@ static void reportWave(Logging *logging, int index) { float oneDegreeUs = getOneDegreeTimeUs(getRpm()); appendPrintf(logging, "advance%d%s", index, DELIMETER); - appendFloat(logging, fixAngle(engineConfiguration, (offsetUs / oneDegreeUs) - engineConfiguration->globalTriggerAngleOffset), 3); + appendFloat(logging, fixAngle((offsetUs / oneDegreeUs) - engineConfiguration->globalTriggerAngleOffset PASS_ENGINE_PARAMETER), 3); appendPrintf(logging, "%s", DELIMETER); } } diff --git a/unit_tests/test_fuel_map.cpp b/unit_tests/test_fuel_map.cpp index 19e5e43f6e..1d0e8efe6a 100644 --- a/unit_tests/test_fuel_map.cpp +++ b/unit_tests/test_fuel_map.cpp @@ -163,7 +163,7 @@ void testAngleResolver(void) { confgiureFordAspireTriggerShape(ts); - ts->calculateTriggerSynchPoint(engineConfiguration, &engineConfiguration->triggerConfig); + ts->calculateTriggerSynchPoint(engineConfiguration, &engineConfiguration->triggerConfig, engine); assertEqualsM("index 2", 232.76, ts->eventAngles[3]); // this angle is relation to synch point assertEqualsM("time 2", 0.3233, ts->wave.getSwitchTime(2));