summaryrefslogtreecommitdiff
path: root/libraries/OBD/OBD.cpp
diff options
context:
space:
mode:
authorStanley Huang <stanleyhuangyc@gmail.com>2015-05-04 11:23:46 +1000
committerStanley Huang <stanleyhuangyc@gmail.com>2015-05-04 11:23:46 +1000
commitc09ad9a88036f9f4c658abe795cf2ee1eb8d3e1c (patch)
tree6898fcd2ba156f919896afcff1828e4c5a3d964e /libraries/OBD/OBD.cpp
parentc56afd24349d1b4bdf1befe0622a30a2c15c9b48 (diff)
download2021-arduino-obd-c09ad9a88036f9f4c658abe795cf2ee1eb8d3e1c.tar.gz
2021-arduino-obd-c09ad9a88036f9f4c658abe795cf2ee1eb8d3e1c.tar.bz2
2021-arduino-obd-c09ad9a88036f9f4c658abe795cf2ee1eb8d3e1c.zip
Fix setBaudRate()
Diffstat (limited to 'libraries/OBD/OBD.cpp')
-rw-r--r--libraries/OBD/OBD.cpp21
1 files changed, 9 insertions, 12 deletions
diff --git a/libraries/OBD/OBD.cpp b/libraries/OBD/OBD.cpp
index 72955f0..8ee5ae9 100644
--- a/libraries/OBD/OBD.cpp
+++ b/libraries/OBD/OBD.cpp
@@ -2,7 +2,7 @@
* Arduino Library for OBD-II UART/I2C Adapter
* Distributed under GPL v2.0
* Visit http://freematics.com for more information
-* (C)2012-2014 Stanley Huang <stanleyhuangyc@gmail.com>
+* (C)2012-2015 Stanley Huang <stanleyhuangyc@gmail.com>
*************************************************************************/
#include <Arduino.h>
@@ -377,17 +377,14 @@ void COBD::end()
bool COBD::setBaudRate(unsigned long baudrate)
{
- char buf[OBD_RECV_BUF_SIZE];
OBDUART.print("ATBR1 ");
OBDUART.print(baudrate);
OBDUART.print('\r');
- if (receive(buf) && strstr(buf, "OK")) {
- OBDUART.end();
- OBDUART.begin(baudrate);
- return true;
- } else {
- return false;
- }
+ delay(100);
+ OBDUART.end();
+ OBDUART.begin(baudrate);
+ while (available()) read();
+ return true;
}
bool COBD::initGPS(unsigned long baudrate)
@@ -490,7 +487,7 @@ void COBDI2C::write(const char* s)
Wire.endTransmission();
}
-bool COBDI2C::sendCommand(byte cmd, uint8_t data, byte* payload, byte payloadBytes)
+bool COBDI2C::sendCommandBlock(byte cmd, uint8_t data, byte* payload, byte payloadBytes)
{
COMMAND_BLOCK cmdblock = {millis(), cmd, data};
Wire.beginTransmission(I2C_ADDR);
@@ -548,13 +545,13 @@ void COBDI2C::setPID(byte pid)
void COBDI2C::applyPIDs()
{
- sendCommand(CMD_APPLY_OBD_PIDS, 0, (byte*)obdPid, sizeof(obdPid));
+ sendCommandBlock(CMD_APPLY_OBD_PIDS, 0, (byte*)obdPid, sizeof(obdPid));
delay(200);
}
void COBDI2C::loadData()
{
- sendCommand(CMD_LOAD_OBD_DATA);
+ sendCommandBlock(CMD_LOAD_OBD_DATA);
dataIdleLoop();
Wire.requestFrom((byte)I2C_ADDR, (byte)MAX_PAYLOAD_SIZE, (byte)0);
Wire.readBytes((char*)obdInfo, MAX_PAYLOAD_SIZE);