summaryrefslogtreecommitdiff
path: root/megalogger
diff options
context:
space:
mode:
authorStanley Huang <stanleyhuangyc@gmail.com>2013-10-03 13:38:13 +0800
committerStanley Huang <stanleyhuangyc@gmail.com>2013-10-03 13:38:13 +0800
commit96e4492ae7d1dcc7194acb4ac07a07efe34f7e45 (patch)
tree9a46dfef3de0e0f03afeff1b03684cd21fd97324 /megalogger
parent567a89f9c9289e1f3f018060e5f90547b1fa6c78 (diff)
download2021-arduino-obd-96e4492ae7d1dcc7194acb4ac07a07efe34f7e45.tar.gz
2021-arduino-obd-96e4492ae7d1dcc7194acb4ac07a07efe34f7e45.tar.bz2
2021-arduino-obd-96e4492ae7d1dcc7194acb4ac07a07efe34f7e45.zip
update MEGA Logger
Diffstat (limited to 'megalogger')
-rw-r--r--megalogger/megalogger.ino44
1 files changed, 8 insertions, 36 deletions
diff --git a/megalogger/megalogger.ino b/megalogger/megalogger.ino
index eb336eb..a24647f 100644
--- a/megalogger/megalogger.ino
+++ b/megalogger/megalogger.ino
@@ -85,10 +85,6 @@ static int startDistance = 0;
static uint16_t fileIndex = 0;
static uint32_t startTime = 0;
-// cached data to be displayed
-static byte lastPID = 0;
-static int lastData;
-
class COBDLogger : public COBD, public CDataLogger
{
public:
@@ -231,9 +227,6 @@ public:
state |= STATE_GPS_READY;
}
#endif
- if (state & STATE_ACC_READY) {
- processAccelerometer();
- }
}
bool checkSD()
{
@@ -293,8 +286,12 @@ private:
void dataIdleLoop()
{
if (getState() == OBD_CONNECTED) {
+ if (state & STATE_ACC_READY)
+ processAccelerometer();
+
if (lastDataTime && GPSUART.available())
processGPS();
+
return;
}
@@ -302,6 +299,7 @@ private:
char buf[10];
unsigned int t = (millis() - startTime) / 1000;
sprintf(buf, "%02u:%02u", t / 60, t % 60);
+ lcd.setFont(FONT_SIZE_SMALL);
lcd.setCursor(0, 28);
lcd.print(buf);
#ifdef GPSUART
@@ -426,42 +424,16 @@ private:
int value;
uint32_t start = millis();
- // send a query to OBD adapter for specified OBD-II pid
- sendQuery(pid);
- // wait for reponse
- bool hasData;
- do {
- dataIdleLoop();
- } while (!(hasData = available()) && millis() - start < OBD_TIMEOUT_SHORT);
- // no need to continue if no data available
- if (!hasData) {
- errors++;
+ if (!readSensor(pid, value))
return;
- }
-
- // display data while waiting for OBD response
- showSensorData(lastPID, lastData);
- // get response from OBD adapter
- pid = 0;
- char* data = getResponse(pid, buffer);
- if (!data) {
- // try recover next time
- write('\r');
- return;
- }
- // keep data timestamp of returned data as soon as possible
dataTime = millis();
-
- // convert raw data to normal value
- value = normalizeData(pid, data);
+ // display data
+ showSensorData(pid, value);
// log data to SD card
logData(0x100 | pid, value);
- lastPID = pid;
- lastData = value;
-
// flush SD data every 1KB
if (dataSize - lastFileSize >= 1024) {
flushFile();