From 9e2dd0fbafa3e56885ca30f321bf03501de423b9 Mon Sep 17 00:00:00 2001 From: Stanley Huang Date: Tue, 2 Apr 2013 14:09:28 +0800 Subject: adding DataTimeout callback --- libraries/OBD/OBD.cpp | 31 ++++++++++++++++--------------- libraries/OBD/OBD.h | 1 + 2 files changed, 17 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; } diff --git a/libraries/OBD/OBD.h b/libraries/OBD/OBD.h index 1247c49..e608fee 100644 --- a/libraries/OBD/OBD.h +++ b/libraries/OBD/OBD.h @@ -81,4 +81,5 @@ protected: virtual char ReadData(); virtual void WriteData(const char* s); virtual void WriteData(const char c); + virtual void DataTimeout() {} }; -- cgit v1.2.3