2015-12-31 13:02:30 -08:00
|
|
|
/**
|
2017-01-03 03:05:22 -08:00
|
|
|
* @author Andrey Belomutskiy, (c) 2012-2017
|
2015-12-31 13:02:30 -08:00
|
|
|
*/
|
2016-01-03 16:01:43 -08:00
|
|
|
#include "ego.h"
|
2015-07-10 06:01:56 -07:00
|
|
|
#include "interpolation.h"
|
|
|
|
#include "adc_inputs.h"
|
|
|
|
#include "engine.h"
|
|
|
|
|
|
|
|
EXTERN_ENGINE;
|
|
|
|
|
2017-05-15 20:33:22 -07:00
|
|
|
bool hasAfrSensor(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
2016-12-17 08:01:40 -08:00
|
|
|
return engineConfiguration->afr.hwChannel != EFI_ADC_NONE;
|
|
|
|
}
|
|
|
|
|
2017-05-15 20:33:22 -07:00
|
|
|
float getAfr(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
2017-01-22 14:03:31 -08:00
|
|
|
afr_sensor_s * sensor = &CONFIG(afr);
|
2015-07-10 06:01:56 -07:00
|
|
|
|
|
|
|
float volts = getVoltageDivided("ego", sensor->hwChannel);
|
|
|
|
|
2017-10-29 17:29:02 -07:00
|
|
|
if (boardConfiguration->afr_type == ES_NarrowBand) {
|
|
|
|
return interpolate2d("narrow", volts, engineConfiguration->narrowToWideOxygenBins, engineConfiguration->narrowToWideOxygen, NARROW_BAND_WIDE_BAND_CONVERSION_SIZE);
|
|
|
|
}
|
|
|
|
|
2016-06-22 21:01:55 -07:00
|
|
|
return interpolate(sensor->v1, sensor->value1, sensor->v2, sensor->value2, volts)
|
|
|
|
+ engineConfiguration->egoValueShift;
|
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;
|
|
|
|
case ES_NarrowBand:
|
|
|
|
sensor->v1 = 0.1;
|
|
|
|
sensor->value1 = 15;
|
|
|
|
sensor->v2 = 0.9;
|
|
|
|
sensor->value2 = 14;
|
|
|
|
break;
|
|
|
|
default:
|
2017-04-19 19:03:14 -07:00
|
|
|
firmwareError(CUSTOM_EGO_TYPE, "Unexpected EGO %d", type);
|
2015-07-10 06:01:56 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-15 20:33:22 -07:00
|
|
|
void setEgoSensor(ego_sensor_e type DECLARE_ENGINE_PARAMETER_SUFFIX) {
|
2015-07-10 06:01:56 -07:00
|
|
|
boardConfiguration->afr_type = type;
|
|
|
|
initEgoSensor(&engineConfiguration->afr, type);
|
|
|
|
}
|