diff options
Diffstat (limited to 'libraries/OBD/OBD.cpp')
-rw-r--r-- | libraries/OBD/OBD.cpp | 16 |
1 files changed, 8 insertions, 8 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) |