diff options
author | Stanley Huang <stanleyhuangyc@gmail.com> | 2014-06-28 12:03:12 +1000 |
---|---|---|
committer | Stanley Huang <stanleyhuangyc@gmail.com> | 2014-06-28 12:03:12 +1000 |
commit | 82f6938f17b3afb13e0403c87f3fdef4e2ff180f (patch) | |
tree | d9f78b3053691cd9bcac8547f91074a50df01b92 | |
parent | 04ff9adeac754d1cf917a341c46dcb8eb8ba1455 (diff) | |
download | 2021-arduino-obd-82f6938f17b3afb13e0403c87f3fdef4e2ff180f.tar.gz 2021-arduino-obd-82f6938f17b3afb13e0403c87f3fdef4e2ff180f.tar.bz2 2021-arduino-obd-82f6938f17b3afb13e0403c87f3fdef4e2ff180f.zip |
Define more OBD-II PIDs
-rw-r--r-- | libraries/OBD/OBD.cpp | 78 | ||||
-rw-r--r-- | libraries/OBD/OBD.h | 26 |
2 files changed, 50 insertions, 54 deletions
diff --git a/libraries/OBD/OBD.cpp b/libraries/OBD/OBD.cpp index 7f6828b..2728a09 100644 --- a/libraries/OBD/OBD.cpp +++ b/libraries/OBD/OBD.cpp @@ -104,6 +104,7 @@ int COBD::normalizeData(byte pid, char* data) int result; switch (pid) { case PID_RPM: + case PID_EVAP_SYS_VAPOR_PRESSURE: result = getLargeValue(data) >> 2; break; case PID_FUEL_PRESSURE: @@ -116,10 +117,19 @@ int COBD::normalizeData(byte pid, char* data) result = getTemperatureValue(data); break; case PID_THROTTLE: + case PID_COMMANDED_EGR: + case PID_COMMANDED_EVAPORATIVE_PURGE: + case PID_FUEL_LEVEL_INPUT: + case PID_RELATIVE_THROTTLE_POS: + case PID_ABSOLUTE_THROTTLE_POS_B: + case PID_ABSOLUTE_THROTTLE_POS_C: + case PID_ACC_PEDAL_POS_D: + case PID_ACC_PEDAL_POS_E: + case PID_ACC_PEDAL_POS_F: + case PID_COMMANDED_THROTTLE_ACTUATOR: case PID_ENGINE_LOAD: - case PID_FUEL_LEVEL: case PID_ABSOLUTE_ENGINE_LOAD: - case PID_ETHANOL_PERCENTAGE: + case PID_ETHANOL_FUEL: case PID_HYBRID_BATTERY_PERCENTAGE: result = getPercentageValue(data); break; @@ -130,6 +140,9 @@ int COBD::normalizeData(byte pid, char* data) result = (int)(getSmallValue(data) / 2) - 64; break; case PID_DISTANCE: // km + case PID_DISTANCE_WITH_MIL: // km + case PID_TIME_WITH_MIL: // minute + case PID_TIME_SINCE_CODES_CLEARED: // minute case PID_RUNTIME: // second case PID_FUEL_RAIL_PRESSURE: // kPa case PID_ENGINE_REF_TORQUE: // Nm @@ -141,9 +154,20 @@ int COBD::normalizeData(byte pid, char* data) case PID_ENGINE_FUEL_RATE: // L/h result = getLargeValue(data) / 20; break; + case PID_ENGINE_TORQUE_DEMANDED: // % case PID_ENGINE_TORQUE_PERCENTAGE: // % result = (int)getSmallValue(data) - 125; break; + case PID_SHORT_TERM_FUEL_TRIM_1: + case PID_LONG_TERM_FUEL_TRIM_1: + case PID_SHORT_TERM_FUEL_TRIM_2: + case PID_LONG_TERM_FUEL_TRIM_2: + case PID_EGR_ERROR: + result = ((int)getSmallValue(data) - 128) * 100 / 128; + break; + case PID_FUEL_INJECTION_TIMING: + result = ((int32_t)getLargeValue(data) - 26880) / 128; + break; default: result = getSmallValue(data); } @@ -459,53 +483,3 @@ void COBDI2C::loadData() Wire.requestFrom((byte)m_addr, (byte)MAX_PAYLOAD_SIZE, (byte)0); Wire.readBytes((char*)obdInfo, MAX_PAYLOAD_SIZE); } - -uint16_t COBDI2C::getData(byte pid, int& result) -{ - byte n; - for (n = 0; n < MAX_PIDS && obdPid[n] != pid; n++); - if (n == MAX_PIDS) - return -1; - - PID_INFO* pi = obdInfo + n; - switch (pid) { - case PID_RPM: - result = pi->value >> 2; - break; - case PID_FUEL_PRESSURE: - result = (int)pi->value * 3; - break; - case PID_COOLANT_TEMP: - case PID_INTAKE_TEMP: - case PID_AMBIENT_TEMP: - case PID_ENGINE_OIL_TEMP: - result = (int)pi->value - 40; - break; - case PID_THROTTLE: - case PID_ENGINE_LOAD: - case PID_FUEL_LEVEL: - case PID_ABSOLUTE_ENGINE_LOAD: - case PID_ETHANOL_PERCENTAGE: - case PID_HYBRID_BATTERY_PERCENTAGE: - result = pi->value * 100 / 255; // % - break; - case PID_MAF_FLOW: - result = pi->value / 100; - break; - case PID_TIMING_ADVANCE: - result = (int)pi->value / 2 - 64; - break; - case PID_CONTROL_MODULE_VOLTAGE: // V - result = pi->value / 1000; - break; - case PID_ENGINE_FUEL_RATE: // L/h - result = pi->value / 20; - break; - case PID_ENGINE_TORQUE_PERCENTAGE: // % - result = (int)pi->value - 125; - break; - default: - result = pi->value; - } - return result; -} diff --git a/libraries/OBD/OBD.h b/libraries/OBD/OBD.h index 1d8d7f9..ebc86b1 100644 --- a/libraries/OBD/OBD.h +++ b/libraries/OBD/OBD.h @@ -26,6 +26,10 @@ // Mode 1 PIDs
#define PID_ENGINE_LOAD 0x04
#define PID_COOLANT_TEMP 0x05
+#define PID_SHORT_TERM_FUEL_TRIM_1 0x06
+#define PID_LONG_TERM_FUEL_TRIM_1 0x07
+#define PID_SHORT_TERM_FUEL_TRIM_2 0x08
+#define PID_LONG_TERM_FUEL_TRIM_2 0x09
#define PID_FUEL_PRESSURE 0x0A
#define PID_INTAKE_MAP 0x0B
#define PID_RPM 0x0C
@@ -34,18 +38,36 @@ #define PID_INTAKE_TEMP 0x0F
#define PID_MAF_FLOW 0x10
#define PID_THROTTLE 0x11
+#define PID_AUX_INPUT 0x1E
#define PID_RUNTIME 0x1F
-#define PID_FUEL_LEVEL 0x2F
+#define PID_DISTANCE_WITH_MIL 0x21
+#define PID_COMMANDED_EGR 0x2C
+#define PID_EGR_ERROR 0x2D
+#define PID_COMMANDED_EVAPORATIVE_PURGE 0x2E
+#define PID_FUEL_LEVEL_INPUT 0x2F
+#define PID_WARMS_UPS 0x30
#define PID_DISTANCE 0x31
+#define PID_EVAP_SYS_VAPOR_PRESSURE 0x32
#define PID_BAROMETRIC 0x33
#define PID_CONTROL_MODULE_VOLTAGE 0x42
#define PID_ABSOLUTE_ENGINE_LOAD 0x43
+#define PID_RELATIVE_THROTTLE_POS 0x45
#define PID_AMBIENT_TEMP 0x46
-#define PID_ETHANOL_PERCENTAGE 0x52
+#define PID_ABSOLUTE_THROTTLE_POS_B 0x47
+#define PID_ABSOLUTE_THROTTLE_POS_C 0x48
+#define PID_ACC_PEDAL_POS_D 0x49
+#define PID_ACC_PEDAL_POS_E 0x4A
+#define PID_ACC_PEDAL_POS_F 0x4B
+#define PID_COMMANDED_THROTTLE_ACTUATOR 0x4C
+#define PID_TIME_WITH_MIL 0x4D
+#define PID_TIME_SINCE_CODES_CLEARED 0x4E
+#define PID_ETHANOL_FUEL 0x52
#define PID_FUEL_RAIL_PRESSURE 0x59
#define PID_HYBRID_BATTERY_PERCENTAGE 0x5B
#define PID_ENGINE_OIL_TEMP 0x5C
+#define PID_FUEL_INJECTION_TIMING 0x5D
#define PID_ENGINE_FUEL_RATE 0x5E
+#define PID_ENGINE_TORQUE_DEMANDED 0x61
#define PID_ENGINE_TORQUE_PERCENTAGE 0x62
#define PID_ENGINE_REF_TORQUE 0x63
|