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
|
|
|
*/
|
2021-07-25 22:05:17 -07:00
|
|
|
#include "pch.h"
|
|
|
|
|
2018-01-23 05:24:13 -08:00
|
|
|
#include "cyclic_buffer.h"
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2021-11-16 01:15:29 -08:00
|
|
|
bool hasAfrSensor() {
|
2024-09-19 20:38:24 -07:00
|
|
|
if (engineConfiguration->enableAemXSeries) {
|
2020-01-12 00:44:37 -08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-01-05 13:02:20 -08:00
|
|
|
return isAdcChannelValid(engineConfiguration->afr.hwChannel);
|
2016-12-17 08:01:40 -08:00
|
|
|
}
|
|
|
|
|
2020-05-11 09:17:42 -07:00
|
|
|
extern float InnovateLC2AFR;
|
2020-01-12 00:44:37 -08:00
|
|
|
|
2023-01-29 02:01:39 -08:00
|
|
|
float getAfr(SensorType type) {
|
2021-11-17 00:54:21 -08:00
|
|
|
afr_sensor_s * sensor = &engineConfiguration->afr;
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2023-01-29 02:01:39 -08:00
|
|
|
if (!isAdcChannelValid(type == SensorType::Lambda1 ? engineConfiguration->afr.hwChannel : engineConfiguration->afr.hwChannel2)) {
|
2020-12-28 16:19:11 -08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2023-01-29 02:01:39 -08:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2024-03-15 17:09:32 -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:
|
2023-04-11 17:01:34 -07:00
|
|
|
firmwareError(ObdCode::CUSTOM_EGO_TYPE, "Unexpected EGO %d", type);
|
2015-07-10 06:01:56 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-16 01:15:29 -08:00
|
|
|
void setEgoSensor(ego_sensor_e type) {
|
2021-11-17 00:54:21 -08:00
|
|
|
engineConfiguration->afr_type = type;
|
2015-07-10 06:01:56 -07:00
|
|
|
initEgoSensor(&engineConfiguration->afr, type);
|
|
|
|
}
|