migrating to SensorType::Rpm API

This commit is contained in:
Andrey 2022-01-20 22:12:04 -05:00
parent 5feab6f6c3
commit 9f08db256b
3 changed files with 7 additions and 7 deletions

View File

@ -114,7 +114,7 @@ void EngineState::periodicFastCallback() {
} }
recalculateAuxValveTiming(); recalculateAuxValveTiming();
int rpm = engine->rpmCalculator.getRpm(); int rpm = Sensor::getOrZero(SensorType::Rpm);
sparkDwell = getSparkDwell(rpm); sparkDwell = getSparkDwell(rpm);
dwellAngle = cisnan(rpm) ? NAN : sparkDwell / getOneDegreeTimeMs(rpm); dwellAngle = cisnan(rpm) ? NAN : sparkDwell / getOneDegreeTimeMs(rpm);

View File

@ -38,7 +38,7 @@ TEST(fuelCut, coasting) {
// mock TPS - throttle is opened // mock TPS - throttle is opened
Sensor::setMockValue(SensorType::Tps1, 60); Sensor::setMockValue(SensorType::Tps1, 60);
// set 'running' RPM - just above RpmHigh threshold // set 'running' RPM - just above RpmHigh threshold
engine->rpmCalculator.mockRpm = engineConfiguration->coastingFuelCutRpmHigh + 1; Sensor::setMockValue(SensorType::Rpm, engineConfiguration->coastingFuelCutRpmHigh + 1);
// 'advance' time (amount doesn't matter) // 'advance' time (amount doesn't matter)
eth.moveTimeForwardUs(1000); eth.moveTimeForwardUs(1000);
@ -70,28 +70,28 @@ TEST(fuelCut, coasting) {
// restore CLT // restore CLT
Sensor::setMockValue(SensorType::Clt, hotClt); Sensor::setMockValue(SensorType::Clt, hotClt);
// And set RPM - somewhere between RpmHigh and RpmLow threshold // And set RPM - somewhere between RpmHigh and RpmLow threshold
engine->rpmCalculator.mockRpm = (engineConfiguration->coastingFuelCutRpmHigh + engineConfiguration->coastingFuelCutRpmLow) / 2; Sensor::setMockValue(SensorType::Rpm, (engineConfiguration->coastingFuelCutRpmHigh + engineConfiguration->coastingFuelCutRpmLow) / 2);
eth.engine.periodicFastCallback(); eth.engine.periodicFastCallback();
// Fuel cut-off is enabled - nothing should change // Fuel cut-off is enabled - nothing should change
assertEqualsM("inj dur#4 mid", normalInjDuration, engine->injectionDuration); assertEqualsM("inj dur#4 mid", normalInjDuration, engine->injectionDuration);
// Now drop RPM just below RpmLow threshold // Now drop RPM just below RpmLow threshold
engine->rpmCalculator.mockRpm = engineConfiguration->coastingFuelCutRpmLow - 1; Sensor::setMockValue(SensorType::Rpm, engineConfiguration->coastingFuelCutRpmLow - 1);
eth.engine.periodicFastCallback(); eth.engine.periodicFastCallback();
// Fuel cut-off is now disabled (the engine is idling) // Fuel cut-off is now disabled (the engine is idling)
assertEqualsM("inj dur#5 idle", normalInjDuration, engine->injectionDuration); assertEqualsM("inj dur#5 idle", normalInjDuration, engine->injectionDuration);
// Now change RPM just below RpmHigh threshold // Now change RPM just below RpmHigh threshold
engine->rpmCalculator.mockRpm = engineConfiguration->coastingFuelCutRpmHigh - 1; Sensor::setMockValue(SensorType::Rpm, engineConfiguration->coastingFuelCutRpmHigh - 1);
eth.engine.periodicFastCallback(); eth.engine.periodicFastCallback();
// Fuel cut-off is still disabled // Fuel cut-off is still disabled
assertEqualsM("inj dur#6 mid", normalInjDuration, engine->injectionDuration); assertEqualsM("inj dur#6 mid", normalInjDuration, engine->injectionDuration);
// Now set RPM just above RpmHigh threshold // Now set RPM just above RpmHigh threshold
engine->rpmCalculator.mockRpm = engineConfiguration->coastingFuelCutRpmHigh + 1; Sensor::setMockValue(SensorType::Rpm, engineConfiguration->coastingFuelCutRpmHigh + 1);
eth.engine.periodicFastCallback(); eth.engine.periodicFastCallback();
// Fuel cut-off is active again! // Fuel cut-off is active again!

View File

@ -67,7 +67,7 @@ TEST(misc, testEngineMath) {
Sensor::setMockValue(SensorType::Iat, 20); Sensor::setMockValue(SensorType::Iat, 20);
Sensor::setMockValue(SensorType::Map, 100); Sensor::setMockValue(SensorType::Map, 100);
Sensor::setMockValue(SensorType::Tps1, 0); Sensor::setMockValue(SensorType::Tps1, 0);
engine->rpmCalculator.mockRpm = 1000; Sensor::setMockValue(SensorType::Rpm, 1000);
// calc. airFlow using airMass, and find tCharge // calc. airFlow using airMass, and find tCharge
engine->periodicFastCallback(); engine->periodicFastCallback();