summaryrefslogtreecommitdiff
path: root/samples
diff options
context:
space:
mode:
Diffstat (limited to 'samples')
-rw-r--r--samples/dashboard_1602/dashboard_1602.ino8
-rw-r--r--samples/dashboard_4884/dashboard_4884.ino46
-rw-r--r--samples/dashboard_oled/dashboard_oled.ino20
-rw-r--r--samples/obdtest/obdtest.ino42
4 files changed, 51 insertions, 65 deletions
diff --git a/samples/dashboard_1602/dashboard_1602.ino b/samples/dashboard_1602/dashboard_1602.ino
index cfabbe9..848800e 100644
--- a/samples/dashboard_1602/dashboard_1602.ino
+++ b/samples/dashboard_1602/dashboard_1602.ino
@@ -26,7 +26,7 @@ uint8_t modes[2] = {0, 2};
const char modePids[] = {PID_RPM, PID_SPEED, PID_THROTTLE, PID_ENGINE_LOAD,
PID_COOLANT_TEMP, PID_INTAKE_TEMP, PID_AMBIENT_TEMP, PID_MAF_FLOW,
- PID_ABS_ENGINE_LOAD, PID_FUEL_PRESSURE, PID_INTAKE_PRESSURE, PID_BAROMETRIC,
+ PID_ABS_ENGINE_LOAD, PID_FUEL_PRESSURE, PID_INTAKE_MAP, PID_BAROMETRIC,
PID_TIMING_ADVANCE, PID_FUEL_LEVEL, PID_RUNTIME, PID_DISTANCE};
const char* modeLabels[] = {
@@ -73,7 +73,7 @@ bool showData(int index)
uint8_t mode = modes[index];
uint8_t pid = modePids[mode];
digitalWrite(13, HIGH); // set the LED on
- if (!obd.ReadSensor(pid, value)) {
+ if (!obd.readSensor(pid, value)) {
// display received data on error
lcd.cursorTo(index + 1, 0);
lcd.printIn("Error");
@@ -99,7 +99,7 @@ bool setupConnection()
char buf[16];
lcd.clear();
lcd.printIn("Connecting...");
- while (!obd.Init()) {
+ while (!obd.init()) {
lcd.cursorTo(2, 0);
sprintf(buf, "Attempts #%d", ++errors);
lcd.printIn(buf);
@@ -115,7 +115,7 @@ void setup()
{
pinMode(13, OUTPUT); //we'll use the debug LED to output a heartbeat
lcd.init();
- OBDUART.begin(OBD_SERIAL_BAUDRATE);
+ obd.begin();
setupConnection();
}
diff --git a/samples/dashboard_4884/dashboard_4884.ino b/samples/dashboard_4884/dashboard_4884.ino
index 8239b73..6f845e2 100644
--- a/samples/dashboard_4884/dashboard_4884.ino
+++ b/samples/dashboard_4884/dashboard_4884.ino
@@ -10,14 +10,6 @@
#include "OBD.h"
#include "LCD4884.h"
-// the following line toggles between hardware serial and software serial
-// #define USE_SOFTSERIAL
-
-#ifdef USE_SOFTSERIAL
-#include <SoftwareSerial.h>
-SoftwareSerial mySerial(11, 12); // RX, TX
-#endif
-
//keypad debounce parameter
#define DEBOUNCE_MAX 15
#define DEBOUNCE_ON 10
@@ -168,9 +160,10 @@ class COBDDash : public COBD
public:
void Connect()
{
+ int value;
lcd.LCD_clear();
lcd.LCD_write_string(0, 0, "Connecting..", MENU_NORMAL);
- for (int n = 0; !Init(); n++) {
+ for (int n = 0; !init(); n++) {
lcd.LCD_putchar('.');
if (n == 3) lcd.backlight(OFF);
}
@@ -178,17 +171,15 @@ public:
lcd.backlight(ON); //Turn on the backlight
lcd.LCD_clear();
lcd.LCD_write_string(0, 0, "Connected!", MENU_NORMAL);
-
- int value;
lcd.LCD_write_string(0, 1, "Wait ECU start", MENU_NORMAL);
do {
delay(1000);
- } while (!ReadSensor(PID_RPM, value));
+ } while (!readSensor(PID_RPM, value));
lcd.LCD_write_string(0, 2, "ECU started ", MENU_NORMAL);
lcd.LCD_write_string(0, 3, "Wait ignition ", MENU_NORMAL);
do {
delay(100);
- } while (!ReadSensor(PID_RPM, value) || value == 0);
+ } while (!readSensor(PID_RPM, value) || value == 0);
lcd.LCD_write_string(0, 4, "Engine started", MENU_NORMAL);
delay(1000);
}
@@ -272,49 +263,49 @@ public:
private:
void DisplayData1()
{
- if (ReadSensor(PID_RPM, value)) {
+ if (readSensor(PID_RPM, value)) {
ShowRPM(value);
}
- if (ReadSensor(PID_SPEED, value)) {
+ if (readSensor(PID_SPEED, value)) {
ShowSpeed(value);
}
- if (ReadSensor(PID_ENGINE_LOAD, value)) {
+ if (readSensor(PID_ENGINE_LOAD, value)) {
ShowEngineLoad(value);
}
}
void DisplayData2()
{
- if (ReadSensor(PID_RPM, value)) {
+ if (readSensor(PID_RPM, value)) {
ShowRPM(value);
}
- if (ReadSensor(PID_SPEED, value)) {
+ if (readSensor(PID_SPEED, value)) {
ShowSpeed2(value);
}
}
void DisplayData21()
{
- if (ReadSensor(PID_COOLANT_TEMP, value)) {
+ if (readSensor(PID_COOLANT_TEMP, value)) {
ShowTemperature(value, 42, 3);
}
}
void DisplayData22()
{
- if (ReadSensor(PID_INTAKE_TEMP, value)) {
+ if (readSensor(PID_INTAKE_TEMP, value)) {
ShowTemperature(value, 42, 4);
}
}
void DisplayData23()
{
- if (ReadSensor(PID_AMBIENT_TEMP, value)) {
+ if (readSensor(PID_AMBIENT_TEMP, value)) {
ShowTemperature(value, 42, 5);
}
}
void DisplayData3()
{
- if (ReadSensor(PID_SPEED, value)) {
+ if (readSensor(PID_SPEED, value)) {
ShowSpeed2(value);
}
- if (ReadSensor(PID_INTAKE_PRESSURE, value)) {
+ if (readSensor(PID_INTAKE_MAP, value)) {
char buf[8];
sprintf(buf, "%3u", value);
lcd.LCD_write_string(24, 4, buf, MENU_NORMAL);
@@ -323,7 +314,7 @@ private:
sprintf(buf, "%d.%02d", boost / 100, boost % 100);
lcd.LCD_write_string_big(0, 0, buf, MENU_NORMAL);
}
- if (ReadSensor(PID_FUEL_PRESSURE, value)) {
+ if (readSensor(PID_FUEL_PRESSURE, value)) {
char buf[8];
sprintf(buf, "%3u", value);
lcd.LCD_write_string(24, 5, buf, MENU_NORMAL);
@@ -446,12 +437,7 @@ void setup()
pinMode(13, OUTPUT);
-#ifndef USE_SOFTSERIAL
- OBDUART.begin(OBD_SERIAL_BAUDRATE);
-#else
- Serial.begin(9600);
- mySerial.begin(OBD_SERIAL_BAUDRATE);
-#endif
+ obd.begin();
}
// Timer2 interrupt routine -
diff --git a/samples/dashboard_oled/dashboard_oled.ino b/samples/dashboard_oled/dashboard_oled.ino
index 8ee8a9c..653a006 100644
--- a/samples/dashboard_oled/dashboard_oled.ino
+++ b/samples/dashboard_oled/dashboard_oled.ino
@@ -35,7 +35,7 @@ public:
char buf[16];
InitScreen();
- for (int n = 1; !Init(); n++) {
+ for (int n = 1; !init(); n++) {
sprintf(buf, "Connecting [%d]", n);
if (n <= 20)
DisplayString(buf);
@@ -48,14 +48,14 @@ public:
DisplayString("Wait ECU start", 0 , 2);
do {
delay(500);
- } while (!ReadSensor(PID_RPM, value));
+ } while (!readSensor(PID_RPM, value));
DisplayString("ECU started ", 0 , 4);
delay(500);
DisplayString("Wait ignition ", 0 , 6);
delay(500);
do {
delay(500);
- } while (!ReadSensor(PID_RPM, value) || value == 0);
+ } while (!readSensor(PID_RPM, value) || value == 0);
DisplayString("Engine started!", 0 , 6);
delay(1000);
}
@@ -71,35 +71,35 @@ public:
if (count == 0) {
DisplayString("AIR: ", 0, 6);
- if (ReadSensor(PID_INTAKE_TEMP, value)) {
+ if (readSensor(PID_INTAKE_TEMP, value)) {
sprintf(buf, "%4dC", value);
DisplayString(buf, 11 * 8, 6);
}
} else if (count == LOOP_COUNT / 2) {
DisplayString("ENGINE: ", 0, 6);
- if (ReadSensor(PID_COOLANT_TEMP, value)) {
+ if (readSensor(PID_COOLANT_TEMP, value)) {
sprintf(buf, "%4dC", value);
DisplayString(buf, 11 * 8, 6);
}
}
if (count < LOOP_COUNT / 2) {
- if (ReadSensor(PID_INTAKE_PRESSURE, value)) {
+ if (readSensor(PID_INTAKE_MAP, value)) {
sprintf(buf, "%dkPa ", value);
DisplayString(buf, 5 * 8, 6);
}
} else {
- if (ReadSensor(PID_ENGINE_LOAD, value)) {
+ if (readSensor(PID_ENGINE_LOAD, value)) {
sprintf(buf, "%d%% ", value);
DisplayString(buf, 8 * 8, 6);
}
}
- if (ReadSensor(PID_RPM, value)) {
+ if (readSensor(PID_RPM, value)) {
sprintf(buf, "%4d", value);
DisplayLargeNumber(buf, 16, 0);
}
- if (ReadSensor(PID_SPEED, value)) {
+ if (readSensor(PID_SPEED, value)) {
sprintf(buf, "%3d", value);
DisplayLargeNumber(buf, 32, 3);
}
@@ -153,6 +153,6 @@ void loop()
void setup()
{
- OBDUART.begin(OBD_SERIAL_BAUDRATE);
+ dash.begin();
}
diff --git a/samples/obdtest/obdtest.ino b/samples/obdtest/obdtest.ino
index 772ef40..b04ac64 100644
--- a/samples/obdtest/obdtest.ino
+++ b/samples/obdtest/obdtest.ino
@@ -52,11 +52,12 @@ void ShowGPSData()
char buf[32];
unsigned long fix_age;
+ lcd.setFont(FONT_SIZE_SMALL);
if (lcd.getLines() > 2) {
unsigned long date, time;
gps.get_datetime(&date, &time, &fix_age);
sprintf(buf, "TIME: %08ld", time);
- lcd.setCursor(0, 2);
+ lcd.setCursor(0, 6);
lcd.print(buf);
}
@@ -64,7 +65,7 @@ void ShowGPSData()
long lat, lon;
gps.get_position(&lat, &lon, &fix_age);
// display LAT/LON if screen is big enough
- lcd.setCursor(0, 3);
+ lcd.setCursor(0, 7);
if (((unsigned int)millis() / 1000) & 1)
sprintf(buf, "LAT: %d.%5ld ", (int)(lat / 100000), lat % 100000);
else
@@ -82,7 +83,7 @@ public:
unsigned long currentMillis;
unsigned char n;
char prompted;
- char buffer[OBD_RECV_BUF_SIZE];
+ char buffer[128];
for (unsigned char i = 0; i < INIT_CMD_COUNT; i++) {
lcd.clear();
@@ -98,14 +99,13 @@ public:
if (c == '>') {
buffer[n] = 0;
prompted++;
- } else if (n < OBD_RECV_BUF_SIZE - 1) {
+ } else if (n < sizeof(buffer) - 1) {
buffer[n++] = c;
if (c == '\n')
lcd.changeLine();
else if (c >= ' ') {
lcd.write(c);
- delay(5);
}
}
} else if (prompted) {
@@ -133,8 +133,8 @@ public:
sprintf(buffer, "PIDs [%02x-%02x]", i * 0x20 + 1, i * 0x20 + 0x20);
lcd.print(buffer);
byte pid = i * 0x20;
- Query(pid);
- data = GetResponse(pid, buffer);
+ sendQuery(pid);
+ data = getResponse(pid, buffer);
if (!data) break;
lcd.setCursor(0, 1);
lcd.print(data);
@@ -182,7 +182,7 @@ public:
lcd.print(buf);
dataMode = (byte)(pid >> 8);
- Query((byte)pid);
+ sendQuery((byte)pid);
}
void Recover()
{
@@ -217,24 +217,23 @@ public:
// check OBD response
buffer[0] = 0;
byte curpid = (byte)pid;
- char* data = GetResponse(curpid, buffer);
+ char* data = getResponse(curpid, buffer);
lcd.setCursor(6, 0);
if (!data) {
- lcd.print("Data Error");
+ lcd.setCursor(0, 2);
+ lcd.print("Error");
// try recover next time
Recover();
} else {
- if (!hasMPU6050) {
char *p = buffer;
while (*p && *p < ' ') p++;
for (char *q = p; *q; q++) {
if (*q < ' ') *q = ' ';
- }
- lcd.setCursor(0, 1);
- lcd.print(p);
}
- sprintf(buffer, "=%d", GetConvertedValue(curpid, data));
- lcd.setCursor(6, 0);
+ lcd.setCursor(0, 2);
+ lcd.print(p);
+ lcd.setCursor(7 * 9, 0);
+ sprintf(buffer, "%d", normalizeData(curpid, data));
lcd.print(buffer);
}
}
@@ -266,9 +265,9 @@ void testMPU6050()
// there is no filter enabled, and the values
// are not very stable.
- lcd.setCursor(0, 1);
error = MPU6050_read (MPU6050_ACCEL_XOUT_H, (uint8_t *) &accel_t_gyro, sizeof(accel_t_gyro));
if (error != 0) {
+ lcd.setCursor(0, 4);
lcd.print("MPU6050 N/A");
return;
}
@@ -300,7 +299,7 @@ void testMPU6050()
accel_t_gyro.value.y_accel / 128,
accel_t_gyro.value.z_accel / 128);
//Serial.println(buf);
- lcd.setCursor(0, 1);
+ lcd.setCursor(0, 4);
lcd.print(buf);
}
@@ -314,12 +313,12 @@ void ShowECUCap()
lcd.setFont(FONT_SIZE_SMALL);
for (; i < sizeof(pidlist) / sizeof(pidlist[0]) / 2; i++) {
lcd.setCursor(0, i);
- sprintf(buffer, "%s:%c", namelist[i], obd.IsValidPID(pidlist[i]) ? 'Y' : 'N');
+ sprintf(buffer, "%s:%c", namelist[i], obd.isValidPID(pidlist[i]) ? 'Y' : 'N');
lcd.print(buffer);
}
for (byte row = 0; i < sizeof(pidlist) / sizeof(pidlist[0]); i++, row++) {
lcd.setCursor(64, row);
- sprintf(buffer, "%s:%c", namelist[i], obd.IsValidPID(pidlist[i]) ? 'Y' : 'N');
+ sprintf(buffer, "%s:%c", namelist[i], obd.isValidPID(pidlist[i]) ? 'Y' : 'N');
lcd.print(buffer);
}
}
@@ -345,7 +344,7 @@ void setup()
do {
testMPU6050();
delay(100);
- } while (millis() - t <= 10000);
+ } while (millis() - t <= 1000);
}
delay(1000);
@@ -364,6 +363,7 @@ void setup()
delay(500);
} while(!obd.Init());
+ ShowECUCap();
delay(3000);
lcd.clear();
//query();