From 366c19cdba2bf7fb6de3ad1a8c6cafea99d97fd1 Mon Sep 17 00:00:00 2001 From: Stanley Huang Date: Mon, 24 Mar 2014 23:00:27 +0800 Subject: Update MEGA Logger Add switch for OBD-II UART and I2C adapter --- megalogger/config.h | 1 + megalogger/datalogger.h | 36 +----------------------------------- megalogger/megalogger.ino | 2 +- megalogger/megalogger.layout | 16 ++++++++-------- 4 files changed, 11 insertions(+), 44 deletions(-) (limited to 'megalogger') diff --git a/megalogger/config.h b/megalogger/config.h index ac06fd6..7b4c1f7 100644 --- a/megalogger/config.h +++ b/megalogger/config.h @@ -10,6 +10,7 @@ * Choose model of OBD-II Adapter **************************************/ #define OBD_MODEL OBD_MODEL_UART +#define OBD_PROTOCOL 0 /* 0 for auto */ /************************************** * Choose SD pin here diff --git a/megalogger/datalogger.h b/megalogger/datalogger.h index 1f3b301..4fdf805 100644 --- a/megalogger/datalogger.h +++ b/megalogger/datalogger.h @@ -93,7 +93,7 @@ typedef struct { #define FILE_NAME_FORMAT "/DAT%05d.CSV" #endif -#if ENABLE_DATA_OUT && !USE_OBD_BT +#if ENABLE_DATA_OUT #if defined(__AVR_ATmega2560__) || defined(__AVR_ATmega1280__) SoftwareSerial mySerial(A8, A9); /* for BLE Shield on MEGA*/ #elif defined(__AVR_ATmega644P__) @@ -111,12 +111,8 @@ public: void initSender() { #if ENABLE_DATA_OUT -#if USE_OBD_BT - btInit(9600); -#else mySerial.begin(9600); #endif -#endif #if ENABLE_DATA_LOG && LOG_FORMAT == FORMAT_CSV m_lastDataTime = 0; #endif @@ -140,26 +136,17 @@ public: info.logType = hdr.logType; info.logFlags = hdr.flags; info.checksum = getChecksum((char*)&info, sizeof(info)); -#if USE_OBD_BT - btSend((uint8_t*)&info, sizeof(info)); -#else mySerial.write((uint8_t*)&info, sizeof(info)); -#endif } void sendCommand(byte message, void* data = 0, byte bytes = 0) { LOG_DATA_COMMAND msg = {0, PID_MESSAGE, message}; if (data) memcpy(msg.data, data, bytes); msg.checksum = getChecksum((char*)&msg, sizeof(msg)); -#if USE_OBD_BT - btSend((uint8_t*)&msg, sizeof(msg)); -#else mySerial.write((uint8_t*)&msg, sizeof(msg)); -#endif } bool receiveCommand(LOG_DATA_COMMAND& msg) { -#if !USE_OBD_BT if (!mySerial.available()) return false; @@ -171,7 +158,6 @@ public: if (getChecksum((char*)&msg, sizeof(msg)) != msg.checksum) { return false; } -#endif return true; } #endif @@ -180,12 +166,8 @@ public: LOG_DATA_COMM ld = {dataTime, pid, 1, 0, value}; ld.checksum = getChecksum((char*)&ld, 12); #if ENABLE_DATA_OUT -#if USE_OBD_BT - btSend((uint8_t*)&ld, 12); -#else mySerial.write((uint8_t*)&ld, 12); #endif -#endif #if ENABLE_DATA_LOG #if LOG_FORMAT == FORMAT_BIN sdfile.write((uint8_t*)&ld, 12); @@ -206,12 +188,8 @@ public: LOG_DATA_COMM ld = {dataTime, pid, 1, 0, value}; ld.checksum = getChecksum((char*)&ld, 12); #if ENABLE_DATA_OUT -#if USE_OBD_BT - btSend((uint8_t*)&ld, 12); -#else mySerial.write((uint8_t*)&ld, 12); #endif -#endif #if ENABLE_DATA_LOG #if LOG_FORMAT == FORMAT_BIN sdfile.write((uint8_t*)&ld, 12); @@ -232,12 +210,8 @@ public: LOG_DATA_COMM ld = {dataTime, pid, 2, 0, {value1, value2}}; ld.checksum = getChecksum((char*)&ld, 16); #if ENABLE_DATA_OUT -#if USE_OBD_BT - btSend((uint8_t*)&ld, 16); -#else mySerial.write((uint8_t*)&ld, 16); #endif -#endif #if ENABLE_DATA_LOG #if LOG_FORMAT == FORMAT_BIN sdfile.write((uint8_t*)&ld, 16); @@ -260,12 +234,8 @@ public: LOG_DATA_COMM ld = {dataTime, pid, 2, 0, {value1, value2}}; ld.checksum = getChecksum((char*)&ld, 16); #if ENABLE_DATA_OUT -#if USE_OBD_BT - btSend((uint8_t*)&ld, 16); -#else mySerial.write((uint8_t*)&ld, 16); #endif -#endif #if ENABLE_DATA_LOG #if LOG_FORMAT == FORMAT_BIN sdfile.write((uint8_t*)&ld, 16); @@ -288,12 +258,8 @@ public: LOG_DATA_COMM ld = {dataTime, pid, 3, 0, {value1, value2, value3}}; ld.checksum = getChecksum((char*)&ld, 20); #if ENABLE_DATA_OUT -#if USE_OBD_BT - btSend((uint8_t*)&ld, 20); -#else mySerial.write((uint8_t*)&ld, 20); #endif -#endif #if ENABLE_DATA_LOG #if LOG_FORMAT == FORMAT_BIN sdfile.write((uint8_t*)&ld, 20); diff --git a/megalogger/megalogger.ino b/megalogger/megalogger.ino index 401e06e..da65d6d 100644 --- a/megalogger/megalogger.ino +++ b/megalogger/megalogger.ino @@ -103,7 +103,7 @@ public: do { showStates(); - } while (!init()); + } while (!init(OBD_PROTOCOL)); state |= STATE_OBD_READY; diff --git a/megalogger/megalogger.layout b/megalogger/megalogger.layout index e3b98df..0aceb52 100644 --- a/megalogger/megalogger.layout +++ b/megalogger/megalogger.layout @@ -1,24 +1,24 @@ - + - + - + - + - + - + - + - + -- cgit v1.2.3