2014-08-29 07:52:33 -07:00
|
|
|
/**
|
|
|
|
* @file engine.h
|
|
|
|
*
|
|
|
|
* @date May 21, 2014
|
|
|
|
* @author Andrey Belomutskiy, (c) 2012-2014
|
|
|
|
*/
|
|
|
|
#ifndef ENGINE_H_
|
|
|
|
#define ENGINE_H_
|
|
|
|
|
|
|
|
#include "main.h"
|
|
|
|
#include "engine_configuration.h"
|
2014-09-26 11:06:01 -07:00
|
|
|
#include "ec2.h"
|
2014-11-11 13:05:09 -08:00
|
|
|
#include "rpm_calculator.h"
|
2014-08-29 07:52:33 -07:00
|
|
|
|
|
|
|
class EngineState {
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Access to these two fields is not synchronized in any way - that should work since float read/write are atomic.
|
|
|
|
*/
|
|
|
|
float iat;
|
|
|
|
float clt;
|
2014-09-26 11:06:01 -07:00
|
|
|
|
|
|
|
|
2014-08-29 07:52:33 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
class RpmCalculator;
|
|
|
|
|
|
|
|
class Engine {
|
|
|
|
public:
|
2014-11-07 20:03:53 -08:00
|
|
|
Engine();
|
2014-09-26 13:03:02 -07:00
|
|
|
void init();
|
2014-11-11 13:05:09 -08:00
|
|
|
RpmCalculator rpmCalculator;
|
2014-08-29 07:52:33 -07:00
|
|
|
engine_configuration_s *engineConfiguration;
|
2014-09-26 11:06:01 -07:00
|
|
|
engine_configuration2_s *engineConfiguration2;
|
2014-08-29 07:52:33 -07:00
|
|
|
|
2014-10-31 12:03:00 -07:00
|
|
|
Thermistor iat;
|
|
|
|
Thermistor clt;
|
|
|
|
|
2014-11-24 13:03:32 -08:00
|
|
|
trigger_shape_s triggerShape;
|
|
|
|
|
2014-11-11 06:03:18 -08:00
|
|
|
void onTriggerEvent(uint64_t nowNt);
|
2014-08-29 07:52:33 -07:00
|
|
|
EngineState engineState;
|
2014-11-11 06:03:18 -08:00
|
|
|
uint64_t lastTriggerEventTimeNt;
|
2014-08-29 07:52:33 -07:00
|
|
|
|
2014-10-31 12:03:00 -07:00
|
|
|
/**
|
|
|
|
* This coefficient translates ADC value directly into voltage adjusted according to
|
|
|
|
* voltage divider configuration. This is a future (?) performance optimization.
|
|
|
|
*/
|
|
|
|
float adcToVoltageInputDividerCoefficient;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This field is true if we are in 'cylinder cleanup' state right now
|
|
|
|
* see isCylinderCleanupEnabled
|
|
|
|
*/
|
|
|
|
bool isCylinderCleanupMode;
|
|
|
|
|
|
|
|
|
2014-08-29 07:52:33 -07:00
|
|
|
void updateSlowSensors();
|
2014-09-26 13:03:02 -07:00
|
|
|
void watchdog();
|
|
|
|
private:
|
|
|
|
/**
|
|
|
|
* By the way:
|
|
|
|
* 'cranking' means engine is not stopped and the rpm are below crankingRpm
|
|
|
|
* 'running' means RPM are above crankingRpm
|
|
|
|
* 'spinning' means the engine is not stopped
|
|
|
|
*/
|
|
|
|
bool isSpinning;
|
2014-09-27 16:02:54 -07:00
|
|
|
bool stopPins();
|
2014-08-29 07:52:33 -07:00
|
|
|
};
|
|
|
|
|
2014-10-17 14:03:00 -07:00
|
|
|
/**
|
|
|
|
* 6 crossing over 50% TPS means pressing and releasing three times
|
|
|
|
*/
|
|
|
|
#define PUMPS_TO_PRIME 6
|
2014-10-17 13:05:16 -07:00
|
|
|
|
2014-10-17 12:02:59 -07:00
|
|
|
class StartupFuelPumping {
|
|
|
|
public:
|
|
|
|
StartupFuelPumping();
|
|
|
|
void update(Engine *engine);
|
|
|
|
bool isTpsAbove50;
|
|
|
|
int pumpsCounter;
|
|
|
|
private:
|
2014-10-17 13:05:16 -07:00
|
|
|
void setPumpsCounter(engine_configuration_s *engineConfiguration, int newValue);
|
2014-10-17 12:02:59 -07:00
|
|
|
};
|
|
|
|
|
2014-11-10 07:03:20 -08:00
|
|
|
void prepareShapes(Engine *engine);
|
2014-10-31 13:03:07 -07:00
|
|
|
void resetConfigurationExt(Logging * logger, engine_type_e engineType,
|
|
|
|
Engine *engine);
|
|
|
|
void applyNonPersistentConfiguration(Logging * logger, Engine *engine);
|
|
|
|
void prepareOutputSignals(Engine *engine);
|
|
|
|
|
2014-08-29 07:52:33 -07:00
|
|
|
#endif /* ENGINE_H_ */
|