From 883336ff304b71dad52bd18e5b40f12aa61ed4e6 Mon Sep 17 00:00:00 2001 From: Matthew Kennedy Date: Thu, 19 Oct 2023 17:34:29 -0400 Subject: [PATCH] fixAngle -> wrapAngle --- firmware/controllers/algo/advance_map.cpp | 2 +- firmware/controllers/algo/engine.cpp | 2 +- firmware/controllers/algo/fuel_math.cpp | 2 +- firmware/controllers/engine_cycle/aux_valves.cpp | 2 +- firmware/controllers/engine_cycle/map_averaging.cpp | 4 ++-- firmware/controllers/engine_cycle/rpm_calculator.cpp | 2 +- firmware/controllers/math/engine_math.cpp | 2 +- firmware/controllers/math/engine_math.h | 4 +--- firmware/controllers/trigger/instant_rpm_calculator.cpp | 4 ++-- firmware/controllers/trigger/trigger_decoder.cpp | 2 +- firmware/development/logic_analyzer.cpp | 2 +- 11 files changed, 13 insertions(+), 15 deletions(-) diff --git a/firmware/controllers/algo/advance_map.cpp b/firmware/controllers/algo/advance_map.cpp index 861ea7a52d..3b9e097e24 100644 --- a/firmware/controllers/algo/advance_map.cpp +++ b/firmware/controllers/algo/advance_map.cpp @@ -188,7 +188,7 @@ angle_t getAdvance(int rpm, float engineLoad) { } efiAssert(ObdCode::CUSTOM_ERR_ASSERT, !cisnan(angle), "_AngleN5", 0); - fixAngle(angle, "getAdvance", ObdCode::CUSTOM_ERR_ADCANCE_CALC_ANGLE); + wrapAngle(angle, "getAdvance", ObdCode::CUSTOM_ERR_ADCANCE_CALC_ANGLE); return angle; #else return 0; diff --git a/firmware/controllers/algo/engine.cpp b/firmware/controllers/algo/engine.cpp index 8537f7ebc4..d3cc6ebb55 100644 --- a/firmware/controllers/algo/engine.cpp +++ b/firmware/controllers/algo/engine.cpp @@ -293,7 +293,7 @@ int Engine::getGlobalConfigurationVersion(void) const { void Engine::reset() { /** - * it's important for fixAngle() that engineCycle field never has zero + * it's important for wrapAngle() that engineCycle field never has zero */ engineState.engineCycle = getEngineCycle(FOUR_STROKE_CRANK_SENSOR); resetLua(); diff --git a/firmware/controllers/algo/fuel_math.cpp b/firmware/controllers/algo/fuel_math.cpp index b3e0b7177d..ed7f0ed869 100644 --- a/firmware/controllers/algo/fuel_math.cpp +++ b/firmware/controllers/algo/fuel_math.cpp @@ -228,7 +228,7 @@ angle_t getInjectionOffset(float rpm, float load) { } angle_t result = value; - fixAngle(result, "inj offset#2", ObdCode::CUSTOM_ERR_6553); + wrapAngle(result, "inj offset#2", ObdCode::CUSTOM_ERR_6553); return result; } diff --git a/firmware/controllers/engine_cycle/aux_valves.cpp b/firmware/controllers/engine_cycle/aux_valves.cpp index 6398b59a9f..09aa14cb8d 100644 --- a/firmware/controllers/engine_cycle/aux_valves.cpp +++ b/firmware/controllers/engine_cycle/aux_valves.cpp @@ -41,7 +41,7 @@ void auxPlainPinTurnOn(AuxActor *current) { angle_t duration = engine->engineState.auxValveEnd - engine->engineState.auxValveStart; - fixAngle(duration, "duration", ObdCode::CUSTOM_ERR_6557); + wrapAngle(duration, "duration", ObdCode::CUSTOM_ERR_6557); engine->module()->schedule( "aux-valve", diff --git a/firmware/controllers/engine_cycle/map_averaging.cpp b/firmware/controllers/engine_cycle/map_averaging.cpp index 3d2da43465..6f9a6b54e2 100644 --- a/firmware/controllers/engine_cycle/map_averaging.cpp +++ b/firmware/controllers/engine_cycle/map_averaging.cpp @@ -185,7 +185,7 @@ void refreshMapAveragingPreCalc() { // move the loop into start-up calculation and not have this loop as part of periodic calculation // todo: change the logic as described above in order to reduce periodic CPU usage? float cylinderStart = start + cylinderOffset - offsetAngle + tdcPosition(); - fixAngle(cylinderStart, "cylinderStart", ObdCode::CUSTOM_ERR_6562); + wrapAngle(cylinderStart, "cylinderStart", ObdCode::CUSTOM_ERR_6562); engine->engineState.mapAveragingStart[i] = cylinderStart; } engine->engineState.mapAveragingDuration = interpolate2d(rpm, c->samplingWindowBins, c->samplingWindow); @@ -242,7 +242,7 @@ void mapAveragingTriggerCallback( } // todo: pre-calculate samplingEnd for each cylinder - fixAngle(samplingEnd, "samplingEnd", ObdCode::CUSTOM_ERR_6563); + wrapAngle(samplingEnd, "samplingEnd", ObdCode::CUSTOM_ERR_6563); // only if value is already prepared int structIndex = getRevolutionCounter() % 2; diff --git a/firmware/controllers/engine_cycle/rpm_calculator.cpp b/firmware/controllers/engine_cycle/rpm_calculator.cpp index ff8bf752e6..2577d564d3 100644 --- a/firmware/controllers/engine_cycle/rpm_calculator.cpp +++ b/firmware/controllers/engine_cycle/rpm_calculator.cpp @@ -376,7 +376,7 @@ void tdcMarkCallback( if (isValidRpm(rpm)) { angle_t tdcPosition = tdcPosition(); // we need a positive angle offset here - fixAngle(tdcPosition, "tdcPosition", ObdCode::CUSTOM_ERR_6553); + wrapAngle(tdcPosition, "tdcPosition", ObdCode::CUSTOM_ERR_6553); scheduleByAngle(&engine->tdcScheduler[revIndex2], edgeTimestamp, tdcPosition, onTdcCallback); } } diff --git a/firmware/controllers/math/engine_math.cpp b/firmware/controllers/math/engine_math.cpp index 7c02bb676d..2d3c2cb5be 100644 --- a/firmware/controllers/math/engine_math.cpp +++ b/firmware/controllers/math/engine_math.cpp @@ -31,7 +31,7 @@ extern bool verboseMode; #endif /* EFI_UNIT_TEST */ angle_t wrapAngleMethod(angle_t param, const char *msg, ObdCode code) { - fixAngle(param, msg, code); + wrapAngle(param, msg, code); return param; } diff --git a/firmware/controllers/math/engine_math.h b/firmware/controllers/math/engine_math.h index fddbbba52a..2adea31fa3 100644 --- a/firmware/controllers/math/engine_math.h +++ b/firmware/controllers/math/engine_math.h @@ -15,11 +15,9 @@ void setFlatInjectorLag(float value); /** * 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, getEngineState()->engineCycle) -#define wrapAngle(angle, msg, code) fixAngle(angle, msg, code) +#define wrapAngle(angle, msg, code) wrapAngle2(angle, msg, code, getEngineState()->engineCycle) // proper method avoids un-wrapped state of variables angle_t wrapAngleMethod(angle_t param, const char *msg, ObdCode code); diff --git a/firmware/controllers/trigger/instant_rpm_calculator.cpp b/firmware/controllers/trigger/instant_rpm_calculator.cpp index 37ddfd83e2..6721faf1be 100644 --- a/firmware/controllers/trigger/instant_rpm_calculator.cpp +++ b/firmware/controllers/trigger/instant_rpm_calculator.cpp @@ -58,7 +58,7 @@ float InstantRpmCalculator::calculateInstantRpm( // Hunt for a tooth ~90 degrees ago to compare to the current time angle_t previousAngle = currentAngle - 90; - fixAngle(previousAngle, "prevAngle", ObdCode::CUSTOM_ERR_TRIGGER_ANGLE_RANGE); + wrapAngle(previousAngle, "prevAngle", ObdCode::CUSTOM_ERR_TRIGGER_ANGLE_RANGE); int prevIndex = triggerShape.findAngleIndex(triggerFormDetails, previousAngle); // now let's get precise angle for that event @@ -77,7 +77,7 @@ float InstantRpmCalculator::calculateInstantRpm( angle_t angleDiff = currentAngle - prevIndexAngle; // Wrap the angle in to the correct range (ie, could be -630 when we want +90) - fixAngle(angleDiff, "angleDiff", ObdCode::CUSTOM_ERR_6561); + wrapAngle(angleDiff, "angleDiff", ObdCode::CUSTOM_ERR_6561); // just for safety, avoid divide-by-0 if (time == 0) { diff --git a/firmware/controllers/trigger/trigger_decoder.cpp b/firmware/controllers/trigger/trigger_decoder.cpp index b9b560fb4b..393a6c85ec 100644 --- a/firmware/controllers/trigger/trigger_decoder.cpp +++ b/firmware/controllers/trigger/trigger_decoder.cpp @@ -160,7 +160,7 @@ void TriggerFormDetails::prepareEventAngles(TriggerWaveform *shape) { efiAssertVoid(ObdCode::CUSTOM_TRIGGER_CYCLE, !cisnan(angle), "trgSyncNaN"); // Wrap the angle back in to [0, 720) - fixAngle(angle, "trgSync", ObdCode::CUSTOM_TRIGGER_SYNC_ANGLE_RANGE); + wrapAngle(angle, "trgSync", ObdCode::CUSTOM_TRIGGER_SYNC_ANGLE_RANGE); if (shape->useOnlyRisingEdges) { criticalAssertVoid(triggerDefinitionIndex < triggerShapeLength, "trigger shape fail"); diff --git a/firmware/development/logic_analyzer.cpp b/firmware/development/logic_analyzer.cpp index fa71461255..af50750f9a 100644 --- a/firmware/development/logic_analyzer.cpp +++ b/firmware/development/logic_analyzer.cpp @@ -218,7 +218,7 @@ static void reportWave(Logging *logging, int index) { logging->appendPrintf("advance%d%s", index, LOG_DELIMITER); float angle = (offsetUs / oneDegreeUs) - tdcPosition(); - fixAngle(angle, "waveAn", ObdCode::CUSTOM_ERR_6564); + wrapAngle(angle, "waveAn", ObdCode::CUSTOM_ERR_6564); logging->appendFloat(angle, 3); logging->appendPrintf("%s", LOG_DELIMITER); }