Line data Source code
1 : /** 2 : * @author Andrey Belomutskiy, (c) 2012-2020 3 : * 4 : * EGO Exhaust Gas Oxygen, also known as AFR Air/Fuel Ratio :) 5 : * 6 : * rusEfi has three options for wideband: 7 : * 1) integration with external widebands using liner analog signal wire 8 : * 2) 8-point interpolation curve to emulate a wide-band with a narrow-band sensor. 9 : * 3) CJ125 internal wideband controller is known to work with both 4.2 and 4.9 10 : * 11 : */ 12 : #include "pch.h" 13 : 14 : #include "cyclic_buffer.h" 15 : 16 0 : bool hasAfrSensor() { 17 0 : if (engineConfiguration->enableAemXSeries) { 18 0 : return true; 19 : } 20 : 21 0 : return isAdcChannelValid(engineConfiguration->afr.hwChannel); 22 : } 23 : 24 : extern float InnovateLC2AFR; 25 : 26 0 : float getAfr(SensorType type) { 27 0 : afr_sensor_s * sensor = &engineConfiguration->afr; 28 : 29 0 : if (!isAdcChannelValid(type == SensorType::Lambda1 ? engineConfiguration->afr.hwChannel : engineConfiguration->afr.hwChannel2)) { 30 0 : return 0; 31 : } 32 : 33 0 : float volts = adcGetScaledVoltage("ego", type == SensorType::Lambda1 ? sensor->hwChannel : sensor->hwChannel2); 34 : 35 0 : return interpolateMsg("AFR", sensor->v1, sensor->value1, sensor->v2, sensor->value2, volts) 36 0 : + engineConfiguration->egoValueShift; 37 : } 38 : 39 : // this method is only used for canned tunes now! User-facing selection is defined in tunerstudio.template.ini using settingSelector 40 509 : static void initEgoSensor(afr_sensor_s *sensor, ego_sensor_e type) { 41 : 42 509 : switch (type) { 43 0 : case ES_BPSX_D1: 44 : /** 45 : * This decodes BPSX D1 Wideband Controller analog signal 46 : */ 47 0 : sensor->v1 = 0; 48 0 : sensor->value1 = 9; 49 0 : sensor->v2 = 5; 50 0 : sensor->value2 = 19; 51 0 : break; 52 : 53 6 : case ES_Innovate_MTX_L: 54 6 : sensor->v1 = 0; 55 6 : sensor->value1 = 7.35; 56 6 : sensor->v2 = 5; 57 6 : sensor->value2 = 22.39; 58 6 : break; 59 500 : case ES_14Point7_Free: 60 500 : sensor->v1 = 0; 61 500 : sensor->value1 = 9.996; 62 500 : sensor->v2 = 5; 63 500 : sensor->value2 = 19.992; 64 500 : break; 65 : // technically 14Point7 and PLX use the same scale 66 3 : case ES_PLX: 67 3 : sensor->v1 = 0; 68 3 : sensor->value1 = 10; 69 3 : sensor->v2 = 5; 70 3 : sensor->value2 = 20; 71 3 : break; 72 0 : case ES_AEM: 73 0 : sensor->v1 = 0.5; 74 0 : sensor->value1 = 8.5; 75 0 : sensor->v2 = 4.5; 76 0 : sensor->value2 = 18; 77 0 : break; 78 0 : default: 79 0 : firmwareError(ObdCode::CUSTOM_EGO_TYPE, "Unexpected EGO %d", type); 80 0 : break; 81 : } 82 509 : } 83 : 84 509 : void setEgoSensor(ego_sensor_e type) { 85 509 : engineConfiguration->afr_type = type; 86 509 : initEgoSensor(&engineConfiguration->afr, type); 87 509 : }