rusefi/firmware/controllers/sensors/impl/ego.cpp

88 lines
2.2 KiB
C++
Raw Normal View History

2015-12-31 13:02:30 -08:00
/**
2020-01-13 18:57:43 -08:00
* @author Andrey Belomutskiy, (c) 2012-2020
2017-11-14 15:49:16 -08:00
*
* EGO Exhaust Gas Oxygen, also known as AFR Air/Fuel Ratio :)
*
2019-03-17 15:11:03 -07:00
* rusEfi has three options for wideband:
* 1) integration with external widebands using liner analog signal wire
* 2) 8-point interpolation curve to emulate a wide-band with a narrow-band sensor.
* 3) CJ125 internal wideband controller is known to work with both 4.2 and 4.9
2017-11-14 15:49:16 -08:00
*
2015-12-31 13:02:30 -08:00
*/
#include "pch.h"
#include "cyclic_buffer.h"
2015-07-10 06:01:56 -07:00
bool hasAfrSensor() {
if (engineConfiguration->enableAemXSeries) {
return true;
}
return isAdcChannelValid(engineConfiguration->afr.hwChannel);
2016-12-17 08:01:40 -08:00
}
extern float InnovateLC2AFR;
float getAfr(SensorType type) {
afr_sensor_s * sensor = &engineConfiguration->afr;
2015-07-10 06:01:56 -07:00
if (!isAdcChannelValid(type == SensorType::Lambda1 ? engineConfiguration->afr.hwChannel : engineConfiguration->afr.hwChannel2)) {
2020-12-28 16:19:11 -08:00
return 0;
}
float volts = getVoltageDivided("ego", type == SensorType::Lambda1 ? sensor->hwChannel : sensor->hwChannel2);
2015-07-10 06:01:56 -07:00
2018-06-12 02:45:11 -07:00
return interpolateMsg("AFR", sensor->v1, sensor->value1, sensor->v2, sensor->value2, volts)
2016-06-22 21:01:55 -07:00
+ engineConfiguration->egoValueShift;
2015-07-10 06:01:56 -07:00
}
// this method is only used for canned tunes now! User-facing selection is defined in tunerstudio.template.ini using settingSelector
2015-07-10 06:01:56 -07:00
static void initEgoSensor(afr_sensor_s *sensor, ego_sensor_e type) {
switch (type) {
case ES_BPSX_D1:
/**
* This decodes BPSX D1 Wideband Controller analog signal
*/
sensor->v1 = 0;
sensor->value1 = 9;
sensor->v2 = 5;
sensor->value2 = 19;
break;
case ES_Innovate_MTX_L:
sensor->v1 = 0;
sensor->value1 = 7.35;
sensor->v2 = 5;
sensor->value2 = 22.39;
break;
case ES_14Point7_Free:
sensor->v1 = 0;
sensor->value1 = 9.996;
sensor->v2 = 5;
sensor->value2 = 19.992;
break;
// technically 14Point7 and PLX use the same scale
case ES_PLX:
sensor->v1 = 0;
sensor->value1 = 10;
sensor->v2 = 5;
sensor->value2 = 20;
break;
2023-08-24 13:29:35 -07:00
case ES_AEM:
sensor->v1 = 0.5;
sensor->value1 = 8.5;
sensor->v2 = 4.5;
sensor->value2 = 18;
break;
2015-07-10 06:01:56 -07:00
default:
firmwareError(ObdCode::CUSTOM_EGO_TYPE, "Unexpected EGO %d", type);
2015-07-10 06:01:56 -07:00
break;
}
}
void setEgoSensor(ego_sensor_e type) {
engineConfiguration->afr_type = type;
2015-07-10 06:01:56 -07:00
initEgoSensor(&engineConfiguration->afr, type);
}