rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
Public Member Functions | Private Attributes
MapAverager Class Reference

#include <map_averaging.h>

Inheritance diagram for MapAverager:
Inheritance graph
[legend]
Collaboration diagram for MapAverager:
Collaboration graph
[legend]

Public Member Functions

 MapAverager (SensorType type, efidur_t timeout)
 
void start (uint8_t cylinderNumber)
 
void stop ()
 
SensorResult submit (float sensorVolts)
 
void setFunction (SensorConverter &func)
 
void showInfo (const char *sensorName) const override
 
- Public Member Functions inherited from StoredValueSensor
SensorResult get () const final override
 
 StoredValueSensor (SensorType type, efidur_t timeoutNt)
 
void invalidate ()
 
void invalidate (UnexpectedCode why)
 
void setValidValue (float value, efitick_t timestamp)
 
void showInfo (const char *sensorName) const override
 
virtual void setTimeout (int timeoutMs)
 
- Public Member Functions inherited from Sensor
bool Register ()
 
const chargetSensorName () const
 
virtual bool hasSensor () const
 
virtual float getRaw () const
 
virtual bool isRedundant () const
 
void unregister ()
 
SensorType type () const
 

Private Attributes

SensorConverterm_function = nullptr
 
bool m_isAveraging = false
 
size_t m_counter = 0
 
size_t m_lastCounter = 0
 
float m_sum = 0
 
uint8_t m_cylinderNumber = 0
 

Additional Inherited Members

- Static Public Member Functions inherited from Sensor
static void showAllSensorInfo ()
 
static void showInfo (SensorType type)
 
static void resetRegistry ()
 
static const SensorgetSensorOfType (SensorType type)
 
static SensorResult get (SensorType type)
 
static float getOrZero (SensorType type)
 
static float getRaw (SensorType type)
 
static bool isRedundant (SensorType type)
 
static bool hasSensor (SensorType type)
 
static void setMockValue (SensorType type, float value, bool mockRedundant=false)
 
static void setInvalidMockValue (SensorType type)
 
static void resetMockValue (SensorType type)
 
static void resetAllMocks ()
 
static void inhibitTimeouts (bool inhibit)
 
static const chargetSensorName (SensorType type)
 
- Protected Member Functions inherited from Sensor
 Sensor (SensorType type)
 
- Static Protected Attributes inherited from Sensor
static bool s_inhibitSensorTimeouts = false
 

Detailed Description

Definition at line 35 of file map_averaging.h.

Constructor & Destructor Documentation

◆ MapAverager()

MapAverager::MapAverager ( SensorType  type,
efidur_t  timeout 
)
inline

Definition at line 37 of file map_averaging.h.

38 : StoredValueSensor(type, timeout)
39 {
40 }
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...

Member Function Documentation

◆ setFunction()

void MapAverager::setFunction ( SensorConverter func)
inline

Definition at line 47 of file map_averaging.h.

47 {
48 m_function = &func;
49 }
SensorConverter * m_function

Referenced by initMap().

Here is the caller graph for this function:

◆ showInfo()

void MapAverager::showInfo ( const char sensorName) const
overridevirtual

Implements Sensor.

Definition at line 82 of file sensor_info_printing.cpp.

82 {
83 const auto value = get();
84 efiPrintf("Sensor \"%s\" is MAP averager: valid: %s value: %.2f averaged sample count: %d", sensorName, boolToString(value.Valid), value.Value, m_lastCounter);
85}
size_t m_lastCounter
SensorResult get() const final override
const char * boolToString(bool value)
Definition efilib.cpp:19
Here is the call graph for this function:

◆ start()

void MapAverager::start ( uint8_t  cylinderNumber)

Definition at line 74 of file map_averaging.cpp.

74 {
75 chibios_rt::CriticalSectionLocker csl;
76
77 m_counter = 0;
78 m_sum = 0;
79 m_isAveraging = true;
80 m_cylinderNumber = cylinderNumber;
81}
size_t m_counter
uint8_t m_cylinderNumber

◆ stop()

void MapAverager::stop ( )

Definition at line 104 of file map_averaging.cpp.

104 {
105 chibios_rt::CriticalSectionLocker csl;
106
107 m_isAveraging = false;
108
109 if (m_counter > 0) {
110 float averageMap = m_sum / m_counter;
112
113 // TODO: this should be per-sensor, not one for all MAP sensors
115 // increment circular running buffer index
117 // find min. value (only works for pressure values, not raw voltages!)
118 float minPressure = averagedMapRunningBuffer[0];
119 for (int i = 1; i < mapMinBufferLength; i++) {
120 if (averagedMapRunningBuffer[i] < minPressure)
121 minPressure = averagedMapRunningBuffer[i];
122 }
123
126 } else {
127#if EFI_PROD_CODE
128 warning(ObdCode::CUSTOM_UNEXPECTED_MAP_VALUE, "No MAP values to average");
129#endif
130 }
131}
TunerStudioOutputChannels outputChannels
Definition engine.h:109
void setValidValue(float value, efitick_t timestamp)
efitick_t getTimeNowNt()
Definition efitime.cpp:19
static EngineAccessor engine
Definition engine.h:413
bool warning(ObdCode code, const char *fmt,...)
static float averagedMapRunningBuffer[MAX_MAP_BUFFER_LENGTH]
static int averagedMapBufIdx
static int mapMinBufferLength
float filterMapValue(float value)
@ CUSTOM_UNEXPECTED_MAP_VALUE
uint8_t mapPerCylinder[MAX_CYLINDER_COUNT]

Referenced by endAveraging().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ submit()

SensorResult MapAverager::submit ( float  sensorVolts)

Definition at line 83 of file map_averaging.cpp.

83 {
84 auto result = m_function ? m_function->convert(volts) : unexpected;
85
86 if (m_isAveraging && result) {
87 chibios_rt::CriticalSectionLocker csl;
88
89 m_counter++;
90 m_sum += result.Value;
91 }
92
93 return result;
94}
virtual SensorResult convert(float raw) const =0

Referenced by mapAveragingAdcCallback().

Here is the call graph for this function:
Here is the caller graph for this function:

Field Documentation

◆ m_counter

size_t MapAverager::m_counter = 0
private

Definition at line 57 of file map_averaging.h.

Referenced by start(), stop(), and submit().

◆ m_cylinderNumber

uint8_t MapAverager::m_cylinderNumber = 0
private

Definition at line 60 of file map_averaging.h.

Referenced by start(), and stop().

◆ m_function

SensorConverter* MapAverager::m_function = nullptr
private

Definition at line 54 of file map_averaging.h.

Referenced by setFunction(), and submit().

◆ m_isAveraging

bool MapAverager::m_isAveraging = false
private

Definition at line 56 of file map_averaging.h.

Referenced by start(), stop(), and submit().

◆ m_lastCounter

size_t MapAverager::m_lastCounter = 0
private

Definition at line 58 of file map_averaging.h.

Referenced by showInfo(), and stop().

◆ m_sum

float MapAverager::m_sum = 0
private

Definition at line 59 of file map_averaging.h.

Referenced by start(), stop(), and submit().


The documentation for this class was generated from the following files: