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 || engineConfiguration->enableInnovateLC2) { 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 : #if EFI_AUX_SERIAL 28 : if (engineConfiguration->enableInnovateLC2) 29 : return InnovateLC2AFR; 30 : #endif 31 : 32 0 : afr_sensor_s * sensor = &engineConfiguration->afr; 33 : 34 0 : if (!isAdcChannelValid(type == SensorType::Lambda1 ? engineConfiguration->afr.hwChannel : engineConfiguration->afr.hwChannel2)) { 35 0 : return 0; 36 : } 37 : 38 0 : float volts = getVoltageDivided("ego", type == SensorType::Lambda1 ? sensor->hwChannel : sensor->hwChannel2); 39 : 40 0 : return interpolateMsg("AFR", sensor->v1, sensor->value1, sensor->v2, sensor->value2, volts) 41 0 : + engineConfiguration->egoValueShift; 42 : } 43 : 44 : // this method is only used for canned tunes now! User-facing selection is defined in tunerstudio.template.ini using settingSelector 45 390 : static void initEgoSensor(afr_sensor_s *sensor, ego_sensor_e type) { 46 : 47 390 : switch (type) { 48 0 : case ES_BPSX_D1: 49 : /** 50 : * This decodes BPSX D1 Wideband Controller analog signal 51 : */ 52 0 : sensor->v1 = 0; 53 0 : sensor->value1 = 9; 54 0 : sensor->v2 = 5; 55 0 : sensor->value2 = 19; 56 0 : break; 57 : 58 6 : case ES_Innovate_MTX_L: 59 6 : sensor->v1 = 0; 60 6 : sensor->value1 = 7.35; 61 6 : sensor->v2 = 5; 62 6 : sensor->value2 = 22.39; 63 6 : break; 64 381 : case ES_14Point7_Free: 65 381 : sensor->v1 = 0; 66 381 : sensor->value1 = 9.996; 67 381 : sensor->v2 = 5; 68 381 : sensor->value2 = 19.992; 69 381 : break; 70 : // technically 14Point7 and PLX use the same scale 71 3 : case ES_PLX: 72 3 : sensor->v1 = 0; 73 3 : sensor->value1 = 10; 74 3 : sensor->v2 = 5; 75 3 : sensor->value2 = 20; 76 3 : break; 77 0 : case ES_AEM: 78 0 : sensor->v1 = 0.5; 79 0 : sensor->value1 = 8.5; 80 0 : sensor->v2 = 4.5; 81 0 : sensor->value2 = 18; 82 0 : break; 83 0 : default: 84 0 : firmwareError(ObdCode::CUSTOM_EGO_TYPE, "Unexpected EGO %d", type); 85 0 : break; 86 : } 87 390 : } 88 : 89 390 : void setEgoSensor(ego_sensor_e type) { 90 390 : engineConfiguration->afr_type = type; 91 390 : initEgoSensor(&engineConfiguration->afr, type); 92 390 : }