refactoring around "stopEngine" logic
This commit is contained in:
parent
aced64810f
commit
5b74163136
|
@ -116,6 +116,15 @@ Engine::Engine(persistent_config_s *config) {
|
||||||
reset();
|
reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see scheduleStopEngine()
|
||||||
|
* @return true if there is a reason to stop engine
|
||||||
|
*/
|
||||||
|
bool Engine::needToStopEngine(efitick_t nowNt) {
|
||||||
|
return stopEngineRequestTimeNt != 0 &&
|
||||||
|
nowNt - stopEngineRequestTimeNt < 3 * US2NT(US_PER_SECOND_LL);
|
||||||
|
}
|
||||||
|
|
||||||
void Engine::reset() {
|
void Engine::reset() {
|
||||||
withError = isEngineChartEnabled = false;
|
withError = isEngineChartEnabled = false;
|
||||||
etbAutoTune = false;
|
etbAutoTune = false;
|
||||||
|
@ -270,9 +279,13 @@ void Engine::checkShutdown() {
|
||||||
#if EFI_MAIN_RELAY_CONTROL || defined(__DOXYGEN__)
|
#if EFI_MAIN_RELAY_CONTROL || defined(__DOXYGEN__)
|
||||||
int rpm = rpmCalculator.getRpm();
|
int rpm = rpmCalculator.getRpm();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Something is weird here: "below 5.0 volts on battery" what is it about? Is this about
|
||||||
|
* Frankenso powering everything while driver has already turned ignition off? or what is this condition about?
|
||||||
|
*/
|
||||||
const float vBattThreshold = 5.0f;
|
const float vBattThreshold = 5.0f;
|
||||||
if (isValidRpm(rpm) && sensors.vBatt < vBattThreshold && stopEngineRequestTimeNt == 0) {
|
if (isValidRpm(rpm) && sensors.vBatt < vBattThreshold && stopEngineRequestTimeNt == 0) {
|
||||||
stopEngine();
|
scheduleStopEngine();
|
||||||
// todo: add stepper motor parking
|
// todo: add stepper motor parking
|
||||||
}
|
}
|
||||||
#endif /* EFI_MAIN_RELAY_CONTROL */
|
#endif /* EFI_MAIN_RELAY_CONTROL */
|
||||||
|
|
|
@ -304,7 +304,7 @@ public:
|
||||||
float fsioLastValue[FSIO_COMMAND_COUNT];
|
float fsioLastValue[FSIO_COMMAND_COUNT];
|
||||||
|
|
||||||
WallFuel wallFuel;
|
WallFuel wallFuel;
|
||||||
|
bool needToStopEngine(efitick_t nowNt);
|
||||||
bool etbAutoTune;
|
bool etbAutoTune;
|
||||||
/**
|
/**
|
||||||
* That's the list of pending spark firing events
|
* That's the list of pending spark firing events
|
||||||
|
|
|
@ -258,7 +258,7 @@ void runIoTest(int subsystem, int index) {
|
||||||
// call to pit
|
// call to pit
|
||||||
setCallFromPitStop(30000);
|
setCallFromPitStop(30000);
|
||||||
} else if (subsystem == 0x99) {
|
} else if (subsystem == 0x99) {
|
||||||
stopEngine();
|
scheduleStopEngine();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -75,7 +75,7 @@ static MenuItem miMapV(&miSensors, LL_MAF_V);
|
||||||
static MenuItem miMapKgHr(&miSensors, LL_MAF_KG_HR);
|
static MenuItem miMapKgHr(&miSensors, LL_MAF_KG_HR);
|
||||||
static MenuItem miKnock(&miSensors, LL_KNOCK);
|
static MenuItem miKnock(&miSensors, LL_KNOCK);
|
||||||
|
|
||||||
static MenuItem miStopEngine(&miBench, "stop engine", stopEngine);
|
static MenuItem miStopEngine(&miBench, "stop engine", scheduleStopEngine);
|
||||||
static MenuItem miTestFan(&miBench, "test fan", fanBench);
|
static MenuItem miTestFan(&miBench, "test fan", fanBench);
|
||||||
static MenuItem miTestFuelPump(&miBench, "test pump", fuelPumpBench);
|
static MenuItem miTestFuelPump(&miBench, "test pump", fuelPumpBench);
|
||||||
static MenuItem miTestMIL(&miBench, "test MIL", milBench);
|
static MenuItem miTestMIL(&miBench, "test MIL", milBench);
|
||||||
|
|
|
@ -970,7 +970,11 @@ static void disableSpi(int index) {
|
||||||
setSpiMode(index, false);
|
setSpiMode(index, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void stopEngine(void) {
|
/**
|
||||||
|
* See 'Engine::needToStopEngine' for code which actually stops engine
|
||||||
|
* weird: we stop pins from here? we probably should stop engine from the code which is actually stopping engine?
|
||||||
|
*/
|
||||||
|
void scheduleStopEngine(void) {
|
||||||
engine->stopEngineRequestTimeNt = getTimeNowNt();
|
engine->stopEngineRequestTimeNt = getTimeNowNt();
|
||||||
// let's close injectors or else if these happen to be open right now
|
// let's close injectors or else if these happen to be open right now
|
||||||
enginePins.stopPins();
|
enginePins.stopPins();
|
||||||
|
@ -1339,7 +1343,7 @@ void initSettings(void) {
|
||||||
|
|
||||||
addConsoleActionSSS("set_timing_map", setTimingMap);
|
addConsoleActionSSS("set_timing_map", setTimingMap);
|
||||||
|
|
||||||
addConsoleAction("stopengine", (Void) stopEngine);
|
addConsoleAction("stopengine", (Void) scheduleStopEngine);
|
||||||
|
|
||||||
// todo: refactor this - looks like all boolean flags should be controlled with less code duplication
|
// todo: refactor this - looks like all boolean flags should be controlled with less code duplication
|
||||||
addConsoleActionI("enable_spi", enableSpi);
|
addConsoleActionI("enable_spi", enableSpi);
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
void initSettings(void);
|
void initSettings(void);
|
||||||
void printSpiState(Logging *logger, board_configuration_s *boardConfiguration);
|
void printSpiState(Logging *logger, board_configuration_s *boardConfiguration);
|
||||||
void printConfiguration(const engine_configuration_s *engineConfiguration);
|
void printConfiguration(const engine_configuration_s *engineConfiguration);
|
||||||
void stopEngine(void);
|
void scheduleStopEngine(void);
|
||||||
void setCallFromPitStop(int durationMs);
|
void setCallFromPitStop(int durationMs);
|
||||||
void setEngineType(int value);
|
void setEngineType(int value);
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -90,6 +90,9 @@ bool RpmCalculator::isRunning(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
||||||
return state == RUNNING;
|
return state == RUNNING;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return true if engine is spinning (cranking or running)
|
||||||
|
*/
|
||||||
bool RpmCalculator::checkIfSpinning(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
bool RpmCalculator::checkIfSpinning(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
||||||
if (lastRpmEventTimeNt == 0) {
|
if (lastRpmEventTimeNt == 0) {
|
||||||
// here we assume 64 bit time does not overflow
|
// here we assume 64 bit time does not overflow
|
||||||
|
@ -97,13 +100,10 @@ bool RpmCalculator::checkIfSpinning(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
efitick_t nowNt = getTimeNowNt();
|
efitick_t nowNt = getTimeNowNt();
|
||||||
if (ENGINE(stopEngineRequestTimeNt) != 0) {
|
if (ENGINE(needToStopEngine(nowNt))) {
|
||||||
if (nowNt - ENGINE(stopEngineRequestTimeNt) < 3 * US2NT(US_PER_SECOND_LL)) {
|
|
||||||
// 'stopengine' command implementation
|
|
||||||
setStopped(PASS_ENGINE_PARAMETER_SIGNATURE);
|
setStopped(PASS_ENGINE_PARAMETER_SIGNATURE);
|
||||||
return false;
|
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
|
||||||
|
|
Loading…
Reference in New Issue