2015-07-10 06:01:56 -07:00
|
|
|
/**
|
|
|
|
* @file map_averaging.h
|
|
|
|
*
|
|
|
|
* @date Dec 11, 2013
|
2020-01-13 18:57:43 -08:00
|
|
|
* @author Andrey Belomutskiy, (c) 2012-2020
|
2015-07-10 06:01:56 -07:00
|
|
|
*/
|
|
|
|
|
2019-11-14 21:00:13 -08:00
|
|
|
#pragma once
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2022-10-27 10:59:36 -07:00
|
|
|
#include "sensor_converter_func.h"
|
|
|
|
|
2019-04-12 19:07:03 -07:00
|
|
|
#if EFI_MAP_AVERAGING
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2019-04-12 19:07:03 -07:00
|
|
|
#if HAL_USE_ADC
|
2023-01-05 09:14:48 -08:00
|
|
|
void mapAveragingAdcCallback(float instantVoltage);
|
2015-07-10 06:01:56 -07:00
|
|
|
#endif
|
|
|
|
|
2021-11-16 01:15:29 -08:00
|
|
|
void initMapAveraging();
|
|
|
|
void refreshMapAveragingPreCalc();
|
2019-10-14 03:18:08 -07:00
|
|
|
|
2020-10-03 23:09:12 -07:00
|
|
|
void mapAveragingTriggerCallback(
|
2021-11-16 01:15:29 -08:00
|
|
|
uint32_t index, efitick_t edgeTimestamp);
|
2020-10-03 22:43:02 -07:00
|
|
|
|
2019-10-14 03:18:08 -07:00
|
|
|
#if EFI_TUNER_STUDIO
|
2018-02-06 13:21:41 -08:00
|
|
|
void postMapState(TunerStudioOutputChannels *tsOutputChannels);
|
2019-10-14 03:18:08 -07:00
|
|
|
#endif
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2022-10-27 10:59:36 -07:00
|
|
|
// allow smoothing up to number of cylinders
|
|
|
|
#define MAX_MAP_BUFFER_LENGTH (MAX_CYLINDER_COUNT)
|
|
|
|
|
2015-07-10 06:01:56 -07:00
|
|
|
#endif /* EFI_MAP_AVERAGING */
|
2022-10-27 10:59:36 -07:00
|
|
|
|
|
|
|
class MapAverager : public StoredValueSensor {
|
|
|
|
public:
|
|
|
|
MapAverager(SensorType type, efitick_t timeout)
|
|
|
|
: StoredValueSensor(type, timeout)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void start();
|
|
|
|
void stop();
|
|
|
|
|
|
|
|
SensorResult submit(float sensorVolts);
|
|
|
|
|
|
|
|
void setFunction(SensorConverter& func) {
|
|
|
|
m_function = &func;
|
|
|
|
}
|
|
|
|
|
|
|
|
void showInfo(const char* sensorName) const override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
SensorConverter* m_function = nullptr;
|
|
|
|
|
|
|
|
bool m_isAveraging = false;
|
|
|
|
size_t m_counter = 0;
|
|
|
|
size_t m_lastCounter = 0;
|
|
|
|
float m_sum = 0;
|
|
|
|
};
|
|
|
|
|
2022-10-27 18:15:04 -07:00
|
|
|
MapAverager& getMapAvg(size_t idx);
|