summaryrefslogtreecommitdiff
path: root/libraries/OBD/OBD.cpp
diff options
context:
space:
mode:
authorStanley Huang <stanleyhuangyc@gmail.com>2013-04-02 14:09:28 +0800
committerStanley Huang <stanleyhuangyc@gmail.com>2013-04-02 14:09:28 +0800
commit9e2dd0fbafa3e56885ca30f321bf03501de423b9 (patch)
tree270cc661c97c6743006a04627899f3e9f9cb0919 /libraries/OBD/OBD.cpp
parent7af9330e5a976b4715eb406d613dff915dc292d8 (diff)
download2021-arduino-obd-9e2dd0fbafa3e56885ca30f321bf03501de423b9.tar.gz
2021-arduino-obd-9e2dd0fbafa3e56885ca30f321bf03501de423b9.tar.bz2
2021-arduino-obd-9e2dd0fbafa3e56885ca30f321bf03501de423b9.zip
adding DataTimeout callback
Diffstat (limited to 'libraries/OBD/OBD.cpp')
-rw-r--r--libraries/OBD/OBD.cpp31
1 files changed, 16 insertions, 15 deletions
diff --git a/libraries/OBD/OBD.cpp b/libraries/OBD/OBD.cpp
index b3da34e..938523b 100644
--- a/libraries/OBD/OBD.cpp
+++ b/libraries/OBD/OBD.cpp
@@ -240,12 +240,12 @@ bool COBD::Init(bool passive)
strcpy_P(cmd, s_initcmd[i]);
WriteData(cmd);
}
- n = 0;
- prompted = 0;
+ n = 0;
+ prompted = 0;
currentMillis = millis();
- for (;;) {
- if (DataAvailable()) {
- char c = ReadData();
+ for (;;) {
+ if (DataAvailable()) {
+ char c = ReadData();
if (c == '>') {
buffer[n] = 0;
prompted++;
@@ -254,16 +254,17 @@ bool COBD::Init(bool passive)
}
} else if (prompted) {
break;
- } else {
- unsigned long elapsed = millis() - currentMillis;
- if (elapsed > OBD_TIMEOUT_INIT) {
- // init timeout
- //WriteData("\r");
- return false;
- }
- }
- }
- }
+ } else {
+ unsigned long elapsed = millis() - currentMillis;
+ if (elapsed > OBD_TIMEOUT_INIT) {
+ // init timeout
+ //WriteData("\r");
+ return false;
+ }
+ DataTimeout();
+ }
+ }
+ }
errors = 0;
return true;
}