auto-sync

This commit is contained in:
rusEfi 2016-03-15 22:03:43 -04:00
parent e48ad09286
commit 3e7cbbefe8
3 changed files with 20 additions and 6 deletions

View File

@ -48,7 +48,7 @@ RpmCalculator::RpmCalculator() {
mockRpm = MOCK_UNDEFINED; mockRpm = MOCK_UNDEFINED;
#endif #endif
rpmValue = 0; rpmValue = 0;
setRpmValue(0); assignRpmValue(0);
// we need this initial to have not_running at first invocation // we need this initial to have not_running at first invocation
lastRpmEventTimeNt = (efitime_t) -10 * US2NT(US_PER_SECOND_LL); lastRpmEventTimeNt = (efitime_t) -10 * US2NT(US_PER_SECOND_LL);
@ -82,7 +82,9 @@ bool RpmCalculator::isRunning(DECLARE_ENGINE_PARAMETER_F) {
return result; return result;
} }
void RpmCalculator::setRpmValue(int value) {
// private method
void RpmCalculator::assignRpmValue(int value) {
previousRpmValue = rpmValue; previousRpmValue = rpmValue;
rpmValue = value; rpmValue = value;
if (rpmValue <= 0) { if (rpmValue <= 0) {
@ -92,6 +94,17 @@ void RpmCalculator::setRpmValue(int value) {
} }
} }
void RpmCalculator::setRpmValue(int value DECLARE_ENGINE_PARAMETER_S) {
assignRpmValue(value);
if (previousRpmValue == 0 && rpmValue > 0) {
/**
* this would make sure that we have good numbers for first cranking revolution
* #275 cranking could be improved
*/
engine->periodicFastCallback(PASS_ENGINE_PARAMETER_F);
}
}
void RpmCalculator::onNewEngineCycle() { void RpmCalculator::onNewEngineCycle() {
revolutionCounterSinceBoot++; revolutionCounterSinceBoot++;
revolutionCounterSinceStart++; revolutionCounterSinceStart++;
@ -194,11 +207,11 @@ void rpmShaftPositionCallback(trigger_event_e ckpSignalType,
* *
*/ */
if (diffNt == 0) { if (diffNt == 0) {
rpmState->setRpmValue(NOISY_RPM); rpmState->setRpmValue(NOISY_RPM PASS_ENGINE_PARAMETER);
} else { } else {
int mult = getEngineCycle(engineConfiguration->operationMode) / 360; int mult = getEngineCycle(engineConfiguration->operationMode) / 360;
int rpm = (int) (60 * US2NT(US_PER_SECOND_LL) * mult / diffNt); int rpm = (int) (60 * US2NT(US_PER_SECOND_LL) * mult / diffNt);
rpmState->setRpmValue(rpm > UNREALISTIC_RPM ? NOISY_RPM : rpm); rpmState->setRpmValue(rpm > UNREALISTIC_RPM ? NOISY_RPM : rpm PASS_ENGINE_PARAMETER);
} }
} }
rpmState->onNewEngineCycle(); rpmState->onNewEngineCycle();

View File

@ -47,7 +47,7 @@ public:
*/ */
void onNewEngineCycle(); void onNewEngineCycle();
uint32_t getRevolutionCounter(void); uint32_t getRevolutionCounter(void);
void setRpmValue(int value); void setRpmValue(int value DECLARE_ENGINE_PARAMETER_S);
uint32_t getRevolutionCounterSinceStart(void); uint32_t getRevolutionCounterSinceStart(void);
float getRpmAcceleration(); float getRpmAcceleration();
/** /**
@ -62,6 +62,7 @@ public:
volatile floatus_t oneDegreeUs; volatile floatus_t oneDegreeUs;
volatile efitime_t lastRpmEventTimeNt; volatile efitime_t lastRpmEventTimeNt;
private: private:
void assignRpmValue(int value);
/** /**
* This counter is incremented with each revolution of one of the shafts. Could be * This counter is incremented with each revolution of one of the shafts. Could be
* crankshaft could be camshaft. * crankshaft could be camshaft.

View File

@ -18,7 +18,7 @@ void testAccelEnrichment(void) {
EngineTestHelper eth(FORD_ASPIRE_1996); EngineTestHelper eth(FORD_ASPIRE_1996);
EXPAND_EngineTestHelper; EXPAND_EngineTestHelper;
engine->rpmCalculator.setRpmValue(600); engine->rpmCalculator.setRpmValue(600 PASS_ENGINE_PARAMETER);
engine->periodicFastCallback(PASS_ENGINE_PARAMETER_F); engine->periodicFastCallback(PASS_ENGINE_PARAMETER_F);
assertEqualsM("eventsCount", 4, engine->engineConfiguration2->injectionEvents->eventsCount); assertEqualsM("eventsCount", 4, engine->engineConfiguration2->injectionEvents->eventsCount);