diff options
author | Stanley Huang <stanleyhuangyc@gmail.com> | 2013-10-06 08:00:08 +0800 |
---|---|---|
committer | Stanley Huang <stanleyhuangyc@gmail.com> | 2013-10-06 08:00:08 +0800 |
commit | 9ece6899db9a20e6cbfb0a197960b195b1a0d719 (patch) | |
tree | 181a056600d37bdc0794aac46cadad87e45b8e6a | |
parent | 1f3705b6834b385ccac844ceff1fda27fa2d0f1d (diff) | |
download | 2021-arduino-obd-9ece6899db9a20e6cbfb0a197960b195b1a0d719.tar.gz 2021-arduino-obd-9ece6899db9a20e6cbfb0a197960b195b1a0d719.tar.bz2 2021-arduino-obd-9ece6899db9a20e6cbfb0a197960b195b1a0d719.zip |
update MEGA Logger
-rw-r--r-- | megalogger/megalogger.cbp | 4 | ||||
-rw-r--r-- | megalogger/megalogger.ino | 43 |
2 files changed, 27 insertions, 20 deletions
diff --git a/megalogger/megalogger.cbp b/megalogger/megalogger.cbp index 6a46da9..6d01560 100644 --- a/megalogger/megalogger.cbp +++ b/megalogger/megalogger.cbp @@ -57,20 +57,20 @@ <Option type="1" /> <Option compiler="avrgcc" /> <Compiler> + <Add option="-O3" /> <Add option="-x c++" /> <Add option="-mmcu=$(MCU)" /> <Add option="-DF_CPU=16000000L" /> <Add option="-D__AVR_ATmega2560__" /> - <Add option="-O2" /> <Add directory="$(ARDUINO_DIR)/hardware/arduino/cores/arduino" /> <Add directory="$(ARDUINO_DIR)/libraries" /> <Add directory="$(ARDUINO_DIR)/hardware/arduino/variants/mega" /> </Compiler> <Linker> + <Add option="-s" /> <Add option="-mmcu=$(MCU)" /> <Add option='"$(PROJECT_DIR)${TARGET_OUTPUT_DIR}/lib_${BOARD_ID}_${MCU_CLOCK}.a"' /> <Add option='"$(PROJECT_DIR)${TARGET_OUTPUT_DIR}/core_${BOARD_ID}_${MCU_CLOCK}.a"' /> - <Add option="-s" /> </Linker> <ExtraCommands> <Add before='$(TARGET_COMPILER_DIR)ArduinoUploader "$(PROJECT_DIR)." $(BOARD_ID) - $(MCU_CLOCK) 0 "$(PROJECT_DIR)${TARGET_OUTPUT_DIR}/lib_${BOARD_ID}_${MCU_CLOCK}.a" "$(PROJECT_DIR)${TARGET_OUTPUT_DIR}/core_${BOARD_ID}_${MCU_CLOCK}.a"' /> diff --git a/megalogger/megalogger.ino b/megalogger/megalogger.ino index d0a7494..d09091a 100644 --- a/megalogger/megalogger.ino +++ b/megalogger/megalogger.ino @@ -16,6 +16,10 @@ #include "images.h" #include "datalogger.h" +#if !defined(__AVR_ATmega2560__) && !defined(__AVR_ATmega1280__) && !defined(__AVR_ATmega644P__) +#error This sketch requires Arduino MEGA to work +#endif + /************************************** * Choose SD pin here **************************************/ @@ -68,8 +72,6 @@ TinyGPS gps; #endif LCD_ILI9325D lcd; /* for 2.8" TFT shield */ -#define LCD_LINES 24 -#define CHAR_WIDTH 9 #define RGB16(r,g,b) (((uint16_t)(r >> 3) << 11) | ((uint16_t)(g >> 2) << 5) | (b >> 2)) #define RGB16_RED 0xF800 @@ -83,11 +85,11 @@ static uint32_t lastGPSDataTime = 0; static uint32_t lastACCDataTime = 0; static uint16_t lastRefreshTime = 0; static uint16_t lastSpeed = -1; -static int startDistance = 0; +static uint16_t startDistance = 0; static uint16_t fileIndex = 0; static uint32_t startTime = 0; -class COBDLogger : public COBD, public CDataLogger +class COBDLogger : public COBDI2C, public CDataLogger { public: COBDLogger():state(0) {} @@ -122,10 +124,6 @@ public: //lcd.setCursor(0, 14); //lcd.print("VIN: XXXXXXXX"); - showECUCap(); - - readSensor(PID_DISTANCE, startDistance); - // open file for logging if (!(state & STATE_SD_READY)) { if (checkSD()) { @@ -143,9 +141,13 @@ public: lcd.setCursor(0, 6); lcd.print("File ID:"); lcd.printInt(index); - delay(1000); #endif + showECUCap(); + delay(1000); + + readSensor(PID_DISTANCE, (int&)startDistance); + initScreen(); lastDataTime = millis(); @@ -293,9 +295,11 @@ private: { // callback while waiting OBD data if (getState() == OBD_CONNECTED) { +#ifdef GPSUART if (lastDataTime && GPSUART.available()) processGPS(); return; +#endif } // display while initializing @@ -389,10 +393,15 @@ private: #endif void processAccelerometer() { + dataTime = millis(); + + if (dataTime - lastACCDataTime < ACC_DATA_INTERVAL) { + return; + } + char buf[20]; accel_t_gyro_union data; MPU6050_readout(&data); - dataTime = millis(); lcd.setFont(FONT_SIZE_SMALL); @@ -420,6 +429,8 @@ private: logData(PID_ACC, data.value.x_accel, data.value.y_accel, data.value.z_accel); // log x/y/z of gyro meter logData(PID_GYRO, data.value.x_gyro, data.value.y_gyro, data.value.z_gyro); + + lastACCDataTime = dataTime; } void logOBDData(byte pid) { @@ -429,6 +440,10 @@ private: sendQuery(pid); + if (state & STATE_ACC_READY) { + processAccelerometer(); + } + pid = 0; if (!getResponseParsed(pid, value)) { errors++; @@ -456,14 +471,6 @@ private: } #endif - if (state & STATE_ACC_READY) { - uint32_t t = millis(); - if (t - lastACCDataTime > ACC_DATA_INTERVAL) { - processAccelerometer(); - lastACCDataTime = t; - } - } - // if OBD response is very fast, go on processing other data for a while #ifdef OBD_MIN_INTERVAL while (millis() - start < OBD_MIN_INTERVAL) { |