fome-fw/firmware/controllers/algo/engine_parts.h

125 lines
2.4 KiB
C
Raw Normal View History

2019-05-27 15:50:23 -07:00
/*
* @file engine_parts.h
*
* @date May 27, 2019
2020-01-07 21:02:40 -08:00
* @author Andrey Belomutskiy, (c) 2012-2020
2019-05-27 15:50:23 -07:00
*/
2019-09-19 21:25:43 -07:00
#pragma once
2019-05-27 15:50:23 -07:00
#include "cyclic_buffer.h"
#include "timer.h"
2019-05-27 15:50:23 -07:00
#define MOCK_ADC_SIZE 26
2019-05-27 15:50:23 -07:00
class MockAdcState {
public:
MockAdcState();
bool hasMockAdc[MOCK_ADC_SIZE];
int fakeAdcValues[MOCK_ADC_SIZE];
2019-09-19 21:25:43 -07:00
void setMockVoltage(int hwChannel, float voltage DECLARE_ENGINE_PARAMETER_SUFFIX);
2019-05-27 15:50:23 -07:00
int getMockAdcValue(int hwChannel) const;
};
class Accelerometer {
public:
float x = 0; // G value
float y = 0;
float z = 0;
};
class SensorsState {
public:
SensorsState();
Accelerometer accelerometer;
};
class FuelConsumptionState {
public:
void consumeFuel(float grams, efitick_t nowNt);
float getConsumedGrams() const;
float getConsumptionGramPerSecond() const;
private:
float m_consumedGrams = 0;
float m_rate = 0;
Timer m_timer;
2019-05-27 15:50:23 -07:00
};
class TransmissionState {
public:
gear_e gearSelectorPosition;
};
2021-06-23 03:37:32 -07:00
typedef cyclic_buffer<int, 8> warningBuffer_t;
2019-05-27 15:50:23 -07:00
class WarningCodeState {
public:
WarningCodeState();
void addWarningCode(obd_code_e code);
bool isWarningNow(efitimesec_t now, bool forIndicator DECLARE_ENGINE_PARAMETER_SUFFIX) const;
void clear();
int warningCounter;
int lastErrorCode;
efitimesec_t timeOfPreviousWarning;
// todo: we need a way to post multiple recent warnings into TS
2021-06-23 03:37:32 -07:00
warningBuffer_t recentWarnings;
2019-05-27 15:50:23 -07:00
};
class FsioState {
public:
FsioState();
float fsioLastValue[FSIO_COMMAND_COUNT];
2019-09-19 05:05:23 -07:00
#if EFI_UNIT_TEST
float mockFan = 0;
float mockRpm = 0;
float mockCrankingRpm = 0;
float mockTimeSinceBoot = 0;
float mockTimeSinceTrigger = 0;
2019-09-19 05:05:23 -07:00
int mockAcToggle = 0;
#endif
2019-05-27 15:50:23 -07:00
#if EFI_ENABLE_ENGINE_WARNING
/**
* Shall we purposely miss on some cylinders in order to attract driver's attention to some problem
* like getting too hot
*/
float isEngineWarning;
#endif /* EFI_ENABLE_ENGINE_WARNING */
#if EFI_ENABLE_CRITICAL_ENGINE_STOP
/**
* Shall we stop engine due to some critical condition in order to save the engine
*/
float isCriticalEngineCondition;
#endif /* EFI_ENABLE_CRITICAL_ENGINE_STOP */
};
2019-05-27 15:58:43 -07:00
/**
* 6 crossing over 50% TPS means pressing and releasing three times
* TODO: looks like this code is not finished / not used?
*/
#define PUMPS_TO_PRIME 6
class StartupFuelPumping {
public:
StartupFuelPumping();
void update(DECLARE_ENGINE_PARAMETER_SIGNATURE);
bool isTpsAbove50;
int pumpsCounter;
private:
void setPumpsCounter(int newValue);
};
2020-03-26 08:52:19 -07:00
struct multispark_state
{
2020-07-29 02:22:54 -07:00
efitick_t delay = 0;
efitick_t dwell = 0;
uint8_t count = 0;
2020-03-26 08:52:19 -07:00
};