diff options
author | Stanley Huang <stanleyhuangyc@live.com> | 2016-06-27 19:01:23 +0800 |
---|---|---|
committer | Stanley Huang <stanleyhuangyc@live.com> | 2016-06-27 19:01:23 +0800 |
commit | 23ea91258a34ab568c5dd2878f2eaa8a0dec6fe7 (patch) | |
tree | 7581a7fe8aa41dd5ceb747c81f8ce77673a48c92 /libraries | |
parent | 3655eb4501a8c191a01fa03c74a8f562d664a23e (diff) | |
download | 2021-arduino-obd-23ea91258a34ab568c5dd2878f2eaa8a0dec6fe7.tar.gz 2021-arduino-obd-23ea91258a34ab568c5dd2878f2eaa8a0dec6fe7.tar.bz2 2021-arduino-obd-23ea91258a34ab568c5dd2878f2eaa8a0dec6fe7.zip |
Bugfix
Diffstat (limited to 'libraries')
-rw-r--r-- | libraries/OBD2UART/OBD2UART.cpp | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/libraries/OBD2UART/OBD2UART.cpp b/libraries/OBD2UART/OBD2UART.cpp index a079baa..c2a28fe 100644 --- a/libraries/OBD2UART/OBD2UART.cpp +++ b/libraries/OBD2UART/OBD2UART.cpp @@ -251,7 +251,7 @@ char* COBD::getResultValue(char* buf) { char* p = buf; for (;;) { - if (isdigit(*p)) { + if (isdigit(*p) || *p == '-') { return p; } p = strchr(p, '\r'); @@ -426,7 +426,7 @@ float COBD::getTemperature() char buf[32]; if (sendCommand("ATTEMP\r", buf, sizeof(buf)) > 0) { char* p = getResultValue(buf); - return (float)(atoi(p) + 12412) / 340; + if (p) return (float)(atoi(p) + 12412) / 340; } else { return -1000; @@ -435,9 +435,10 @@ float COBD::getTemperature() bool COBD::readAccel(int& x, int& y, int& z) { - char buf[64]; + char buf[32]; if (sendCommand("ATACL\r", buf, sizeof(buf)) > 0) do { char* p = getResultValue(buf); + if (!p) break; x = atoi(p++); if (!(p = strchr(p, ','))) break; y = atoi(++p); @@ -450,9 +451,10 @@ bool COBD::readAccel(int& x, int& y, int& z) bool COBD::readGyro(int& x, int& y, int& z) { - char buf[64]; + char buf[32]; if (sendCommand("ATGYRO\r", buf, sizeof(buf)) > 0) do { char* p = getResultValue(buf); + if (!p) break; x = atoi(p++); if (!(p = strchr(p, ','))) break; y = atoi(++p); |