baro in sensor model (#2306)
* baro in sensor model * missed * typo * init baro * needs an include there
This commit is contained in:
parent
6a3cf83d02
commit
7d3cadfc87
|
@ -545,9 +545,8 @@ void updateTunerStudioState(TunerStudioOutputChannels *tsOutputChannels DECLARE_
|
||||||
tsOutputChannels->vBatt = getVBatt(PASS_ENGINE_PARAMETER_SIGNATURE);
|
tsOutputChannels->vBatt = getVBatt(PASS_ENGINE_PARAMETER_SIGNATURE);
|
||||||
|
|
||||||
// offset 36
|
// offset 36
|
||||||
#if EFI_ANALOG_SENSORS
|
tsOutputChannels->baroPressure = Sensor::get(SensorType::BarometricPressure).value_or(0);
|
||||||
tsOutputChannels->baroPressure = hasBaroSensor() ? getBaroPressure() : 0;
|
|
||||||
#endif /* EFI_ANALOG_SENSORS */
|
|
||||||
// 48
|
// 48
|
||||||
tsOutputChannels->fuelBase = engine->engineState.baseFuel * 1000; // Convert grams to mg
|
tsOutputChannels->fuelBase = engine->engineState.baseFuel * 1000; // Convert grams to mg
|
||||||
// 64
|
// 64
|
||||||
|
|
|
@ -440,12 +440,16 @@ float getFuelCutOffCorrection(efitick_t nowNt, int rpm DECLARE_ENGINE_PARAMETER_
|
||||||
}
|
}
|
||||||
|
|
||||||
float getBaroCorrection(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
float getBaroCorrection(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
||||||
if (hasBaroSensor(PASS_ENGINE_PARAMETER_SIGNATURE)) {
|
if (Sensor::hasSensor(SensorType::BarometricPressure)) {
|
||||||
float correction = baroCorrMap.getValue(GET_RPM(), getBaroPressure(PASS_ENGINE_PARAMETER_SIGNATURE));
|
// Default to 1atm if failed
|
||||||
|
float pressure = Sensor::get(SensorType::BarometricPressure).value_or(101.325f);
|
||||||
|
|
||||||
|
float correction = baroCorrMap.getValue(GET_RPM(), pressure);
|
||||||
if (cisnan(correction) || correction < 0.01) {
|
if (cisnan(correction) || correction < 0.01) {
|
||||||
warning(OBD_Barometric_Press_Circ_Range_Perf, "Invalid baro correction %f", correction);
|
warning(OBD_Barometric_Press_Circ_Range_Perf, "Invalid baro correction %f", correction);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return correction;
|
return correction;
|
||||||
} else {
|
} else {
|
||||||
return 1;
|
return 1;
|
||||||
|
|
|
@ -212,7 +212,7 @@ static void showLine(lcd_line_e line, int /*screenY*/) {
|
||||||
|
|
||||||
#if EFI_ANALOG_SENSORS
|
#if EFI_ANALOG_SENSORS
|
||||||
case LL_BARO:
|
case LL_BARO:
|
||||||
if (hasBaroSensor()) {
|
if (Sensor::hasSensor(SensorType::BarometricPressure)) {
|
||||||
lcdPrintf("Baro: %.2f", getBaroPressure());
|
lcdPrintf("Baro: %.2f", getBaroPressure());
|
||||||
} else {
|
} else {
|
||||||
lcdPrintf("Baro: none");
|
lcdPrintf("Baro: none");
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
#include "interpolation.h"
|
#include "interpolation.h"
|
||||||
#include "map.h"
|
#include "map.h"
|
||||||
#include "engine_controller.h"
|
#include "engine_controller.h"
|
||||||
|
#include "sensor.h"
|
||||||
|
|
||||||
#if EFI_PROD_CODE
|
#if EFI_PROD_CODE
|
||||||
#include "digital_input_icu.h"
|
#include "digital_input_icu.h"
|
||||||
|
@ -173,14 +174,6 @@ float getRawMap(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
||||||
return getMapByVoltage(voltage PASS_ENGINE_PARAMETER_SUFFIX);
|
return getMapByVoltage(voltage PASS_ENGINE_PARAMETER_SUFFIX);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns true if a real Baro sensor is present.
|
|
||||||
* Also if 'useFixedBaroCorrFromMap' option is enabled, and we have the initial pressure value stored and passed validation.
|
|
||||||
*/
|
|
||||||
bool hasBaroSensor(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
|
||||||
return isAdcChannelValid(engineConfiguration->baroSensor.hwChannel) || !cisnan(storedInitialBaroPressure);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool hasMapSensor(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
bool hasMapSensor(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
||||||
return isAdcChannelValid(engineConfiguration->map.sensor.hwChannel);
|
return isAdcChannelValid(engineConfiguration->map.sensor.hwChannel);
|
||||||
}
|
}
|
||||||
|
@ -274,8 +267,8 @@ static void printMAPInfo(void) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hasBaroSensor(PASS_ENGINE_PARAMETER_SIGNATURE)) {
|
if (Sensor::hasSensor(SensorType::BarometricPressure)) {
|
||||||
scheduleMsg(logger, "baro type=%d value=%.2f", engineConfiguration->baroSensor.type, getBaroPressure(PASS_ENGINE_PARAMETER_SIGNATURE));
|
scheduleMsg(logger, "baro type=%d value=%.2f", engineConfiguration->baroSensor.type, Sensor::get(SensorType::BarometricPressure).value_or(-1));
|
||||||
if (engineConfiguration->baroSensor.type == MT_CUSTOM) {
|
if (engineConfiguration->baroSensor.type == MT_CUSTOM) {
|
||||||
scheduleMsg(logger, "min=%.2f@%.2f max=%.2f@%.2f",
|
scheduleMsg(logger, "min=%.2f@%.2f max=%.2f@%.2f",
|
||||||
engineConfiguration->baroSensor.lowValue,
|
engineConfiguration->baroSensor.lowValue,
|
||||||
|
|
|
@ -18,7 +18,6 @@ void initMapDecoder(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_SUFFIX);
|
||||||
*/
|
*/
|
||||||
float getRawMap(DECLARE_ENGINE_PARAMETER_SIGNATURE);
|
float getRawMap(DECLARE_ENGINE_PARAMETER_SIGNATURE);
|
||||||
float getBaroPressure(DECLARE_ENGINE_PARAMETER_SIGNATURE);
|
float getBaroPressure(DECLARE_ENGINE_PARAMETER_SIGNATURE);
|
||||||
bool hasBaroSensor(DECLARE_ENGINE_PARAMETER_SIGNATURE);
|
|
||||||
bool hasMapSensor(DECLARE_ENGINE_PARAMETER_SIGNATURE);
|
bool hasMapSensor(DECLARE_ENGINE_PARAMETER_SIGNATURE);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -43,6 +43,8 @@ static const char* s_sensorNames[] = {
|
||||||
"Flex Fuel",
|
"Flex Fuel",
|
||||||
|
|
||||||
"Battery Voltage",
|
"Battery Voltage",
|
||||||
|
|
||||||
|
"Barometric Pressure",
|
||||||
};
|
};
|
||||||
|
|
||||||
// This struct represents one sensor in the registry.
|
// This struct represents one sensor in the registry.
|
||||||
|
|
|
@ -62,6 +62,8 @@ enum class SensorType : unsigned char {
|
||||||
|
|
||||||
BatteryVoltage,
|
BatteryVoltage,
|
||||||
|
|
||||||
|
BarometricPressure,
|
||||||
|
|
||||||
// Leave me at the end!
|
// Leave me at the end!
|
||||||
PlaceholderLast
|
PlaceholderLast
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
#include "map.h"
|
#include "map.h"
|
||||||
|
#include "adc_inputs.h"
|
||||||
#include "function_pointer_sensor.h"
|
#include "function_pointer_sensor.h"
|
||||||
#include "engine.h"
|
#include "engine.h"
|
||||||
|
|
||||||
|
@ -19,8 +20,28 @@ static FunctionPointerSensor mapSensor(SensorType::Map,
|
||||||
return mapWrapper.getMap();
|
return mapWrapper.getMap();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
struct GetBaroWrapper {
|
||||||
|
DECLARE_ENGINE_PTR;
|
||||||
|
|
||||||
|
float getBaro() {
|
||||||
|
return ::getBaroPressure(PASS_ENGINE_PARAMETER_SIGNATURE);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
static GetBaroWrapper baroWrapper;
|
||||||
|
|
||||||
|
static FunctionPointerSensor baroSensor(SensorType::BarometricPressure,
|
||||||
|
[]() {
|
||||||
|
return baroWrapper.getBaro();
|
||||||
|
});
|
||||||
|
|
||||||
void initMap(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
void initMap(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
||||||
INJECT_ENGINE_REFERENCE(&mapWrapper);
|
INJECT_ENGINE_REFERENCE(&mapWrapper);
|
||||||
|
INJECT_ENGINE_REFERENCE(&baroWrapper);
|
||||||
mapSensor.Register();
|
mapSensor.Register();
|
||||||
|
|
||||||
|
// Only register if configured
|
||||||
|
if (isAdcChannelValid(engineConfiguration->baroSensor.hwChannel)) {
|
||||||
|
baroSensor.Register();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,8 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "rusefi_hw_enums.h"
|
||||||
|
|
||||||
static inline bool isAdcChannelValid(adc_channel_e hwChannel) {
|
static inline bool isAdcChannelValid(adc_channel_e hwChannel) {
|
||||||
if (hwChannel <= EFI_ADC_NONE) {
|
if (hwChannel <= EFI_ADC_NONE) {
|
||||||
return false;
|
return false;
|
||||||
|
|
Loading…
Reference in New Issue