rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
init_map.cpp
Go to the documentation of this file.
1#include "pch.h"
2
3#include "adc_subscription.h"
4#include "linear_func.h"
5#include "fallback_sensor.h"
6#include "functional_sensor.h"
7#include "map_averaging.h"
8
11
12// This converter is shared between both fast and slow: the only difference is
13// how the *voltage* is determined, not how its converted to a pressure.
16// unfinished/dead? static FunctionalSensor slowMapSensor2(SensorType::MapSlow2, MS2NT(50));
19
20// lowest reasonable idle is maybe 600 rpm
21// one sample per cycle (1 cylinder, or "sample one cyl" mode) gives a period of 100ms
22// add some margin -> 200ms timeout for fast MAP sampling
23// 'fast' means averaged? why is that fast again?!
26
27// instant map values are injected here
28MapAverager& getMapAvg(size_t cylinderBankIndex) {
29 // May 2025: cylinderBankIndex is always zero, second MAP sensor feature is not finished
30 return cylinderBankIndex == 0 ? fastMapSensor : fastMapSensor2;
31}
32
33// Combine MAP sensors: prefer fast sensor, but use slow if fast is unavailable.
36
37// helper struct for the local getMapCfg function
38struct MapCfg {
39 float v1;
40 float map1;
41 float v2;
42 float map2;
43};
44
45static MapCfg getMapCfg(air_pressure_sensor_type_e sensorType) {
46 switch (sensorType) {
47 case MT_DENSO183:
48 return {0, -6.64, 5, 182.78};
49 case MT_MPX4100:
50 return {0.306, 20, 4.897, 105};
51 case MT_MPX4250:
52 case MT_MPX4250A:
53 return {0.204, 20, 4.896, 250};
54 case MT_HONDA3BAR:
55 return {0.5, 91.422, 3.0, 0};
56 case MT_DODGE_NEON_2003:
57 return {0.4, 15.34, 4.5, 100};
58 case MT_SUBY_DENSO:
59 return {0, 0, 5, 200};
60 case MT_GM_3_BAR:
61 return {0.631, 40, 4.914, 304};
62 case MT_GM_2_BAR:
63 return {0, 8.8, 5, 208};
64 case MT_GM_1_BAR:
65 return {0, 10, 5, 105};
66 case MT_TOYOTA_89420_02010:
67 return {3.7 - 2, 33.32, 3.7, 100};
68 case MT_MAZDA_1_BAR:
69 return {0, 2.5, 5, 117};
70 case MT_BOSCH_2_5:
71 // kpa=54.11764705882353v−1.6470588235294201
72 return {0.4 , 20 , 4.65, 250};
73 case MT_MPXH6400:
74 return {0.2, 20, 4.8, 400};
75 case MT_MPXH6300:
76 return {1.0, 60, 4.5, 270};
77 default:
78 firmwareError(ObdCode::CUSTOM_ERR_MAP_TYPE, "Unknown MAP type: decoder %d", sensorType);
79 // falls through to custom
80 return {};
81 case MT_CUSTOM: {
82 auto& mapConfig = engineConfiguration->map.sensor;
83 return {
85 mapConfig.lowValue,
87 mapConfig.highValue
88 };
89 }}
90}
91
93 auto cfg = getMapCfg(sensorType);
94
95 converter.configure(
96 cfg.v1,
97 cfg.map1,
98 cfg.v2,
99 cfg.map2,
102 );
103}
104
105void initMap() {
106 // Set up the conversion function
108
110// unfinished/dead? slowMapSensor2.setFunction(mapConverter);
115
116 auto mapChannel = engineConfiguration->map.sensor.hwChannel;
117 if (isAdcChannelValid(mapChannel)) {
119// unfinished/dead? slowMapSensor2.Register();
124
125 // Configure slow MAP as a normal analog sensor
126 // it's possible/probably that slow and fast both read from same physical pin, apparently that's fine?!
128 }
129
132
133 auto baroChannel = engineConfiguration->baroSensor.hwChannel;
134 if (isAdcChannelValid(baroChannel)) {
136
139
141 }
142}
143
bool isAdcChannelValid(adc_channel_e hwChannel)
Definition adc_inputs.h:23
static AdcSubscriptionEntry * SubscribeSensor(FunctionalSensorBase &sensor, adc_channel_e channel, float lowpassCutoffHZ, float voltsPerAdcVolt=0.0f)
static void UnsubscribeSensor(FunctionalSensorBase &sensor)
Class for sensors that convert from some raw floating point value (ex: voltage, frequency,...
void setFunction(ConverterType &func)
void setFunction(SensorConverter &func)
bool Register()
Definition sensor.cpp:131
static constexpr engine_configuration_s * engineConfiguration
void firmwareError(ObdCode code, const char *fmt,...)
converter
static FunctionalSensor throttleInletPress(SensorType::ThrottleInletPressure, MS2NT(50))
static FallbackSensor mapCombiner(SensorType::Map, SensorType::MapFast, SensorType::MapSlow)
static FunctionalSensor baroSensor(SensorType::BarometricPressure, MS2NT(50))
static MapCfg getMapCfg(air_pressure_sensor_type_e sensorType)
Definition init_map.cpp:45
void initMap()
Definition init_map.cpp:105
static FallbackSensor mapCombiner2(SensorType::Map2, SensorType::MapFast2, SensorType::MapSlow2)
static LinearFunc mapConverter
Definition init_map.cpp:14
static FunctionalSensor slowMapSensor(SensorType::MapSlow, MS2NT(50))
static LinearFunc baroConverter
Definition init_map.cpp:9
void configureMapFunction(LinearFunc &converter, air_pressure_sensor_type_e sensorType)
Definition init_map.cpp:92
static MapAverager fastMapSensor(SensorType::MapFast, MS2NT(200))
static MapAverager fastMapSensor2(SensorType::MapFast2, MS2NT(200))
static FunctionalSensor compressorDischargePress(SensorType::CompressorDischargePressure, MS2NT(50))
MapAverager & getMapAvg(size_t cylinderBankIndex)
Definition init_map.cpp:28
void deinitMap()
Definition init_map.cpp:144
@ CUSTOM_ERR_MAP_TYPE
air_pressure_sensor_type_e
@ ThrottleInletPressure
@ CompressorDischargePressure
@ BarometricPressure