summaryrefslogtreecommitdiff
path: root/libraries
diff options
context:
space:
mode:
authorStanley Huang <stanleyhuangyc@gmail.com>2014-09-07 00:18:22 +1000
committerStanley Huang <stanleyhuangyc@gmail.com>2014-09-07 00:18:22 +1000
commitdc68f92f175fa8e0bf761baed4b49dc1e2aa150b (patch)
tree7d47ec70fa4bc156932488ea8b04b99f7cb46de5 /libraries
parent78698f65a918bfdb90dc3a19a85c84c9833125ba (diff)
download2021-arduino-obd-dc68f92f175fa8e0bf761baed4b49dc1e2aa150b.tar.gz
2021-arduino-obd-dc68f92f175fa8e0bf761baed4b49dc1e2aa150b.tar.bz2
2021-arduino-obd-dc68f92f175fa8e0bf761baed4b49dc1e2aa150b.zip
Update getVoltage()
Diffstat (limited to 'libraries')
-rw-r--r--libraries/OBD/OBD.cpp16
-rw-r--r--libraries/OBD/OBD.h4
2 files changed, 10 insertions, 10 deletions
diff --git a/libraries/OBD/OBD.cpp b/libraries/OBD/OBD.cpp
index a568d7a..0e09640 100644
--- a/libraries/OBD/OBD.cpp
+++ b/libraries/OBD/OBD.cpp
@@ -245,7 +245,7 @@ void COBD::wakeup()
receive();
}
-unsigned int COBD::getVoltage()
+int COBD::getVoltage()
{
char buf[OBD_RECV_BUF_SIZE];
write("ATRV\r");
@@ -256,16 +256,16 @@ unsigned int COBD::getVoltage()
int v1 = atoi(buf);
int v2 = 0;
char *p = strchr(buf, '.');
- if (p) v2 = atoi(p + 1);
- if (v2 < 10)
- v2 *= 100;
- else if (v2 <100)
- v2 *= 10;
- return (unsigned int)v1 * 1000 + v2;
+ if (p++) {
+ if (*p >= '0' && *p <= '9') {
+ v2 = *p - '0';
+ }
+ }
+ return v1 * 10 + v2;
}
}
}
- return 0;
+ return -1;
}
bool COBD::isValidPID(byte pid)
diff --git a/libraries/OBD/OBD.h b/libraries/OBD/OBD.h
index 11fa70d..0a15e97 100644
--- a/libraries/OBD/OBD.h
+++ b/libraries/OBD/OBD.h
@@ -121,8 +121,8 @@ public:
virtual bool setProtocol(OBD_PROTOCOLS h = PROTO_AUTO);
// clear diagnostic trouble code
virtual void clearDTC();
- // get battery voltage (in mV, 12500 for 12.5V, works without ECU)
- virtual unsigned int getVoltage();
+ // get battery voltage (in 0.1V, e.g. 125 for 12.5V, works without ECU)
+ virtual int getVoltage();
// send query for specified PID
virtual void sendQuery(byte pid);
// retrive and parse the response of specifie PID