rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
map_averaging.h
Go to the documentation of this file.
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"
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*/
22
23#if EFI_MAP_AVERAGING
24
25#if HAL_USE_ADC
26void 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
36public:
38 : StoredValueSensor(type, timeout)
39 {
40 }
41
42 void start(uint8_t cylinderNumber);
43 void stop();
44
45 SensorResult submit(float sensorVolts);
46
48 m_function = &func;
49 }
50
51 void showInfo(const char* sensorName) const override;
52
53private:
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
63MapAverager& getMapAvg(size_t idx);
64float filterMapValue(float value);
65void startAveraging(struct mapSampler* s);
66
68public:
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};
size_t m_lastCounter
void showInfo(const char *sensorName) const override
MapAverager(SensorType type, efidur_t timeout)
void start(uint8_t cylinderNumber)
size_t m_counter
SensorResult submit(float sensorVolts)
SensorConverter * m_function
uint8_t m_cylinderNumber
void setFunction(SensorConverter &func)
void submitSample(float voltsMap1, float voltsMap2)
void onEnginePhase(float, efitick_t edgeTimestamp, float currentPhase, float nextPhase) override
void onFastCallback() override
void onConfigurationChange(engine_configuration_s const *previousConfig) override
mapSampler samplers[MAX_CYLINDER_COUNT]
void triggerCallback(uint32_t index, efitick_t edgeTimestamp)
SensorType type() const
Definition sensor.h:162
Base class for sensors that compute a value on one thread, and want to make it available to consumers...
void mapAveragingAdcCallback(float instantVoltage)
void startAveraging(struct mapSampler *s)
float filterMapValue(float value)
MapAverager & getMapAvg(size_t idx)
Definition init_map.cpp:28
efitick_t efidur_t
expected< float > SensorResult
Definition sensor.h:46
SensorType
Definition sensor_type.h:18
Base class for a sensor that has its value asynchronously set, then later retrieved by a consumer.
scheduling_s timer
uint8_t cylinderNumber