refactoring around "stopEngine" logic
This commit is contained in:
parent
aced64810f
commit
5b74163136
|
@ -116,6 +116,15 @@ Engine::Engine(persistent_config_s *config) {
|
|||
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() {
|
||||
withError = isEngineChartEnabled = false;
|
||||
etbAutoTune = false;
|
||||
|
@ -270,9 +279,13 @@ void Engine::checkShutdown() {
|
|||
#if EFI_MAIN_RELAY_CONTROL || defined(__DOXYGEN__)
|
||||
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;
|
||||
if (isValidRpm(rpm) && sensors.vBatt < vBattThreshold && stopEngineRequestTimeNt == 0) {
|
||||
stopEngine();
|
||||
scheduleStopEngine();
|
||||
// todo: add stepper motor parking
|
||||
}
|
||||
#endif /* EFI_MAIN_RELAY_CONTROL */
|
||||
|
|
|
@ -304,7 +304,7 @@ public:
|
|||
float fsioLastValue[FSIO_COMMAND_COUNT];
|
||||
|
||||
WallFuel wallFuel;
|
||||
|
||||
bool needToStopEngine(efitick_t nowNt);
|
||||
bool etbAutoTune;
|
||||
/**
|
||||
* That's the list of pending spark firing events
|
||||
|
|
|
@ -258,7 +258,7 @@ void runIoTest(int subsystem, int index) {
|
|||
// call to pit
|
||||
setCallFromPitStop(30000);
|
||||
} 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 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 miTestFuelPump(&miBench, "test pump", fuelPumpBench);
|
||||
static MenuItem miTestMIL(&miBench, "test MIL", milBench);
|
||||
|
|
|
@ -970,7 +970,11 @@ static void disableSpi(int index) {
|
|||
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();
|
||||
// let's close injectors or else if these happen to be open right now
|
||||
enginePins.stopPins();
|
||||
|
@ -1339,7 +1343,7 @@ void initSettings(void) {
|
|||
|
||||
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
|
||||
addConsoleActionI("enable_spi", enableSpi);
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
void initSettings(void);
|
||||
void printSpiState(Logging *logger, board_configuration_s *boardConfiguration);
|
||||
void printConfiguration(const engine_configuration_s *engineConfiguration);
|
||||
void stopEngine(void);
|
||||
void scheduleStopEngine(void);
|
||||
void setCallFromPitStop(int durationMs);
|
||||
void setEngineType(int value);
|
||||
/**
|
||||
|
|
|
@ -90,6 +90,9 @@ bool RpmCalculator::isRunning(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
|||
return state == RUNNING;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if engine is spinning (cranking or running)
|
||||
*/
|
||||
bool RpmCalculator::checkIfSpinning(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
||||
if (lastRpmEventTimeNt == 0) {
|
||||
// here we assume 64 bit time does not overflow
|
||||
|
@ -97,12 +100,9 @@ bool RpmCalculator::checkIfSpinning(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
|||
return false;
|
||||
}
|
||||
efitick_t nowNt = getTimeNowNt();
|
||||
if (ENGINE(stopEngineRequestTimeNt) != 0) {
|
||||
if (nowNt - ENGINE(stopEngineRequestTimeNt) < 3 * US2NT(US_PER_SECOND_LL)) {
|
||||
// 'stopengine' command implementation
|
||||
setStopped(PASS_ENGINE_PARAMETER_SIGNATURE);
|
||||
return false;
|
||||
}
|
||||
if (ENGINE(needToStopEngine(nowNt))) {
|
||||
setStopped(PASS_ENGINE_PARAMETER_SIGNATURE);
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue