rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
map.cpp
Go to the documentation of this file.
1/**
2 * @file map.cpp
3 *
4 * See also map_averaging.cpp
5 *
6 * @author Andrey Belomutskiy, (c) 2012-2020
7 */
8#include "pch.h"
9
10#if EFI_ANALOG_SENSORS
11
12/**
13 * This function checks if Baro/MAP sensor value is inside of expected range
14 * @return unchanged mapKPa parameter or NaN
15 */
16static float validateBaroMap(float mapKPa) {
17 // Highest interstate is the Eisenhower Tunnel at 11158 feet -> 66 kpa
18 // Lowest point is the Dead Sea, -1411 feet -> 106 kpa
19 if (std::isnan(mapKPa) || mapKPa > 110 || mapKPa < 60) {
20 warning(ObdCode::OBD_Barometric_Press_Circ, "Invalid start-up baro pressure = %.2fkPa", mapKPa);
21 return NAN;
22 }
23 return mapKPa;
24}
25
26#if EFI_PROD_CODE
27
28static void printMAPInfo() {
29#if EFI_ANALOG_SENSORS
30 efiPrintf("instant value=%.2fkPa", Sensor::getOrZero(SensorType::Map));
31
32#if EFI_MAP_AVERAGING && defined (MODULE_MAP_AVERAGING)
33 efiPrintf("map type=%d/%s MAP=%.2fkPa", engineConfiguration->map.sensor.type,
36#endif // EFI_MAP_AVERAGING
37
39 char pinNameBuffer[16];
40
41 efiPrintf("MAP %.2fv @%s",
42 adcGetRawVoltage("mapinfo", mapAdc).value_or(0),
43 getPinNameByAdcChannel("map", mapAdc, pinNameBuffer, sizeof(pinNameBuffer)));
44 if (engineConfiguration->map.sensor.type == MT_CUSTOM) {
45 efiPrintf("at %.2fv=%.2f at %.2fv=%.2f",
50 }
51
53 efiPrintf("baro type=%d value=%.2f", engineConfiguration->baroSensor.type, Sensor::get(SensorType::BarometricPressure).value_or(-1));
54 if (engineConfiguration->baroSensor.type == MT_CUSTOM) {
55 efiPrintf("min=%.2f@%.2f max=%.2f@%.2f",
60 }
61 }
62#endif /* EFI_ANALOG_SENSORS */
63}
64#endif /* EFI_PROD_CODE */
65
68 // Read initial MAP sensor value and store it for Baro correction.
69 float storedInitialBaroPressure = Sensor::get(SensorType::MapSlow).value_or(STD_ATMOSPHERE);
70 efiPrintf("Get initial baro MAP pressure = %.2fkPa", storedInitialBaroPressure);
71 // validate if it's within a reasonable range (the engine should not be spinning etc.)
72 storedInitialBaroPressure = validateBaroMap(storedInitialBaroPressure);
73 if (!std::isnan(storedInitialBaroPressure)) {
74 efiPrintf("Using this fixed MAP pressure to override the baro correction!");
75
76 // TODO: do literally anything other than this
77 Sensor::setMockValue(SensorType::BarometricPressure, storedInitialBaroPressure);
78 } else {
79 efiPrintf("The baro pressure is invalid. The fixed baro correction will be disabled!");
80 }
81 }
82
83#if EFI_PROD_CODE
85#endif
86}
87
88#else /* EFI_ANALOG_SENSORS */
89
90void initMapDecoder() {
91}
92
93#endif /* EFI_ANALOG_SENSORS */
expected< float > adcGetRawVoltage(const char *msg, adc_channel_e hwChannel)
const char * getAir_pressure_sensor_type_e(air_pressure_sensor_type_e value)
static void setMockValue(SensorType type, float value, bool mockRedundant=false)
Definition sensor.cpp:203
virtual bool hasSensor() const
Definition sensor.h:141
virtual SensorResult get() const =0
static float getOrZero(SensorType type)
Definition sensor.h:83
void addConsoleAction(const char *token, Void callback)
Register console action without parameters.
static constexpr engine_configuration_s * engineConfiguration
char * getPinNameByAdcChannel(const char *msg, adc_channel_e hwChannel, char *buffer, size_t bufferSize)
bool warning(ObdCode code, const char *fmt,...)
static void printMAPInfo()
Definition map.cpp:28
static float validateBaroMap(float mapKPa)
Definition map.cpp:16
void initMapDecoder()
Definition map.cpp:66
@ OBD_Barometric_Press_Circ
@ BarometricPressure