diff --git a/firmware/controllers/math/engine_math.h b/firmware/controllers/math/engine_math.h index abe193b059..2a8207439d 100644 --- a/firmware/controllers/math/engine_math.h +++ b/firmware/controllers/math/engine_math.h @@ -13,8 +13,13 @@ void setAlgorithm(engine_load_mode_e algo); void setFlatInjectorLag(float value); -#define fixAngle(angle, msg, code) fixAngle2(angle, msg, code, engine->engineCycle) - +/** + * See also wrapVvt + * TODO: replace all usages of fixAngle with wrapAngle? + * Should we make this a nice method instead of that off macro which changes parameter value? + */ +#define fixAngle(angle, msg, code) wrapAngle2(angle, msg, code, engine->engineCycle) +#define wrapAngle(angle, msg, code) fixAngle(angle, msg, code) /** * @return time needed to rotate crankshaft by one degree, in milliseconds. diff --git a/firmware/controllers/trigger/decoders/trigger_structure.cpp b/firmware/controllers/trigger/decoders/trigger_structure.cpp index 0e715a6100..f68c3f0002 100644 --- a/firmware/controllers/trigger/decoders/trigger_structure.cpp +++ b/firmware/controllers/trigger/decoders/trigger_structure.cpp @@ -388,7 +388,7 @@ void findTriggerPosition(TriggerWaveform *triggerShape, // convert engine cycle angle into trigger cycle angle angle += triggerShape->tdcPosition + engineConfiguration->globalTriggerAngleOffset; efiAssertVoid(CUSTOM_ERR_6577, !cisnan(angle), "findAngle#2"); - fixAngle2(angle, "addFuel#2", CUSTOM_ERR_6555, getEngineCycle(triggerShape->getOperationMode())); + wrapAngle2(angle, "addFuel#2", CUSTOM_ERR_6555, getEngineCycle(triggerShape->getOperationMode())); int triggerEventIndex = triggerShape->findAngleIndex(details, angle); angle_t triggerEventAngle = details->eventAngles[triggerEventIndex]; diff --git a/firmware/controllers/trigger/decoders/trigger_structure.h b/firmware/controllers/trigger/decoders/trigger_structure.h index 3059429def..972e828973 100644 --- a/firmware/controllers/trigger/decoders/trigger_structure.h +++ b/firmware/controllers/trigger/decoders/trigger_structure.h @@ -29,7 +29,7 @@ * @brief Shifts angle into the [0..720) range for four stroke and [0..360) for two stroke * I guess this implementation would be faster than 'angle % engineCycle' */ -#define fixAngle2(angle, msg, code, engineCycle) \ +#define wrapAngle2(angle, msg, code, engineCycle) \ { \ if (cisnan(angle)) { \ firmwareError(CUSTOM_ERR_ANGLE, "aNaN%s", msg); \ diff --git a/firmware/controllers/trigger/trigger_central.cpp b/firmware/controllers/trigger/trigger_central.cpp index 45a9b16683..641ba4b724 100644 --- a/firmware/controllers/trigger/trigger_central.cpp +++ b/firmware/controllers/trigger/trigger_central.cpp @@ -160,6 +160,9 @@ static angle_t adjustCrankPhase(int camIndex) { } } +/** + * See also wrapAngle + */ static angle_t wrapVvt(angle_t vvtPosition, int period) { // Wrap VVT position in to the range [-360, 360) while (vvtPosition < -period / 2) {