28#if EFI_MAP_AVERAGING && defined (MODULE_MAP_AVERAGING)
29#if !EFI_SHAFT_POSITION_INPUT
30 fail(
"EFI_SHAFT_POSITION_INPUT required to have EFI_EMULATE_POSITION_SENSORS")
45#define MAX_MAP_BUFFER_LENGTH (MAX_CYLINDER_COUNT)
67 mapAveragingPin.setHigh();
71 action_s::make<endAveraging>(&averager));
75 chibios_rt::CriticalSectionLocker csl;
87 chibios_rt::CriticalSectionLocker csl;
90 m_sum += result.Value;
105 chibios_rt::CriticalSectionLocker csl;
154 float instantMap = mapResult.value_or(0);
164 mapAveragingPin.setLow();
200 efitick_t edgeTimestamp,
211 for (
int i = 0; i < samplingCount; i++) {
218 float angleOffset = samplingStart - currentPhase;
219 if (angleOffset < 0) {
225 scheduleByAngle(&s.timer, edgeTimestamp, angleOffset, action_s::make<startAveraging>(&s));
236 for (
size_t cylinderIndex = 0; cylinderIndex < MAX_CYLINDER_COUNT; cylinderIndex++) {
241 efiPrintf(
"initMapAveraging...");
244 efiPrintf(
"Running without MapAveraging...");
TunerStudioOutputChannels outputChannels
OneCylinder cylinders[MAX_CYLINDER_COUNT]
angle_t mapAveragingStart[MAX_CYLINDER_COUNT]
angle_t mapAveragingDuration
void setSmoothingFactor(float p_smoothingFactor)
float initOrAverage(float value)
void start(uint8_t cylinderNumber)
SensorResult submit(float sensorVolts)
SensorConverter * m_function
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]
angle_t getAngleOffset() const
static float getOrZero(SensorType type)
void setValidValue(float value, efitick_t timestamp)
bool isPhaseInRange(float test, float current, float next)
static EngineAccessor engine
static constexpr engine_configuration_s * engineConfiguration
bool warning(ObdCode code, const char *fmt,...)
void startAveraging(mapSampler *s)
static float averagedMapRunningBuffer[MAX_MAP_BUFFER_LENGTH]
void mapAveragingAdcCallback(float instantVoltage)
static ExpAverage expAverage
static void endAveraging(MapAverager *arg)
static void applyMapMinBufferLength()
static size_t currentMapAverager
static int averagedMapBufIdx
static int mapMinBufferLength
float filterMapValue(float value)
fail("EFI_SHAFT_POSITION_INPUT required to have EFI_EMULATE_POSITION_SENSORS") static NamedOutputPin mapAveragingPin("map")
float filterMapValue(float value)
MapAverager & getMapAvg(size_t idx)
@ CUSTOM_UNEXPECTED_MAP_VALUE
@ CUSTOM_INSTANT_MAP_DECODING
@ CUSTOM_ERR_MAP_START_ASSERT
@ MapAveragingTriggerCallback
efitick_t scheduleByAngle(scheduling_s *timer, efitick_t nowNt, angle_t angle, action_s const &action)
expected< float > SensorResult
float samplingAngle[MAP_ANGLE_SIZE]
float samplingWindow[MAP_WINDOW_SIZE]
float samplingWindowBins[MAP_WINDOW_SIZE]
float samplingAngleBins[MAP_ANGLE_SIZE]
virtual SensorResult convert(float raw) const =0
bool isMapAveragingEnabled
bool measureMapOnlyInOneCylinder
uint8_t mapPerCylinder[MAX_CYLINDER_COUNT]
scaled_channel< uint16_t, 30, 1 > instantMAPValue
void wrapAngle(angle_t &angle, const char *msg, ObdCode code)