fixAngle -> wrapAngle

This commit is contained in:
Matthew Kennedy 2023-10-19 17:34:29 -04:00 committed by rusefi
parent d638ddd534
commit 883336ff30
11 changed files with 13 additions and 15 deletions

View File

@ -188,7 +188,7 @@ angle_t getAdvance(int rpm, float engineLoad) {
} }
efiAssert(ObdCode::CUSTOM_ERR_ASSERT, !cisnan(angle), "_AngleN5", 0); 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; return angle;
#else #else
return 0; return 0;

View File

@ -293,7 +293,7 @@ int Engine::getGlobalConfigurationVersion(void) const {
void Engine::reset() { 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); engineState.engineCycle = getEngineCycle(FOUR_STROKE_CRANK_SENSOR);
resetLua(); resetLua();

View File

@ -228,7 +228,7 @@ angle_t getInjectionOffset(float rpm, float load) {
} }
angle_t result = value; angle_t result = value;
fixAngle(result, "inj offset#2", ObdCode::CUSTOM_ERR_6553); wrapAngle(result, "inj offset#2", ObdCode::CUSTOM_ERR_6553);
return result; return result;
} }

View File

@ -41,7 +41,7 @@ void auxPlainPinTurnOn(AuxActor *current) {
angle_t duration = engine->engineState.auxValveEnd - engine->engineState.auxValveStart; 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<TriggerScheduler>()->schedule( engine->module<TriggerScheduler>()->schedule(
"aux-valve", "aux-valve",

View File

@ -185,7 +185,7 @@ void refreshMapAveragingPreCalc() {
// move the loop into start-up calculation and not have this loop as part of periodic calculation // 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? // todo: change the logic as described above in order to reduce periodic CPU usage?
float cylinderStart = start + cylinderOffset - offsetAngle + tdcPosition(); 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.mapAveragingStart[i] = cylinderStart;
} }
engine->engineState.mapAveragingDuration = interpolate2d(rpm, c->samplingWindowBins, c->samplingWindow); engine->engineState.mapAveragingDuration = interpolate2d(rpm, c->samplingWindowBins, c->samplingWindow);
@ -242,7 +242,7 @@ void mapAveragingTriggerCallback(
} }
// todo: pre-calculate samplingEnd for each cylinder // 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 // only if value is already prepared
int structIndex = getRevolutionCounter() % 2; int structIndex = getRevolutionCounter() % 2;

View File

@ -376,7 +376,7 @@ void tdcMarkCallback(
if (isValidRpm(rpm)) { if (isValidRpm(rpm)) {
angle_t tdcPosition = tdcPosition(); angle_t tdcPosition = tdcPosition();
// we need a positive angle offset here // 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); scheduleByAngle(&engine->tdcScheduler[revIndex2], edgeTimestamp, tdcPosition, onTdcCallback);
} }
} }

View File

@ -31,7 +31,7 @@ extern bool verboseMode;
#endif /* EFI_UNIT_TEST */ #endif /* EFI_UNIT_TEST */
angle_t wrapAngleMethod(angle_t param, const char *msg, ObdCode code) { angle_t wrapAngleMethod(angle_t param, const char *msg, ObdCode code) {
fixAngle(param, msg, code); wrapAngle(param, msg, code);
return param; return param;
} }

View File

@ -15,11 +15,9 @@ void setFlatInjectorLag(float value);
/** /**
* See also wrapVvt * 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? * 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) wrapAngle2(angle, msg, code, getEngineState()->engineCycle)
#define wrapAngle(angle, msg, code) fixAngle(angle, msg, code)
// proper method avoids un-wrapped state of variables // proper method avoids un-wrapped state of variables
angle_t wrapAngleMethod(angle_t param, const char *msg, ObdCode code); angle_t wrapAngleMethod(angle_t param, const char *msg, ObdCode code);

View File

@ -58,7 +58,7 @@ float InstantRpmCalculator::calculateInstantRpm(
// Hunt for a tooth ~90 degrees ago to compare to the current time // Hunt for a tooth ~90 degrees ago to compare to the current time
angle_t previousAngle = currentAngle - 90; 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); int prevIndex = triggerShape.findAngleIndex(triggerFormDetails, previousAngle);
// now let's get precise angle for that event // now let's get precise angle for that event
@ -77,7 +77,7 @@ float InstantRpmCalculator::calculateInstantRpm(
angle_t angleDiff = currentAngle - prevIndexAngle; angle_t angleDiff = currentAngle - prevIndexAngle;
// Wrap the angle in to the correct range (ie, could be -630 when we want +90) // 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 // just for safety, avoid divide-by-0
if (time == 0) { if (time == 0) {

View File

@ -160,7 +160,7 @@ void TriggerFormDetails::prepareEventAngles(TriggerWaveform *shape) {
efiAssertVoid(ObdCode::CUSTOM_TRIGGER_CYCLE, !cisnan(angle), "trgSyncNaN"); efiAssertVoid(ObdCode::CUSTOM_TRIGGER_CYCLE, !cisnan(angle), "trgSyncNaN");
// Wrap the angle back in to [0, 720) // 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) { if (shape->useOnlyRisingEdges) {
criticalAssertVoid(triggerDefinitionIndex < triggerShapeLength, "trigger shape fail"); criticalAssertVoid(triggerDefinitionIndex < triggerShapeLength, "trigger shape fail");

View File

@ -218,7 +218,7 @@ static void reportWave(Logging *logging, int index) {
logging->appendPrintf("advance%d%s", index, LOG_DELIMITER); logging->appendPrintf("advance%d%s", index, LOG_DELIMITER);
float angle = (offsetUs / oneDegreeUs) - tdcPosition(); float angle = (offsetUs / oneDegreeUs) - tdcPosition();
fixAngle(angle, "waveAn", ObdCode::CUSTOM_ERR_6564); wrapAngle(angle, "waveAn", ObdCode::CUSTOM_ERR_6564);
logging->appendFloat(angle, 3); logging->appendFloat(angle, 3);
logging->appendPrintf("%s", LOG_DELIMITER); logging->appendPrintf("%s", LOG_DELIMITER);
} }