summaryrefslogtreecommitdiff
path: root/megalogger
diff options
context:
space:
mode:
Diffstat (limited to 'megalogger')
-rw-r--r--megalogger/config.h10
-rw-r--r--megalogger/datalogger.h64
-rw-r--r--megalogger/megalogger.ino18
3 files changed, 72 insertions, 20 deletions
diff --git a/megalogger/config.h b/megalogger/config.h
index 6db6a56..50f96a6 100644
--- a/megalogger/config.h
+++ b/megalogger/config.h
@@ -28,9 +28,15 @@
/**************************************
* Data logging/streaming options
**************************************/
-#define ENABLE_DATA_OUT 0
+#define ENABLE_DATA_OUT 1
#define ENABLE_DATA_LOG 1
-#define USE_OBD_BT 1
+#define USE_OBD_BT 0
#define LOG_FORMAT FORMAT_CSV /* options: FORMAT_CSV, FORMAT_BIN */
+/**************************************
+* LCD module
+**************************************/
+LCD_ILI9325D lcd; /* for ILI9325 based TFT shield */
+//LCD_ILI9341 lcd; /* for ILI9341 based SPI TFT */
+
#endif
diff --git a/megalogger/datalogger.h b/megalogger/datalogger.h
index 281d50c..315e803 100644
--- a/megalogger/datalogger.h
+++ b/megalogger/datalogger.h
@@ -175,6 +175,32 @@ public:
return true;
}
#endif
+ void logData(uint16_t pid, int value)
+ {
+ 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);
+ dataSize += 12;
+#else
+ dataSize += sdfile.print(dataTime - m_lastDataTime);
+ dataSize += sdfile.write(',');
+ dataSize += sdfile.print(pid, HEX);
+ dataSize += sdfile.write(',');
+ dataSize += sdfile.print(value);
+ dataSize += sdfile.write('\n');
+ m_lastDataTime = dataTime;
+#endif
+#endif
+ }
void logData(uint16_t pid, float value)
{
LOG_DATA_COMM ld = {dataTime, pid, 1, 0, value};
@@ -195,7 +221,7 @@ public:
dataSize += sdfile.write(',');
dataSize += sdfile.print(pid, HEX);
dataSize += sdfile.write(',');
- dataSize += sdfile.print((int)value);
+ dataSize += sdfile.print(value);
dataSize += sdfile.write('\n');
m_lastDataTime = dataTime;
#endif
@@ -229,7 +255,35 @@ public:
#endif
#endif
}
- void logData(uint16_t pid, float value1, float value2, float value3)
+ void logData(uint16_t pid, uint32_t value1, uint32_t value2)
+ {
+ 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);
+ dataSize += 16;
+#else
+ dataSize += sdfile.print(dataTime - m_lastDataTime);
+ dataSize += sdfile.write(',');
+ dataSize += sdfile.print(pid, HEX);
+ dataSize += sdfile.write(',');
+ dataSize += sdfile.print(value1, 6);
+ dataSize += sdfile.write(' ');
+ dataSize += sdfile.print(value2, 6);
+ dataSize += sdfile.write('\n');
+ m_lastDataTime = dataTime;
+#endif
+#endif
+ }
+ void logData(uint16_t pid, int value1, int value2, int value3)
{
LOG_DATA_COMM ld = {dataTime, pid, 3, 0, {value1, value2, value3}};
ld.checksum = getChecksum((char*)&ld, 20);
@@ -249,11 +303,11 @@ public:
dataSize += sdfile.write(',');
dataSize += sdfile.print(pid, HEX);
dataSize += sdfile.write(',');
- dataSize += sdfile.print((int)value1);
+ dataSize += sdfile.print(value1);
dataSize += sdfile.write(' ');
- dataSize += sdfile.print((int)value2);
+ dataSize += sdfile.print(value2);
dataSize += sdfile.write(' ');
- dataSize += sdfile.print((int)value3);
+ dataSize += sdfile.print(value3);
dataSize += sdfile.write('\n');
m_lastDataTime = dataTime;
#endif
diff --git a/megalogger/megalogger.ino b/megalogger/megalogger.ino
index 3f477ef..43d1f5a 100644
--- a/megalogger/megalogger.ino
+++ b/megalogger/megalogger.ino
@@ -15,10 +15,10 @@
#include <SPI.h>
#include "config.h"
#include "images.h"
-#include "datalogger.h"
#if ENABLE_DATA_OUT
#include <SoftwareSerial.h>
#endif
+#include "datalogger.h"
#if !defined(__AVR_ATmega2560__) && !defined(__AVR_ATmega1280__) && !defined(__AVR_ATmega644P__) && !defined(__SAM3X8E__)
#error This sketch requires Arduino MEGA or DUE to work
@@ -53,9 +53,6 @@ TinyGPS gps;
#endif // GPSUART
#endif
-//LCD_ILI9325D lcd; /* for ILI9325 based TFT shield */
-LCD_ILI9341 lcd; /* for ILI9341 based SPI TFT */
-
static uint32_t lastFileSize = 0;
static uint32_t lastDataTime = 0;
static uint32_t lastGPSDataTime = 0;
@@ -335,7 +332,7 @@ private:
gps.get_datetime(&date, &time, 0);
logData(PID_GPS_TIME, time, date);
- uint32_t speed = gps.speed() * 1852 / 100;
+ int speed = gps.speed() * 1852 / 100 / 1000;
logData(PID_GPS_SPEED, speed);
// no need to log GPS data when vehicle has not been moving
@@ -418,17 +415,12 @@ private:
void logOBDData(byte pid)
{
char buffer[OBD_RECV_BUF_SIZE];
- int value;
uint32_t start = millis();
- sendQuery(pid);
-
- pid = 0;
- if (!getResponseParsed(pid, value)) {
- errors++;
+ // read OBD-II data
+ int value;
+ if (!read(pid, value)) {
return;
- } else {
- errors = 0;
}
dataTime = millis();