summaryrefslogtreecommitdiff
path: root/lpo
diff options
context:
space:
mode:
authorLudovic Pouzenc <ludovic@pouzenc.fr>2021-06-13 13:01:31 +0200
committerLudovic Pouzenc <ludovic@pouzenc.fr>2021-06-13 13:01:31 +0200
commit0282f200a3e0236f5baca9d3fd9db2fb2b66c5e6 (patch)
tree157fc41c58b0abb58c7bda24a14e09588c238441 /lpo
parent8bf6263cbf36c27533c1d24dbbd183dc2ad91533 (diff)
download2021-arduino-obd-0282f200a3e0236f5baca9d3fd9db2fb2b66c5e6.tar.gz
2021-arduino-obd-0282f200a3e0236f5baca9d3fd9db2fb2b66c5e6.tar.bz2
2021-arduino-obd-0282f200a3e0236f5baca9d3fd9db2fb2b66c5e6.zip
MyOBD: Trace every read and write to OBD adapter, lpo.ino: adapt for tracing
Extra for future : cap readDTC() call frequency to not struggle the CAN bus
Diffstat (limited to 'lpo')
-rw-r--r--lpo/MyOBD.h12
-rw-r--r--lpo/lpo.ino26
2 files changed, 28 insertions, 10 deletions
diff --git a/lpo/MyOBD.h b/lpo/MyOBD.h
index ea143be..f2124c3 100644
--- a/lpo/MyOBD.h
+++ b/lpo/MyOBD.h
@@ -1,8 +1,20 @@
#ifndef __MYOBD_H
#define __MYOBD_H
#include <OBD.h>
+
+#include <MyLCD.h>
+extern MyLCD lcd;
+
class MyOBD : public COBDI2C {
public:
+ void write(const char* s) {
+ lcd.print("<<<"); lcd.println(s);
+ COBDI2C::write(s);
+ }
+ byte receive(char* buffer, byte bufsize, int timeout) {
+ byte res = COBDI2C::receive(buffer,bufsize, timeout);
+ lcd.print(">>>"); lcd.println(buffer);
+ }
/* Fake OBD for testing
int i;
MyOBD() {
diff --git a/lpo/lpo.ino b/lpo/lpo.ino
index 85a595b..b85de2b 100644
--- a/lpo/lpo.ino
+++ b/lpo/lpo.ino
@@ -2,38 +2,36 @@
* Inpired from simple_obd_display.ino by Stanley Huang <stanley@freematics.com.au>
* (Simple OBD Data Display for Freematics OBD-II Adapter)
*************************************************************************/
-#include "MyLCD.h"
+#include <MyLCD.h>
#include "MyOBD.h"
-
MyLCD lcd;
MyOBD obd;
void setup()
{
lcd.begin();
- lcd.print("obd.begin()");
+ lcd.println("obd.begin()");
obd.begin();
- lcd.println(" done");
reconnect();
showDTC();
+ while(1); // Freeze exec here for now
initScreen();
}
void reconnect()
{
- lcd.setCursor(1,2);
- lcd.print("obd.init() ");
- lcd.setCursor(11,2);
+ lcd.println("obd.init()");
while (!obd.init()) {
- lcd.print(".");
+ lcd.println("obd.init() failed");
}
- lcd.println(" done");
}
void showDTC() {
static char buf[10];
static uint16_t codes[16];
- byte c, count = obd.readDTC(codes, 16);
+ byte c, count;
+ lcd.println("obd.readDTC()");
+ count = obd.readDTC(codes, 16);
lcd.print("DTC: ");
if ( count==0 ) {
lcd.println("none");
@@ -50,8 +48,16 @@ void loop()
{
static byte pids[]= {PID_RPM, PID_SPEED, PID_ENGINE_LOAD, PID_THROTTLE};
static byte index = 0, prev_err=obd.errors;
+ static long prevRead = 0;
+ long wait;
byte pid = pids[index];
int value;
+
+ // Don't read on CAN bus to fast, it struggle and reset main car dashboard
+ wait = millis() - prevRead + 25; // 40 Hz, 10 FPS for 4 pids
+ if ( wait > 0 ) delay(wait);
+ prevRead = millis();
+
// send a query to OBD adapter for specified OBD-II pid
if (obd.readPID(pid, value)) {
showData(pid, value);