From 7a411f2ae5cc61f69766647934e896d698a51d28 Mon Sep 17 00:00:00 2001 From: Jim Whitelaw Date: Sat, 16 Dec 2023 22:57:46 -0700 Subject: [PATCH] Fix for issue myELM327.supportedPIDs_1_20() not working as expected #157 --- .../ESP32_CheckPIDs_1_20.ino | 53 +++++++++++++++++++ src/ELMduino.cpp | 2 +- 2 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 examples/ESP32_CheckPIDs_1_20/ESP32_CheckPIDs_1_20.ino diff --git a/examples/ESP32_CheckPIDs_1_20/ESP32_CheckPIDs_1_20.ino b/examples/ESP32_CheckPIDs_1_20/ESP32_CheckPIDs_1_20.ino new file mode 100644 index 0000000..735bbda --- /dev/null +++ b/examples/ESP32_CheckPIDs_1_20/ESP32_CheckPIDs_1_20.ino @@ -0,0 +1,53 @@ +#include "BluetoothSerial.h" +#include "ELMduino.h" + +BluetoothSerial SerialBT; +#define ELM_PORT SerialBT +#define DEBUG_PORT Serial + +ELM327 myELM327; + +uint32_t rpm = 0; + +void setup() +{ +#if LED_BUILTIN + pinMode(LED_BUILTIN, OUTPUT); + digitalWrite(LED_BUILTIN, LOW); +#endif + + DEBUG_PORT.begin(115200); + // SerialBT.setPin("1234"); + ELM_PORT.begin("ArduHUD", true); + + if (!ELM_PORT.connect("OBDII")) + { + DEBUG_PORT.println("Couldn't connect to OBD scanner - Phase 1"); + while (1) + ; + } + + if (!myELM327.begin(ELM_PORT, true, 2000)) + { + Serial.println("Couldn't connect to OBD scanner - Phase 2"); + while (1) + ; + } + + Serial.println("Connected to ELM327"); +} + +void loop() +{ + uint32_t pids = myELM327.supportedPIDs_1_20(); + + if (myELM327.nb_rx_state == ELM_SUCCESS) + { + Serial.print("Supported PIDS: "); Serial.println(pids); + delay(10000); + } + else if (myELM327.nb_rx_state != ELM_GETTING_MSG) + { + myELM327.printError(); + } +} diff --git a/src/ELMduino.cpp b/src/ELMduino.cpp index 69c84cf..ac57041 100644 --- a/src/ELMduino.cpp +++ b/src/ELMduino.cpp @@ -2359,7 +2359,7 @@ uint64_t ELM327::findResponse() { uint8_t payloadIndex = firstDatum + i; uint8_t bitsOffset = 4 * (numPayChars - i - 1); - response = response | (ctoi(payload[payloadIndex]) << bitsOffset); + response = response | ((uint64_t)ctoi(payload[payloadIndex]) << bitsOffset); } // It is useful to have the response bytes