Line |
Branch |
Decision |
Exec |
Source |
1 |
|
|
|
/** |
2 |
|
|
|
* @file map_averaging.h |
3 |
|
|
|
* |
4 |
|
|
|
* @date Dec 11, 2013 |
5 |
|
|
|
* @author Andrey Belomutskiy, (c) 2012-2020 |
6 |
|
|
|
*/ |
7 |
|
|
|
|
8 |
|
|
|
#pragma once |
9 |
|
|
|
#include "engine_module.h" |
10 |
|
|
|
#include "stored_value_sensor.h" |
11 |
|
|
|
#include "sensor_converter_func.h" |
12 |
|
|
|
#include "scheduler.h" |
13 |
|
|
|
|
14 |
|
|
|
/** |
15 |
|
|
|
* here we have averaging start and averaging end points for each cylinder |
16 |
|
|
|
* TODO: migrate to AngleBasedEvent, see also #7869 |
17 |
|
|
|
*/ |
18 |
|
|
|
struct mapSampler { |
19 |
|
|
|
scheduling_s timer; |
20 |
|
|
|
uint8_t cylinderNumber; |
21 |
|
|
|
}; |
22 |
|
|
|
|
23 |
|
|
|
#if EFI_MAP_AVERAGING |
24 |
|
|
|
|
25 |
|
|
|
#if HAL_USE_ADC |
26 |
|
|
|
void mapAveragingAdcCallback(float instantVoltage); |
27 |
|
|
|
#endif |
28 |
|
|
|
|
29 |
|
|
|
// allow smoothing up to number of cylinders |
30 |
|
|
|
#define MAX_MAP_BUFFER_LENGTH (MAX_CYLINDER_COUNT) |
31 |
|
|
|
#endif /* EFI_MAP_AVERAGING */ |
32 |
|
|
|
|
33 |
|
|
|
#define SAMPLER_DIMENSION 2 |
34 |
|
|
|
|
35 |
|
|
|
class MapAverager : public StoredValueSensor { |
36 |
|
|
|
public: |
37 |
|
|
2 |
MapAverager(SensorType type, efidur_t timeout) |
38 |
|
|
2 |
: StoredValueSensor(type, timeout) |
39 |
|
|
|
{ |
40 |
|
|
2 |
} |
41 |
|
|
|
|
42 |
|
|
|
void start(uint8_t cylinderNumber); |
43 |
|
|
|
void stop(); |
44 |
|
|
|
|
45 |
|
|
|
SensorResult submit(float sensorVolts); |
46 |
|
|
|
|
47 |
|
|
8 |
void setFunction(SensorConverter& func) { |
48 |
|
|
8 |
m_function = &func; |
49 |
|
|
8 |
} |
50 |
|
|
|
|
51 |
|
|
|
void showInfo(const char* sensorName) const override; |
52 |
|
|
|
|
53 |
|
|
|
private: |
54 |
|
|
|
SensorConverter* m_function = nullptr; |
55 |
|
|
|
|
56 |
|
|
|
bool m_isAveraging = false; |
57 |
|
|
|
size_t m_counter = 0; |
58 |
|
|
|
size_t m_lastCounter = 0; |
59 |
|
|
|
float m_sum = 0; |
60 |
|
|
|
uint8_t m_cylinderNumber = 0; |
61 |
|
|
|
}; |
62 |
|
|
|
|
63 |
|
|
|
MapAverager& getMapAvg(size_t idx); |
64 |
|
|
|
float filterMapValue(float value); |
65 |
|
|
|
void startAveraging(struct mapSampler* s); |
66 |
|
|
|
|
67 |
|
|
|
class MapAveragingModule : public EngineModule { |
68 |
|
|
|
public: |
69 |
|
|
|
void onConfigurationChange(engine_configuration_s const * previousConfig) override; |
70 |
|
|
|
|
71 |
|
|
|
void onFastCallback() override; |
72 |
|
|
|
void onEnginePhase(float /*rpm*/, efitick_t edgeTimestamp, float currentPhase, float nextPhase) override; |
73 |
|
|
|
|
74 |
|
|
|
void triggerCallback(uint32_t index, efitick_t edgeTimestamp); |
75 |
|
|
|
void init(); |
76 |
|
|
|
void submitSample(float voltsMap1, float voltsMap2); |
77 |
|
|
|
mapSampler samplers[MAX_CYLINDER_COUNT]; |
78 |
|
|
|
}; |
79 |
|
|
|
|