tear down Engine god object #4511

just trying different things
This commit is contained in:
Andrey 2022-09-05 02:28:46 -04:00
parent 4bfd39665b
commit 1983a07078
4 changed files with 26 additions and 2 deletions

View File

@ -631,3 +631,9 @@ void doScheduleStopEngine() {
//backupRamFlush();
#endif // EFI_PROD_CODE
}
EngineRotationState * getEngineRotationState() {
return &engine->rpmCalculator;
}

View File

@ -55,7 +55,7 @@ InjectionEvent::InjectionEvent() {
// Returns the start angle of this injector in engine coordinates (0-720 for a 4 stroke),
// or unexpected if unable to calculate the start angle due to missing information.
expected<float> InjectionEvent::computeInjectionAngle(int cylinderIndex) const {
floatus_t oneDegreeUs = engine->rpmCalculator.oneDegreeUs; // local copy
floatus_t oneDegreeUs = getEngineRotationState()->getOneDegreeUs(); // local copy
if (cisnan(oneDegreeUs)) {
// in order to have fuel schedule we need to have current RPM
// wonder if this line slows engine startup?

View File

@ -11,6 +11,7 @@
#include "scheduler.h"
#include "stored_value_sensor.h"
#include "timer.h"
#include "rpm_calculator_api.h"
// we use this value in case of noise on trigger input lines
#define NOISY_RPM -1
@ -39,7 +40,7 @@ typedef enum {
/**
* Most consumers should access value via Sensor framework by SensorType::Rpm key
*/
class RpmCalculator : public StoredValueSensor {
class RpmCalculator : public StoredValueSensor, public EngineRotationState {
public:
RpmCalculator();
@ -109,12 +110,17 @@ public:
* this is RPM on previous engine cycle.
*/
int previousRpmValue = 0;
/**
* This is a performance optimization: let's pre-calculate this each time RPM changes
* NaN while engine is not spinning
*/
volatile floatus_t oneDegreeUs = NAN;
floatus_t getOneDegreeUs() override {
return oneDegreeUs;
}
Timer lastTdcTimer;
// RPM rate of change, in RPM per second

View File

@ -0,0 +1,12 @@
/**
* @file rpm_calculator_api.h
*/
#include "rusefi_types.h"
class EngineRotationState {
public:
virtual floatus_t getOneDegreeUs() = 0;
};
EngineRotationState * getEngineRotationState();