summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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);