refactoring: encapsulation
This commit is contained in:
parent
f3d8be9ed1
commit
baaec6a603
|
@ -416,14 +416,18 @@ void Engine::efiWatchdog() {
|
|||
void Engine::checkShutdown() {
|
||||
#if EFI_MAIN_RELAY_CONTROL
|
||||
// if we are already in the "ignition_on" mode, then do nothing
|
||||
/* this logic is not alive
|
||||
if (ignitionOnTimeNt > 0) {
|
||||
return;
|
||||
}
|
||||
todo: move to shutdown_controller.cpp
|
||||
*/
|
||||
|
||||
// here we are in the shutdown (the ignition is off) or initial mode (after the firmware fresh start)
|
||||
const efitick_t engineStopWaitTimeoutUs = 500000LL; // 0.5 sec
|
||||
// in shutdown mode, we need a small cooldown time between the ignition off and on
|
||||
/* this needs work or tests
|
||||
todo: move to shutdown_controller.cpp
|
||||
if (stopEngineRequestTimeNt == 0 || (getTimeNowNt() - stopEngineRequestTimeNt) > US2NT(engineStopWaitTimeoutUs)) {
|
||||
// if the ignition key is turned on again,
|
||||
// we cancel the shutdown mode, but only if all shutdown procedures are complete
|
||||
|
@ -518,18 +522,6 @@ void Engine::periodicFastCallback() {
|
|||
engine->engineModules.apply_all([](auto & m) { m.onFastCallback(); });
|
||||
}
|
||||
|
||||
void doScheduleStopEngine() {
|
||||
efiPrintf("Starting doScheduleStopEngine");
|
||||
engine->limpManager.stopEngine();
|
||||
engine->ignitionOnTimeNt = 0;
|
||||
// todo: initiate stepper motor parking
|
||||
// make sure we have stored all the info
|
||||
#if EFI_PROD_CODE
|
||||
//todo: FIX kinetis build with this line
|
||||
//backupRamFlush();
|
||||
#endif // EFI_PROD_CODE
|
||||
}
|
||||
|
||||
EngineRotationState * getEngineRotationState() {
|
||||
return &engine->rpmCalculator;
|
||||
}
|
||||
|
|
|
@ -231,11 +231,6 @@ public:
|
|||
bool startStopState = false;
|
||||
int startStopStateToggleCounter = 0;
|
||||
|
||||
/**
|
||||
* this is needed by and checkShutdown()
|
||||
* todo: refactor to Timer?
|
||||
*/
|
||||
efitick_t ignitionOnTimeNt = 0;
|
||||
|
||||
Timer configBurnTimer;
|
||||
|
||||
|
@ -329,7 +324,6 @@ void applyNonPersistentConfiguration();
|
|||
void prepareOutputSignals();
|
||||
|
||||
void validateConfiguration();
|
||||
void doScheduleStopEngine();
|
||||
void scheduleReboot();
|
||||
bool isLockedFromUser();
|
||||
void unlockEcu(int password);
|
||||
|
|
|
@ -213,6 +213,7 @@ angle_t getInjectionOffset(float rpm, float load) {
|
|||
|
||||
if (cisnan(value)) {
|
||||
// we could be here while resetting configuration for example
|
||||
// huh? what? when do we have RPM while resetting configuration? is that CI edge case? shall we fix CI?
|
||||
warning(CUSTOM_ERR_6569, "phase map not ready");
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -65,6 +65,7 @@ CONTROLLERS_SRC_CPP = \
|
|||
$(CONTROLLERS_DIR)/tcu/gear_controller.cpp \
|
||||
$(CONTROLLERS_DIR)/tcu/simple_tcu.cpp \
|
||||
$(CONTROLLERS_DIR)/tcu/tc_4l6x.cpp \
|
||||
$(CONTROLLERS_DIR)/shutdown_controller.cpp \
|
||||
$(CONTROLLERS_DIR)/limp_manager.cpp \
|
||||
|
||||
CONTROLLERS_INC=\
|
||||
|
|
|
@ -82,7 +82,7 @@ bool RpmCalculator::isRunning() const {
|
|||
* @return true if engine is spinning (cranking or running)
|
||||
*/
|
||||
bool RpmCalculator::checkIfSpinning(efitick_t nowNt) const {
|
||||
if (engine->limpManager.isEngineStop(nowNt)) {
|
||||
if (engine->limpManager.shutdownController.isEngineStop(nowNt)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -112,7 +112,7 @@ void LimpManager::updateState(int rpm, efitick_t nowNt) {
|
|||
}
|
||||
|
||||
// If we're in engine stop mode, inhibit fuel
|
||||
if (isEngineStop(nowNt)) {
|
||||
if (shutdownController.isEngineStop(nowNt)) {
|
||||
/**
|
||||
* todo: we need explicit clarification on why do we cut fuel but do not cut spark here!
|
||||
*/
|
||||
|
@ -173,21 +173,6 @@ void LimpManager::fatalError() {
|
|||
setFaultRevLimit(0);
|
||||
}
|
||||
|
||||
void LimpManager::stopEngine() {
|
||||
m_engineStopTimer.reset();
|
||||
}
|
||||
|
||||
bool LimpManager::isEngineStop(efitick_t nowNt) const {
|
||||
float timeSinceStop = getTimeSinceEngineStop(nowNt);
|
||||
|
||||
// If there was stop requested in the past 5 seconds, we're in stop mode
|
||||
return timeSinceStop < 5;
|
||||
}
|
||||
|
||||
float LimpManager::getTimeSinceEngineStop(efitick_t nowNt) const {
|
||||
return m_engineStopTimer.getElapsedSeconds(nowNt);
|
||||
}
|
||||
|
||||
void LimpManager::setFaultRevLimit(int limit) {
|
||||
// Only allow decreasing the limit
|
||||
// aka uses the limit of the worst fault to yet occur
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include "rusefi_types.h"
|
||||
#include "shutdown_controller.h"
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
|
@ -22,6 +22,7 @@ enum class ClearReason : uint8_t {
|
|||
KickStart, // 13
|
||||
|
||||
// Keep this list in sync with fuelIgnCutCodeList in rusefi.input!
|
||||
// todo: add a code generator between ClearReason and fuelIgnCutCodeList in rusefi.input
|
||||
};
|
||||
|
||||
// Only allows clearing the value, but never resetting it.
|
||||
|
@ -79,6 +80,8 @@ private:
|
|||
|
||||
class LimpManager {
|
||||
public:
|
||||
ShutdownController shutdownController;
|
||||
|
||||
// This is called from periodicFastCallback to update internal state
|
||||
void updateState(int rpm, efitick_t nowNt);
|
||||
|
||||
|
@ -93,10 +96,6 @@ public:
|
|||
// Other subsystems call these APIs to indicate a problem has occured
|
||||
void etbProblem();
|
||||
void fatalError();
|
||||
void stopEngine();
|
||||
|
||||
bool isEngineStop(efitick_t nowNt) const;
|
||||
float getTimeSinceEngineStop(efitick_t nowNt) const;
|
||||
|
||||
private:
|
||||
void setFaultRevLimit(int limit);
|
||||
|
@ -117,8 +116,6 @@ private:
|
|||
Clearable m_transientAllowIgnition = true;
|
||||
|
||||
bool m_hadOilPressureAfterStart = false;
|
||||
|
||||
Timer m_engineStopTimer;
|
||||
};
|
||||
|
||||
LimpManager * getLimpManager();
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
/*
|
||||
* @file shutdown_controller.cpp
|
||||
*
|
||||
*/
|
||||
|
||||
#include "shutdown_controller.h"
|
||||
#include "loggingcentral.h"
|
||||
#include "limp_manager.h"
|
||||
|
||||
void doScheduleStopEngine() {
|
||||
efiPrintf("Starting doScheduleStopEngine");
|
||||
getLimpManager()->shutdownController.stopEngine();
|
||||
// todo: initiate stepper motor parking
|
||||
// make sure we have stored all the info
|
||||
#if EFI_PROD_CODE
|
||||
//todo: FIX kinetis build with this line
|
||||
//backupRamFlush();
|
||||
#endif // EFI_PROD_CODE
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
/*
|
||||
* @file shutdown_controller.h
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "timer.h"
|
||||
|
||||
void doScheduleStopEngine();
|
||||
|
||||
class ShutdownController {
|
||||
public:
|
||||
void stopEngine() {
|
||||
m_engineStopTimer.reset();
|
||||
// ignitionOnTimeNt = 0;
|
||||
}
|
||||
|
||||
float getTimeSinceEngineStop(efitick_t nowNt) const {
|
||||
return m_engineStopTimer.getElapsedSeconds(nowNt);
|
||||
}
|
||||
|
||||
bool isEngineStop(efitick_t nowNt) const {
|
||||
float timeSinceStop = getTimeSinceEngineStop(nowNt);
|
||||
|
||||
// If there was stop requested in the past 5 seconds, we're in stop mode
|
||||
return timeSinceStop < 5;
|
||||
}
|
||||
|
||||
private:
|
||||
Timer m_engineStopTimer;
|
||||
|
||||
/**
|
||||
* this is needed by and checkShutdown()
|
||||
*/
|
||||
// is this an unused boolean value?
|
||||
// efitick_t ignitionOnTimeNt = 0;
|
||||
};
|
Loading…
Reference in New Issue