RPM refactoring

This commit is contained in:
rusefi 2017-07-06 20:10:34 -04:00
parent a98b5d87cd
commit 63a8586503
1 changed files with 18 additions and 18 deletions

View File

@ -38,8 +38,6 @@ extern WaveChart waveChart;
EXTERN_ENGINE EXTERN_ENGINE
; ;
efitime_t notRunnintNow;
efitime_t notRunningPrev;
extern bool hasFirmwareErrorFlag; extern bool hasFirmwareErrorFlag;
static Logging * logger; static Logging * logger;
@ -78,30 +76,35 @@ bool RpmCalculator::isCranking(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
* @return true if there was a full shaft revolution within the last second * @return true if there was a full shaft revolution within the last second
*/ */
bool RpmCalculator::isRunning(DECLARE_ENGINE_PARAMETER_SIGNATURE) { bool RpmCalculator::isRunning(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
return checkIfSpinning(PASS_ENGINE_PARAMETER_SIGNATURE);
}
bool RpmCalculator::checkIfSpinning(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
if (lastRpmEventTimeNt == 0) {
// here we assume 64 bit time does not overflow
// zero value is the default meaning no RPM events since reboot
return false;
}
efitick_t nowNt = getTimeNowNt(); efitick_t nowNt = getTimeNowNt();
if (ENGINE(stopEngineRequestTimeNt) != 0) { if (ENGINE(stopEngineRequestTimeNt) != 0) {
if (nowNt - ENGINE(stopEngineRequestTimeNt) < 3 * US2NT(US_PER_SECOND_LL)) { if (nowNt - ENGINE(stopEngineRequestTimeNt) < 3 * US2NT(US_PER_SECOND_LL)) {
// 'stopengine' command implementation
setStopped(PASS_ENGINE_PARAMETER_SIGNATURE);
return false; return false;
} }
} }
if (lastRpmEventTimeNt == 0) {
// here we assume 64 bit time does not overflow, zero value is the default meaning no events so far
return false;
}
/** /**
* note that the result of this subtraction could be negative, that would happen if * note that the result of this subtraction could be negative, that would happen if
* we have a trigger event between the time we've invoked 'getTimeNow' and here * we have a trigger event between the time we've invoked 'getTimeNow' and here
*/ */
bool result = nowNt - lastRpmEventTimeNt < US2NT(2 * US_PER_SECOND_LL); // Anything below 60 rpm is not running bool noEventsForTooLong = nowNt - lastRpmEventTimeNt < US2NT(2 * US_PER_SECOND_LL); // Anything below 60 rpm is not running
if (!result) { if (noEventsForTooLong) {
notRunnintNow = nowNt; setStopped(PASS_ENGINE_PARAMETER_SIGNATURE);
notRunningPrev = lastRpmEventTimeNt; return false;
} }
return result;
}
bool RpmCalculator::checkIfSpinning(DECLARE_ENGINE_PARAMETER_SIGNATURE) { return true;
return false;
} }
// private method // private method
@ -150,10 +153,7 @@ void RpmCalculator::setStopped(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
revolutionCounterSinceStart = 0; revolutionCounterSinceStart = 0;
if (rpmValue != 0) { if (rpmValue != 0) {
rpmValue = 0; rpmValue = 0;
scheduleMsg(logger, scheduleMsg(logger, "engine stopped");
"templog rpm=0 since not running [%x][%x] [%x][%x]",
(int) (notRunnintNow >> 32), (int) notRunnintNow,
(int) (notRunningPrev >> 32), (int) notRunningPrev);
} }
} }