inline method to reduce confusion

This commit is contained in:
Andrey 2022-09-14 01:34:52 -04:00
parent 34f87a3683
commit b439f27284
12 changed files with 25 additions and 29 deletions

View File

@ -585,22 +585,6 @@ static bool doesTriggerImplyOperationMode(trigger_type_e type) {
} }
} }
operation_mode_e Engine::getOperationMode() const {
return rpmCalculator.getOperationMode();
}
operation_mode_e RpmCalculator::getOperationMode() const {
// Ignore user-provided setting for well known triggers.
if (doesTriggerImplyOperationMode(engineConfiguration->trigger.type)) {
// For example for Miata NA, there is no reason to allow user to set FOUR_STROKE_CRANK_SENSOR
return engine->triggerCentral.triggerShape.getWheelOperationMode();
} else {
// For example 36-1, could be on either cam or crank, so we have to ask the user
return lookupOperationMode();
}
}
/** /**
* The idea of this method is to execute all heavy calculations in a lower-priority thread, * The idea of this method is to execute all heavy calculations in a lower-priority thread,
* so that trigger event handler/IO scheduler tasks are faster. * so that trigger event handler/IO scheduler tasks are faster.

View File

@ -219,7 +219,6 @@ public:
LocalVersionHolder versionForConfigurationListeners; LocalVersionHolder versionForConfigurationListeners;
LocalVersionHolder auxParametersVersion; LocalVersionHolder auxParametersVersion;
operation_mode_e getOperationMode() const;
AuxActor auxValves[AUX_DIGITAL_VALVE_COUNT][2]; AuxActor auxValves[AUX_DIGITAL_VALVE_COUNT][2];

View File

@ -183,7 +183,7 @@ void refreshMapAveragingPreCalc() {
efiAssertVoid(CUSTOM_ERR_MAP_AVG_OFFSET, !cisnan(offsetAngle), "offsetAngle"); efiAssertVoid(CUSTOM_ERR_MAP_AVG_OFFSET, !cisnan(offsetAngle), "offsetAngle");
for (size_t i = 0; i < engineConfiguration->specs.cylindersCount; i++) { for (size_t i = 0; i < engineConfiguration->specs.cylindersCount; i++) {
angle_t cylinderOffset = getEngineCycle(engine->getOperationMode()) * i / engineConfiguration->specs.cylindersCount; angle_t cylinderOffset = getEngineCycle(getEngineRotationState()->getOperationMode()) * i / engineConfiguration->specs.cylindersCount;
efiAssertVoid(CUSTOM_ERR_MAP_CYL_OFFSET, !cisnan(cylinderOffset), "cylinderOffset"); efiAssertVoid(CUSTOM_ERR_MAP_CYL_OFFSET, !cisnan(cylinderOffset), "cylinderOffset");
// part of this formula related to specific cylinder offset is never changing - we can // part of this formula related to specific cylinder offset is never changing - we can
// 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

View File

@ -101,6 +101,18 @@ bool RpmCalculator::checkIfSpinning(efitick_t nowNt) const {
return true; return true;
} }
// todo: move to triggerCentral/triggerShape since has nothing to do with rotation state!
operation_mode_e RpmCalculator::getOperationMode() const {
// Ignore user-provided setting for well known triggers.
if (doesTriggerImplyOperationMode(engineConfiguration->trigger.type)) {
// For example for Miata NA, there is no reason to allow user to set FOUR_STROKE_CRANK_SENSOR
return engine->triggerCentral.triggerShape.getWheelOperationMode();
} else {
// For example 36-1, could be on either cam or crank, so we have to ask the user
return lookupOperationMode();
}
}
void RpmCalculator::assignRpmValue(float floatRpmValue) { void RpmCalculator::assignRpmValue(float floatRpmValue) {
previousRpmValue = cachedRpmValue; previousRpmValue = cachedRpmValue;
@ -255,7 +267,7 @@ void rpmShaftPositionCallback(trigger_event_e ckpSignalType,
rpmState->setRpmValue(NOISY_RPM); rpmState->setRpmValue(NOISY_RPM);
rpmState->rpmRate = 0; rpmState->rpmRate = 0;
} else { } else {
int mult = (int)getEngineCycle(engine->getOperationMode()) / 360; int mult = (int)getEngineCycle(getEngineRotationState()->getOperationMode()) / 360;
float rpm = 60 * mult / periodSeconds; float rpm = 60 * mult / periodSeconds;
auto rpmDelta = rpm - rpmState->previousRpmValue; auto rpmDelta = rpm - rpmState->previousRpmValue;

View File

@ -15,6 +15,7 @@ public:
*/ */
virtual bool isStopped() const = 0; virtual bool isStopped() const = 0;
// todo: move to triggerCentral/triggerShape since has nothing to do with rotation state!
virtual operation_mode_e getOperationMode() const = 0; virtual operation_mode_e getOperationMode() const = 0;
}; };

View File

@ -406,7 +406,7 @@ static void prepareIgnitionSchedule() {
* but we are already re-purposing the output signals, but everything works because we * but we are already re-purposing the output signals, but everything works because we
* are not affecting that space in memory. todo: use two instances of 'ignitionSignals' * are not affecting that space in memory. todo: use two instances of 'ignitionSignals'
*/ */
operation_mode_e operationMode = engine->getOperationMode(); operation_mode_e operationMode = getEngineRotationState()->getOperationMode();
float maxAllowedDwellAngle = (int) (getEngineCycle(operationMode) / 2); // the cast is about making Coverity happy float maxAllowedDwellAngle = (int) (getEngineCycle(operationMode) / 2); // the cast is about making Coverity happy
if (getCurrentIgnitionMode() == IM_ONE_COIL) { if (getCurrentIgnitionMode() == IM_ONE_COIL) {
@ -498,7 +498,7 @@ int getNumberOfSparks(ignition_mode_e mode) {
*/ */
percent_t getCoilDutyCycle(int rpm) { percent_t getCoilDutyCycle(int rpm) {
floatms_t totalPerCycle = engine->engineState.sparkDwell * getNumberOfSparks(getCurrentIgnitionMode()); floatms_t totalPerCycle = engine->engineState.sparkDwell * getNumberOfSparks(getCurrentIgnitionMode());
floatms_t engineCycleDuration = getCrankshaftRevolutionTimeMs(rpm) * (engine->getOperationMode() == TWO_STROKE ? 1 : 2); floatms_t engineCycleDuration = getCrankshaftRevolutionTimeMs(rpm) * (getEngineRotationState()->getOperationMode() == TWO_STROKE ? 1 : 2);
return 100 * totalPerCycle / engineCycleDuration; return 100 * totalPerCycle / engineCycleDuration;
} }

View File

@ -7,7 +7,7 @@
#define CLEANUP_MODE_TPS 90 #define CLEANUP_MODE_TPS 90
static bool noFiringUntilVvtSync(vvt_mode_e vvtMode) { static bool noFiringUntilVvtSync(vvt_mode_e vvtMode) {
auto operationMode = engine->getOperationMode(); auto operationMode = getEngineRotationState()->getOperationMode();
// V-Twin MAP phase sense needs to always wait for sync // V-Twin MAP phase sense needs to always wait for sync
if (vvtMode == VVT_MAP_V_TWIN) { if (vvtMode == VVT_MAP_V_TWIN) {

View File

@ -35,7 +35,7 @@ angle_t wrapAngleMethod(angle_t param, const char *msg, obd_code_e code) {
} }
floatms_t getEngineCycleDuration(int rpm) { floatms_t getEngineCycleDuration(int rpm) {
return getCrankshaftRevolutionTimeMs(rpm) * (engine->getOperationMode() == TWO_STROKE ? 1 : 2); return getCrankshaftRevolutionTimeMs(rpm) * (getEngineRotationState()->getOperationMode() == TWO_STROKE ? 1 : 2);
} }
/** /**
@ -433,7 +433,7 @@ ignition_mode_e getCurrentIgnitionMode() {
* This heavy method is only invoked in case of a configuration change or initialization. * This heavy method is only invoked in case of a configuration change or initialization.
*/ */
void prepareOutputSignals() { void prepareOutputSignals() {
getEngineState()->engineCycle = getEngineCycle(engine->getOperationMode()); getEngineState()->engineCycle = getEngineCycle(getEngineRotationState()->getOperationMode());
#if EFI_UNIT_TEST #if EFI_UNIT_TEST
if (verboseMode) { if (verboseMode) {

View File

@ -95,7 +95,7 @@ void printConfiguration(const engine_configuration_s *engineConfiguration) {
efiPrintf("configurationVersion=%d", engine->getGlobalConfigurationVersion()); efiPrintf("configurationVersion=%d", engine->getGlobalConfigurationVersion());
efiPrintf("rpmHardLimit: %d/operationMode=%d", engineConfiguration->rpmHardLimit, efiPrintf("rpmHardLimit: %d/operationMode=%d", engineConfiguration->rpmHardLimit,
engine->getOperationMode()); getEngineRotationState()->getOperationMode());
efiPrintf("globalTriggerAngleOffset=%.2f", engineConfiguration->globalTriggerAngleOffset); efiPrintf("globalTriggerAngleOffset=%.2f", engineConfiguration->globalTriggerAngleOffset);

View File

@ -124,7 +124,7 @@ static bool vvtWithRealDecoder(vvt_mode_e vvtMode) {
} }
static angle_t syncAndReport(TriggerCentral *tc, int divider, int remainder) { static angle_t syncAndReport(TriggerCentral *tc, int divider, int remainder) {
angle_t engineCycle = getEngineCycle(engine->getOperationMode()); angle_t engineCycle = getEngineCycle(getEngineRotationState()->getOperationMode());
return tc->triggerState.syncEnginePhase(divider, remainder, engineCycle); return tc->triggerState.syncEnginePhase(divider, remainder, engineCycle);
} }
@ -155,7 +155,7 @@ static angle_t adjustCrankPhase(int camIndex) {
} }
TriggerCentral *tc = &engine->triggerCentral; TriggerCentral *tc = &engine->triggerCentral;
operation_mode_e operationMode = engine->getOperationMode(); operation_mode_e operationMode = getEngineRotationState()->getOperationMode();
vvt_mode_e vvtMode = engineConfiguration->vvtMode[camIndex]; vvt_mode_e vvtMode = engineConfiguration->vvtMode[camIndex];
switch (vvtMode) { switch (vvtMode) {

View File

@ -93,7 +93,7 @@ void setTriggerEmulatorRPM(int rpm) {
if (rpm == 0) { if (rpm == 0) {
triggerSignal.setFrequency(NAN); triggerSignal.setFrequency(NAN);
} else { } else {
float rpmM = getRpmMultiplier(engine->getOperationMode()); float rpmM = getRpmMultiplier(getEngineRotationState()->getOperationMode());
float rPerSecond = rpm * rpmM / 60.0; // per minute converted to per second float rPerSecond = rpm * rpmM / 60.0; // per minute converted to per second
triggerSignal.setFrequency(rPerSecond); triggerSignal.setFrequency(rPerSecond);
} }

View File

@ -50,7 +50,7 @@ TEST(engine, testSymmetricalCrank) {
engineConfiguration->isFasterEngineSpinUpEnabled = false; engineConfiguration->isFasterEngineSpinUpEnabled = false;
engineConfiguration->alwaysInstantRpm = true; engineConfiguration->alwaysInstantRpm = true;
ASSERT_EQ(FOUR_STROKE_SYMMETRICAL_CRANK_SENSOR, engine->getOperationMode()); ASSERT_EQ(FOUR_STROKE_SYMMETRICAL_CRANK_SENSOR, getEngineRotationState()->getOperationMode());
float mult = 0.02; float mult = 0.02;