summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStanley Huang <stanleyhuangyc@gmail.com>2013-06-10 13:21:54 +0800
committerStanley Huang <stanleyhuangyc@gmail.com>2013-06-10 13:21:54 +0800
commitf99f21926e515cf93e2af35eb82808f337998738 (patch)
treeba931f65405704517acc543a4e96fc521fe3212e
parent47c6ff979fea8051c02fb38fe99c0021880a4ed8 (diff)
download2021-arduino-obd-f99f21926e515cf93e2af35eb82808f337998738.tar.gz
2021-arduino-obd-f99f21926e515cf93e2af35eb82808f337998738.tar.bz2
2021-arduino-obd-f99f21926e515cf93e2af35eb82808f337998738.zip
update OBD logger
-rw-r--r--obdlogger/LCD4Bit_mod.cpp209
-rw-r--r--obdlogger/LCD4Bit_mod.h47
-rw-r--r--obdlogger/MPU6050.cpp196
-rw-r--r--obdlogger/MPU6050.h644
-rw-r--r--obdlogger/MultiLCD.cpp182
-rw-r--r--obdlogger/MultiLCD.h84
-rw-r--r--obdlogger/OBD.cpp286
-rw-r--r--obdlogger/OBD.h84
-rw-r--r--obdlogger/PCD8544.cpp313
-rw-r--r--obdlogger/PCD8544.h124
-rw-r--r--obdlogger/README.txt2
-rw-r--r--obdlogger/TinyGPS.cpp426
-rw-r--r--obdlogger/TinyGPS.h153
-rw-r--r--obdlogger/ZtLib.cpp601
-rw-r--r--obdlogger/ZtLib.h127
-rw-r--r--obdlogger/images.h5
-rw-r--r--obdlogger/obdlogger.cbp16
-rw-r--r--obdlogger/obdlogger.ino349
18 files changed, 191 insertions, 3657 deletions
diff --git a/obdlogger/LCD4Bit_mod.cpp b/obdlogger/LCD4Bit_mod.cpp
deleted file mode 100644
index c100c19..0000000
--- a/obdlogger/LCD4Bit_mod.cpp
+++ /dev/null
@@ -1,209 +0,0 @@
-/*
-LCD4Bit v0.1 16/Oct/2006 neillzero http://abstractplain.net
-
-What is this?
-An arduino library for comms with HD44780-compatible LCD, in 4-bit mode (saves pins)
-
-Sources:
-- The original "LiquidCrystal" 8-bit library and tutorial
- http://www.arduino.cc/en/uploads/Tutorial/LiquidCrystal.zip
- http://www.arduino.cc/en/Tutorial/LCDLibrary
-- DEM 16216 datasheet http://www.maplin.co.uk/Media/PDFs/N27AZ.pdf
-- Massimo's suggested 4-bit code (I took initialization from here) http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1144924220/8
-See also:
-- glasspusher's code (probably more correct): http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1160586800/0#0
-
-Tested only with a DEM 16216 (maplin "N27AZ" - http://www.maplin.co.uk/Search.aspx?criteria=N27AZ)
-If you use this successfully, consider feeding back to the arduino wiki with a note of which LCD it worked on.
-
-Usage:
-see the examples folder of this library distribution.
-
-*/
-
-#if defined(ARDUINO) && ARDUINO >= 100
-#include "Arduino.h"
-#else
-#include "WProgram.h"
-#endif
-
-#include "LCD4Bit_mod.h"
-
-//command bytes for LCD
-#define CMD_CLR 0x01
-#define CMD_RIGHT 0x1C
-#define CMD_LEFT 0x18
-#define CMD_HOME 0x02
-
-//pulse the Enable pin high (for a microsecond).
-//This clocks whatever command or data is in DB4~7 into the LCD controller.
-void LCD4Bit_mod::pulseEnablePin(){
- digitalWrite(Enable,LOW);
- delayMicroseconds(1);
- // send a pulse to enable
- digitalWrite(Enable,HIGH);
- delayMicroseconds(1);
- digitalWrite(Enable,LOW);
- delay(1); // pause 1 ms. TODO: what delay, if any, is necessary here?
-}
-
-//push a nibble of data through the the LCD's DB4~7 pins, clocking with the Enable pin.
-//We don't care what RS and RW are, here.
-void LCD4Bit_mod::pushNibble(byte value)
-{
- byte val_nibble= value & 0x0F; //clean the value. (unnecessary)
-
- for (byte i=DB[0]; i <= DB[3]; i++) {
- digitalWrite(i,val_nibble & 01);
- val_nibble >>= 1;
- }
- pulseEnablePin();
-}
-
-//push a byte of data through the LCD's DB4~7 pins, in two steps, clocking each with the enable pin.
-void LCD4Bit_mod::pushByte(byte value)
-{
- byte val_lower = value & 0x0F;
- byte val_upper = value >> 4;
- pushNibble(val_upper);
- pushNibble(val_lower);
-}
-
-void LCD4Bit_mod::commandWriteNibble(byte nibble)
-{
- digitalWrite(RS, LOW);
- if (USING_RW) { digitalWrite(RW, LOW); }
- pushNibble(nibble);
-}
-
-
-void LCD4Bit_mod::commandWrite(byte value)
-{
- digitalWrite(RS, LOW);
- if (USING_RW) { digitalWrite(RW, LOW); }
- pushByte(value);
- //TODO: perhaps better to add a delay after EVERY command, here. many need a delay, apparently.
-}
-
-
-
-
-//print the given character at the current cursor position. overwrites, doesn't insert.
-void LCD4Bit_mod::write(byte c)
-{
- //set the RS and RW pins to show we're writing data
- digitalWrite(RS, HIGH);
- if (USING_RW) { digitalWrite(RW, LOW); }
-
- //let pushByte worry about the intricacies of Enable, nibble order.
- pushByte(c);
-}
-
-
-//print the given string to the LCD at the current cursor position. overwrites, doesn't insert.
-//While I don't understand why this was named printIn (PRINT IN?) in the original LiquidCrystal library, I've preserved it here to maintain the interchangeability of the two libraries.
-void LCD4Bit_mod::print(const char* msg)
-{
- byte i; //fancy int. avoids compiler warning when comparing i with strlen()'s uint8_t
- byte l = strlen(msg);
- for (i=0; i < l; i++){
- if (msg[i] >= 20) write(msg[i]);
- }
-}
-
-
-//send the clear screen command to the LCD
-void LCD4Bit_mod::clear()
-{
- commandWrite(CMD_CLR);
- delay(1);
-}
-
-
-// initiatize lcd after a short pause
-//while there are hard-coded details here of lines, cursor and blink settings, you can override these original settings after calling .init()
-void LCD4Bit_mod::begin ()
-{
- pinMode(Enable,OUTPUT);
- pinMode(RS,OUTPUT);
- if (USING_RW) { pinMode(RW,OUTPUT); }
- pinMode(DB[0],OUTPUT);
- pinMode(DB[1],OUTPUT);
- pinMode(DB[2],OUTPUT);
- pinMode(DB[3],OUTPUT);
-
- delay(50);
-
- //The first 4 nibbles and timings are not in my DEM16217 SYH datasheet, but apparently are HD44780 standard...
- commandWriteNibble(0x03);
- delay(5);
- commandWriteNibble(0x03);
- delayMicroseconds(100);
- commandWriteNibble(0x03);
- delay(5);
-
- // needed by the LCDs controller
- //this being 2 sets up 4-bit mode.
- commandWriteNibble(0x02);
- commandWriteNibble(0x02);
- //todo: make configurable by the user of this library.
- //NFXX where
- //N = num lines (0=1 line or 1=2 lines).
- //F= format (number of dots (0=5x7 or 1=5x10)).
- //X=don't care
-
- byte num_lines_ptn = (num_lines - 1) << 3;
- byte dot_format_ptn = 0x00; //5x7 dots. 0x04 is 5x10
-
- commandWriteNibble(num_lines_ptn | dot_format_ptn);
- delayMicroseconds(60);
-
- //The rest of the init is not specific to 4-bit mode.
- //NOTE: we're writing full bytes now, not nibbles.
-
- // display control:
- // turn display on, cursor off, no blinking
- commandWrite(0x0C);
- delayMicroseconds(60);
-
- //clear display
- commandWrite(0x01);
- delay(3);
-
- // entry mode set: 06
- // increment automatically, display shift, entire shift off
- commandWrite(0x06);
-
- delay(1);//TODO: remove unnecessary delays
-}
-
-
-//non-core stuff --------------------------------------
-//move the cursor to the given absolute position. line numbers start at 1.
-//if this is not a 2-line LCD4Bit_mod instance, will always position on first line.
-void LCD4Bit_mod::setCursor(byte x, byte line)
-{
- //first, put cursor home
- commandWrite(CMD_HOME);
- //offset 40 chars in if second line requested
- x += line * 40;
-
- //advance the cursor to the right according to position. (second line starts at position 40).
- for (byte i=0; i<x; i++) {
- commandWrite(0x14);
- }
-}
-
-//scroll whole display to left
-void LCD4Bit_mod::leftScroll(byte num_chars, unsigned int delay_time)
-{
- for (byte i=0; i<num_chars; i++) {
- commandWrite(CMD_LEFT);
- delay(delay_time);
- }
-}
-
-//Improvements ------------------------------------------------
-//Remove the unnecessary delays (e.g. from the end of pulseEnablePin()).
-//Allow the user to pass the pins to be used by the LCD in the constructor, and store them as member variables of the class instance.
-//-------------------------------------------------------------
diff --git a/obdlogger/LCD4Bit_mod.h b/obdlogger/LCD4Bit_mod.h
deleted file mode 100644
index 7cd5115..0000000
--- a/obdlogger/LCD4Bit_mod.h
+++ /dev/null
@@ -1,47 +0,0 @@
-#ifndef LCD4Bit_mod_h
-#define LCD4Bit_mod_h
-
-#include <inttypes.h>
-
-class LCD4Bit_mod {
-public:
- LCD4Bit_mod(byte num_lines = 2):USING_RW(false),RS(8),RW(11),Enable(9)
- {
- DB[0] = 4;
- DB[1] = 5;
- DB[2] = 6;
- DB[3] = 7;
- this->num_lines = num_lines;
- }
- void commandWrite(byte value);
- void begin();
- void write(byte value);
- void print(const char* string);
- void clear();
- //non-core---------------
- void setCursor(byte x, byte line);
- void leftScroll(byte chars, unsigned int delay_time);
- //end of non-core--------
-
- //4bit only, therefore ideally private but may be needed by user
- void commandWriteNibble(byte nibble);
-private:
- void pulseEnablePin();
- void pushNibble(byte nibble);
- void pushByte(byte value);
- // --------- PINS -------------------------------------
- //is the RW pin of the LCD under our control? If we're only ever going to write to the LCD, we can use one less microcontroller pin, and just tie the LCD pin to the necessary signal, high or low.
- //this stops us sending signals to the RW pin if it isn't being used.
- bool USING_RW;
- //RS, RW and Enable can be set to whatever you like
- byte RS;
- byte RW;
- byte Enable;
- //DB should be an unseparated group of pins - because of lazy coding in pushNibble()
- byte DB[4]; //wire these to DB4~7 on LCD.
- //how many lines has the LCD? (don't change here - specify on calling constructor)
- int num_lines;
-
-};
-
-#endif
diff --git a/obdlogger/MPU6050.cpp b/obdlogger/MPU6050.cpp
deleted file mode 100644
index 3091236..0000000
--- a/obdlogger/MPU6050.cpp
+++ /dev/null
@@ -1,196 +0,0 @@
-// MPU-6050 Accelerometer + Gyro
-// -----------------------------
-//
-// By arduino.cc user "Krodal".
-// June 2012
-// Open Source / Public Domain
-//
-// Using Arduino 1.0.1
-// It will not work with an older version,
-// since Wire.endTransmission() uses a parameter
-// to hold or release the I2C bus.
-//
-// Documentation:
-// - The InvenSense documents:
-// - "MPU-6000 and MPU-6050 Product Specification",
-// PS-MPU-6000A.pdf
-// - "MPU-6000 and MPU-6050 Register Map and Descriptions",
-// RM-MPU-6000A.pdf or RS-MPU-6000A.pdf
-// - "MPU-6000/MPU-6050 9-Axis Evaluation Board User Guide"
-// AN-MPU-6000EVB.pdf
-//
-// The accuracy is 16-bits.
-//
-// Temperature sensor from -40 to +85 degrees Celsius
-// 340 per degrees, -512 at 35 degrees.
-//
-// At power-up, all registers are zero, except these two:
-// Register 0x6B (PWR_MGMT_2) = 0x40 (I read zero).
-// Register 0x75 (WHO_AM_I) = 0x68.
-//
-
-#include <Arduino.h>
-#include "MPU6050.h"
-
-// --------------------------------------------------------
-// MPU6050_read
-//
-// This is a common function to read multiple bytes
-// from an I2C device.
-//
-// It uses the boolean parameter for Wire.endTransMission()
-// to be able to hold or release the I2C-bus.
-// This is implemented in Arduino 1.0.1.
-//
-// Only this function is used to read.
-// There is no function for a single byte.
-//
-int MPU6050_read(int start, uint8_t *buffer, int size)
-{
- int i, n;
-
- Wire.beginTransmission(MPU6050_I2C_ADDRESS);
- n = Wire.write(start);
- if (n != 1)
- return (-10);
-
- n = Wire.endTransmission(false); // hold the I2C-bus
- if (n != 0)
- return (n);
-
- // Third parameter is true: relase I2C-bus after data is read.
- Wire.requestFrom(MPU6050_I2C_ADDRESS, size, true);
- i = 0;
- while(Wire.available() && i<size)
- {
- buffer[i++]=Wire.read();
- }
- if ( i != size)
- return (-11);
-
- return (0); // return : no error
-}
-
-
-// --------------------------------------------------------
-// MPU6050_write
-//
-// This is a common function to write multiple bytes to an I2C device.
-//
-// If only a single register is written,
-// use the function MPU_6050_write_reg().
-//
-// Parameters:
-// start : Start address, use a define for the register
-// pData : A pointer to the data to write.
-// size : The number of bytes to write.
-//
-// If only a single register is written, a pointer
-// to the data has to be used, and the size is
-// a single byte:
-// int data = 0; // the data to write
-// MPU6050_write (MPU6050_PWR_MGMT_1, &c, 1);
-//
-int MPU6050_write(int start, const uint8_t *pData, int size)
-{
- int n, error;
-
- Wire.beginTransmission(MPU6050_I2C_ADDRESS);
- n = Wire.write(start); // write the start address
- if (n != 1)
- return (-20);
-
- n = Wire.write(pData, size); // write data bytes
- if (n != size)
- return (-21);
-
- error = Wire.endTransmission(true); // release the I2C-bus
- if (error != 0)
- return (error);
-
- return (0); // return : no error
-}
-
-// --------------------------------------------------------
-// MPU6050_write_reg
-//
-// An extra function to write a single register.
-// It is just a wrapper around the MPU_6050_write()
-// function, and it is only a convenient function
-// to make it easier to write a single register.
-//
-int MPU6050_write_reg(int reg, uint8_t data)
-{
- int error;
-
- error = MPU6050_write(reg, &data, 1);
-
- return (error);
-}
-
-// --------------------------------------------------------
-// MPU6050_init
-//
-// Initialization
-//
-int MPU6050_init()
-{
- // default at power-up:
- // Gyro at 250 degrees second
- // Acceleration at 2g
- // Clock source at internal 8MHz
- // The device is in sleep mode.
- //
- uint8_t c;
- int error;
- error = MPU6050_read (MPU6050_WHO_AM_I, &c, 1);
- if (error) return error;
-
- // According to the datasheet, the 'sleep' bit
- // should read a '1'. But I read a '0'.
- // That bit has to be cleared, since the sensor
- // is in sleep mode at power-up. Even if the
- // bit reads '0'.
- error = MPU6050_read (MPU6050_PWR_MGMT_2, &c, 1);
- if (error) return error;
-
- // Clear the 'sleep' bit to start the sensor.
- MPU6050_write_reg (MPU6050_PWR_MGMT_1, 0);
- return 0;
-}
-
-// --------------------------------------------------------
-// MPU6050_readout
-//
-// Perform an complete read-out
-//
-
-int MPU6050_readout(accel_t_gyro_union* accel_t_gyro)
-{
- int error;
-
- // Read the raw values.
- // Read 14 bytes at once,
- // containing acceleration, temperature and gyro.
- // With the default settings of the MPU-6050,
- // there is no filter enabled, and the values
- // are not very stable.
- error = MPU6050_read (MPU6050_ACCEL_XOUT_H, (uint8_t *)accel_t_gyro, sizeof(accel_t_gyro_union));
- if (error) return error;
-
- // Swap all high and low bytes.
- // After this, the registers values are swapped,
- // so the structure name like x_accel_l does no
- // longer contain the lower byte.
- uint8_t swap;
- #define SWAP(x,y) swap = x; x = y; y = swap
-
- SWAP (accel_t_gyro->reg.x_accel_h, accel_t_gyro->reg.x_accel_l);
- SWAP (accel_t_gyro->reg.y_accel_h, accel_t_gyro->reg.y_accel_l);
- SWAP (accel_t_gyro->reg.z_accel_h, accel_t_gyro->reg.z_accel_l);
- SWAP (accel_t_gyro->reg.t_h, accel_t_gyro->reg.t_l);
- SWAP (accel_t_gyro->reg.x_gyro_h, accel_t_gyro->reg.x_gyro_l);
- SWAP (accel_t_gyro->reg.y_gyro_h, accel_t_gyro->reg.y_gyro_l);
- SWAP (accel_t_gyro->reg.z_gyro_h, accel_t_gyro->reg.z_gyro_l);
- return 0;
-}
diff --git a/obdlogger/MPU6050.h b/obdlogger/MPU6050.h
deleted file mode 100644
index 8f3b29b..0000000
--- a/obdlogger/MPU6050.h
+++ /dev/null
@@ -1,644 +0,0 @@
-#ifndef MPU6050_H_INCLUDED
-#define MPU6050_H_INCLUDED
-
-#include <Wire.h>
-
-// The temperature sensor is -40 to +85 degrees Celsius.
-// It is a signed integer.
-// According to the datasheet:
-// 340 per degrees Celsius, -512 at 35 degrees.
-// At 0 degrees: -512 - (340 * 35) = -12412
-#define MPU6050_GET_TEMPERATURE(t) (( (float)t + 12412.0) / 340.0)
-
-// The name of the sensor is "MPU-6050".
-// For program code, I omit the '-',
-// therefor I use the name "MPU6050....".
-
-
-// Register names according to the datasheet.
-// According to the InvenSense document
-// "MPU-6000 and MPU-6050 Register Map
-// and Descriptions Revision 3.2", there are no registers
-// at 0x02 ... 0x18, but according other information
-// the registers in that unknown area are for gain
-// and offsets.
-//
-//#define MPU6050_AUX_VDDIO 0x01 // R/W
-#define MPU6050_SMPLRT_DIV 0x19 // R/W
-#define MPU6050_CONFIG 0x1A // R/W
-#define MPU6050_GYRO_CONFIG 0x1B // R/W
-#define MPU6050_ACCEL_CONFIG 0x1C // R/W
-#define MPU6050_FF_THR 0x1D // R/W
-#define MPU6050_FF_DUR 0x1E // R/W
-#define MPU6050_MOT_THR 0x1F // R/W
-#define MPU6050_MOT_DUR 0x20 // R/W
-#define MPU6050_ZRMOT_THR 0x21 // R/W
-#define MPU6050_ZRMOT_DUR 0x22 // R/W
-//#define MPU6050_FIFO_EN 0x23 // R/W
-#define MPU6050_I2C_MST_CTRL 0x24 // R/W
-#define MPU6050_I2C_SLV0_ADDR 0x25 // R/W
-#define MPU6050_I2C_SLV0_REG 0x26 // R/W
-#define MPU6050_I2C_SLV0_CTRL 0x27 // R/W
-#define MPU6050_I2C_SLV1_ADDR 0x28 // R/W
-#define MPU6050_I2C_SLV1_REG 0x29 // R/W
-#define MPU6050_I2C_SLV1_CTRL 0x2A // R/W
-#define MPU6050_I2C_SLV2_ADDR 0x2B // R/W
-#define MPU6050_I2C_SLV2_REG 0x2C // R/W
-#define MPU6050_I2C_SLV2_CTRL 0x2D // R/W
-#define MPU6050_I2C_SLV3_ADDR 0x2E // R/W
-#define MPU6050_I2C_SLV3_REG 0x2F // R/W
-#define MPU6050_I2C_SLV3_CTRL 0x30 // R/W
-#define MPU6050_I2C_SLV4_ADDR 0x31 // R/W
-#define MPU6050_I2C_SLV4_REG 0x32 // R/W
-#define MPU6050_I2C_SLV4_DO 0x33 // R/W
-#define MPU6050_I2C_SLV4_CTRL 0x34 // R/W
-#define MPU6050_I2C_SLV4_DI 0x35 // R
-#define MPU6050_I2C_MST_STATUS 0x36 // R
-#define MPU6050_INT_PIN_CFG 0x37 // R/W
-#define MPU6050_INT_ENABLE 0x38 // R/W
-#define MPU6050_INT_STATUS 0x3A // R
-#define MPU6050_ACCEL_XOUT_H 0x3B // R
-#define MPU6050_ACCEL_XOUT_L 0x3C // R
-#define MPU6050_ACCEL_YOUT_H 0x3D // R
-#define MPU6050_ACCEL_YOUT_L 0x3E // R
-#define MPU6050_ACCEL_ZOUT_H 0x3F // R
-#define MPU6050_ACCEL_ZOUT_L 0x40 // R
-#define MPU6050_TEMP_OUT_H 0x41 // R
-#define MPU6050_TEMP_OUT_L 0x42 // R
-#define MPU6050_GYRO_XOUT_H 0x43 // R
-#define MPU6050_GYRO_XOUT_L 0x44 // R
-#define MPU6050_GYRO_YOUT_H 0x45 // R
-#define MPU6050_GYRO_YOUT_L 0x46 // R
-#define MPU6050_GYRO_ZOUT_H 0x47 // R
-#define MPU6050_GYRO_ZOUT_L 0x48 // R
-#define MPU6050_EXT_SENS_DATA_00 0x49 // R
-#define MPU6050_EXT_SENS_DATA_01 0x4A // R
-#define MPU6050_EXT_SENS_DATA_02 0x4B // R
-#define MPU6050_EXT_SENS_DATA_03 0x4C // R
-#define MPU6050_EXT_SENS_DATA_04 0x4D // R
-#define MPU6050_EXT_SENS_DATA_05 0x4E // R
-#define MPU6050_EXT_SENS_DATA_06 0x4F // R
-#define MPU6050_EXT_SENS_DATA_07 0x50 // R
-#define MPU6050_EXT_SENS_DATA_08 0x51 // R
-#define MPU6050_EXT_SENS_DATA_09 0x52 // R
-#define MPU6050_EXT_SENS_DATA_10 0x53 // R
-#define MPU6050_EXT_SENS_DATA_11 0x54 // R
-#define MPU6050_EXT_SENS_DATA_12 0x55 // R
-#define MPU6050_EXT_SENS_DATA_13 0x56 // R
-#define MPU6050_EXT_SENS_DATA_14 0x57 // R
-#define MPU6050_EXT_SENS_DATA_15 0x58 // R
-#define MPU6050_EXT_SENS_DATA_16 0x59 // R
-#define MPU6050_EXT_SENS_DATA_17 0x5A // R
-#define MPU6050_EXT_SENS_DATA_18 0x5B // R
-#define MPU6050_EXT_SENS_DATA_19 0x5C // R
-#define MPU6050_EXT_SENS_DATA_20 0x5D // R
-#define MPU6050_EXT_SENS_DATA_21 0x5E // R
-#define MPU6050_EXT_SENS_DATA_22 0x5F // R
-#define MPU6050_EXT_SENS_DATA_23 0x60 // R
-#define MPU6050_MOT_DETECT_STATUS 0x61 // R
-#define MPU6050_I2C_SLV0_DO 0x63 // R/W
-#define MPU6050_I2C_SLV1_DO 0x64 // R/W
-#define MPU6050_I2C_SLV2_DO 0x65 // R/W
-#define MPU6050_I2C_SLV3_DO 0x66 // R/W
-#define MPU6050_I2C_MST_DELAY_CTRL 0x67 // R/W
-#define MPU6050_SIGNAL_PATH_RESET 0x68 // R/W
-#define MPU6050_MOT_DETECT_CTRL 0x69 // R/W
-#define MPU6050_USER_CTRL 0x6A // R/W
-#define MPU6050_PWR_MGMT_1 0x6B // R/W
-#define MPU6050_PWR_MGMT_2 0x6C // R/W
-#define MPU6050_FIFO_COUNTH 0x72 // R/W
-#define MPU6050_FIFO_COUNTL 0x73 // R/W
-#define MPU6050_FIFO_R_W 0x74 // R/W
-#define MPU6050_WHO_AM_I 0x75 // R
-
-
-// Defines for the bits, to be able to change
-// between bit number and binary definition.
-// By using the bit number, programming the sensor
-// is like programming the AVR microcontroller.
-// But instead of using "(1<<X)", or "_BV(X)",
-// the Arduino "bit(X)" is used.
-#define MPU6050_D0 0
-#define MPU6050_D1 1
-#define MPU6050_D2 2
-#define MPU6050_D3 3
-#define MPU6050_D4 4
-#define MPU6050_D5 5
-#define MPU6050_D6 6
-#define MPU6050_D7 7
-
-// AUX_VDDIO Register
-#define MPU6050_AUX_VDDIO MPU6050_D7 // I2C high: 1=VDD, 0=VLOGIC
-
-// CONFIG Register
-// DLPF is Digital Low Pass Filter for both gyro and accelerometers.
-// These are the names for the bits.
-// Use these only with the bit() macro.
-#define MPU6050_DLPF_CFG0 MPU6050_D0
-#define MPU6050_DLPF_CFG1 MPU6050_D1
-#define MPU6050_DLPF_CFG2 MPU6050_D2
-#define MPU6050_EXT_SYNC_SET0 MPU6050_D3
-#define MPU6050_EXT_SYNC_SET1 MPU6050_D4
-#define MPU6050_EXT_SYNC_SET2 MPU6050_D5
-
-// Combined definitions for the EXT_SYNC_SET values
-#define MPU6050_EXT_SYNC_SET_0 (0)
-#define MPU6050_EXT_SYNC_SET_1 (bit(MPU6050_EXT_SYNC_SET0))
-#define MPU6050_EXT_SYNC_SET_2 (bit(MPU6050_EXT_SYNC_SET1))
-#define MPU6050_EXT_SYNC_SET_3 (bit(MPU6050_EXT_SYNC_SET1)|bit(MPU6050_EXT_SYNC_SET0))
-#define MPU6050_EXT_SYNC_SET_4 (bit(MPU6050_EXT_SYNC_SET2))
-#define MPU6050_EXT_SYNC_SET_5 (bit(MPU6050_EXT_SYNC_SET2)|bit(MPU6050_EXT_SYNC_SET0))
-#define MPU6050_EXT_SYNC_SET_6 (bit(MPU6050_EXT_SYNC_SET2)|bit(MPU6050_EXT_SYNC_SET1))
-#define MPU6050_EXT_SYNC_SET_7 (bit(MPU6050_EXT_SYNC_SET2)|bit(MPU6050_EXT_SYNC_SET1)|bit(MPU6050_EXT_SYNC_SET0))
-
-// Alternative names for the combined definitions.
-#define MPU6050_EXT_SYNC_DISABLED MPU6050_EXT_SYNC_SET_0
-#define MPU6050_EXT_SYNC_TEMP_OUT_L MPU6050_EXT_SYNC_SET_1
-#define MPU6050_EXT_SYNC_GYRO_XOUT_L MPU6050_EXT_SYNC_SET_2
-#define MPU6050_EXT_SYNC_GYRO_YOUT_L MPU6050_EXT_SYNC_SET_3
-#define MPU6050_EXT_SYNC_GYRO_ZOUT_L MPU6050_EXT_SYNC_SET_4
-#define MPU6050_EXT_SYNC_ACCEL_XOUT_L MPU6050_EXT_SYNC_SET_5
-#define MPU6050_EXT_SYNC_ACCEL_YOUT_L MPU6050_EXT_SYNC_SET_6
-#define MPU6050_EXT_SYNC_ACCEL_ZOUT_L MPU6050_EXT_SYNC_SET_7
-
-// Combined definitions for the DLPF_CFG values
-#define MPU6050_DLPF_CFG_0 (0)
-#define MPU6050_DLPF_CFG_1 (bit(MPU6050_DLPF_CFG0))
-#define MPU6050_DLPF_CFG_2 (bit(MPU6050_DLPF_CFG1))
-#define MPU6050_DLPF_CFG_3 (bit(MPU6050_DLPF_CFG1)|bit(MPU6050_DLPF_CFG0))
-#define MPU6050_DLPF_CFG_4 (bit(MPU6050_DLPF_CFG2))
-#define MPU6050_DLPF_CFG_5 (bit(MPU6050_DLPF_CFG2)|bit(MPU6050_DLPF_CFG0))
-#define MPU6050_DLPF_CFG_6 (bit(MPU6050_DLPF_CFG2)|bit(MPU6050_DLPF_CFG1))
-#define MPU6050_DLPF_CFG_7 (bit(MPU6050_DLPF_CFG2)|bit(MPU6050_DLPF_CFG1)|bit(MPU6050_DLPF_CFG0))
-
-// Alternative names for the combined definitions
-// This name uses the bandwidth (Hz) for the accelometer,
-// for the gyro the bandwidth is almost the same.
-#define MPU6050_DLPF_260HZ MPU6050_DLPF_CFG_0
-#define MPU6050_DLPF_184HZ MPU6050_DLPF_CFG_1
-#define MPU6050_DLPF_94HZ MPU6050_DLPF_CFG_2
-#define MPU6050_DLPF_44HZ MPU6050_DLPF_CFG_3
-#define MPU6050_DLPF_21HZ MPU6050_DLPF_CFG_4
-#define MPU6050_DLPF_10HZ MPU6050_DLPF_CFG_5
-#define MPU6050_DLPF_5HZ MPU6050_DLPF_CFG_6
-#define MPU6050_DLPF_RESERVED MPU6050_DLPF_CFG_7
-
-// GYRO_CONFIG Register
-// The XG_ST, YG_ST, ZG_ST are bits for selftest.
-// The FS_SEL sets the range for the gyro.
-// These are the names for the bits.
-// Use these only with the bit() macro.
-#define MPU6050_FS_SEL0 MPU6050_D3
-#define MPU6050_FS_SEL1 MPU6050_D4
-#define MPU6050_ZG_ST MPU6050_D5
-#define MPU6050_YG_ST MPU6050_D6
-#define MPU6050_XG_ST MPU6050_D7
-
-// Combined definitions for the FS_SEL values
-#define MPU6050_FS_SEL_0 (0)
-#define MPU6050_FS_SEL_1 (bit(MPU6050_FS_SEL0))
-#define MPU6050_FS_SEL_2 (bit(MPU6050_FS_SEL1))
-#define MPU6050_FS_SEL_3 (bit(MPU6050_FS_SEL1)|bit(MPU6050_FS_SEL0))
-
-// Alternative names for the combined definitions
-// The name uses the range in degrees per second.
-#define MPU6050_FS_SEL_250 MPU6050_FS_SEL_0
-#define MPU6050_FS_SEL_500 MPU6050_FS_SEL_1
-#define MPU6050_FS_SEL_1000 MPU6050_FS_SEL_2
-#define MPU6050_FS_SEL_2000 MPU6050_FS_SEL_3
-
-// ACCEL_CONFIG Register
-// The XA_ST, YA_ST, ZA_ST are bits for selftest.
-// The AFS_SEL sets the range for the accelerometer.
-// These are the names for the bits.
-// Use these only with the bit() macro.
-#define MPU6050_ACCEL_HPF0 MPU6050_D0
-#define MPU6050_ACCEL_HPF1 MPU6050_D1
-#define MPU6050_ACCEL_HPF2 MPU6050_D2
-#define MPU6050_AFS_SEL0 MPU6050_D3
-#define MPU6050_AFS_SEL1 MPU6050_D4
-#define MPU6050_ZA_ST MPU6050_D5
-#define MPU6050_YA_ST MPU6050_D6
-#define MPU6050_XA_ST MPU6050_D7
-
-// Combined definitions for the ACCEL_HPF values
-#define MPU6050_ACCEL_HPF_0 (0)
-#define MPU6050_ACCEL_HPF_1 (bit(MPU6050_ACCEL_HPF0))
-#define MPU6050_ACCEL_HPF_2 (bit(MPU6050_ACCEL_HPF1))
-#define MPU6050_ACCEL_HPF_3 (bit(MPU6050_ACCEL_HPF1)|bit(MPU6050_ACCEL_HPF0))
-#define MPU6050_ACCEL_HPF_4 (bit(MPU6050_ACCEL_HPF2))
-#define MPU6050_ACCEL_HPF_7 (bit(MPU6050_ACCEL_HPF2)|bit(MPU6050_ACCEL_HPF1)|bit(MPU6050_ACCEL_HPF0))
-
-// Alternative names for the combined definitions
-// The name uses the Cut-off frequency.
-#define MPU6050_ACCEL_HPF_RESET MPU6050_ACCEL_HPF_0
-#define MPU6050_ACCEL_HPF_5HZ MPU6050_ACCEL_HPF_1
-#define MPU6050_ACCEL_HPF_2_5HZ MPU6050_ACCEL_HPF_2
-#define MPU6050_ACCEL_HPF_1_25HZ MPU6050_ACCEL_HPF_3
-#define MPU6050_ACCEL_HPF_0_63HZ MPU6050_ACCEL_HPF_4
-#define MPU6050_ACCEL_HPF_HOLD MPU6050_ACCEL_HPF_7
-
-// Combined definitions for the AFS_SEL values
-#define MPU6050_AFS_SEL_0 (0)
-#define MPU6050_AFS_SEL_1 (bit(MPU6050_AFS_SEL0))
-#define MPU6050_AFS_SEL_2 (bit(MPU6050_AFS_SEL1))
-#define MPU6050_AFS_SEL_3 (bit(MPU6050_AFS_SEL1)|bit(MPU6050_AFS_SEL0))
-
-// Alternative names for the combined definitions
-// The name uses the full scale range for the accelerometer.
-#define MPU6050_AFS_SEL_2G MPU6050_AFS_SEL_0
-#define MPU6050_AFS_SEL_4G MPU6050_AFS_SEL_1
-#define MPU6050_AFS_SEL_8G MPU6050_AFS_SEL_2
-#define MPU6050_AFS_SEL_16G MPU6050_AFS_SEL_3
-
-// FIFO_EN Register
-// These are the names for the bits.
-// Use these only with the bit() macro.
-#define MPU6050_SLV0_FIFO_EN MPU6050_D0
-#define MPU6050_SLV1_FIFO_EN MPU6050_D1
-#define MPU6050_SLV2_FIFO_EN MPU6050_D2
-#define MPU6050_ACCEL_FIFO_EN MPU6050_D3
-#define MPU6050_ZG_FIFO_EN MPU6050_D4
-#define MPU6050_YG_FIFO_EN MPU6050_D5
-#define MPU6050_XG_FIFO_EN MPU6050_D6
-#define MPU6050_TEMP_FIFO_EN MPU6050_D7
-
-// I2C_MST_CTRL Register
-// These are the names for the bits.
-// Use these only with the bit() macro.
-#define MPU6050_I2C_MST_CLK0 MPU6050_D0
-#define MPU6050_I2C_MST_CLK1 MPU6050_D1
-#define MPU6050_I2C_MST_CLK2 MPU6050_D2
-#define MPU6050_I2C_MST_CLK3 MPU6050_D3
-#define MPU6050_I2C_MST_P_NSR MPU6050_D4
-#define MPU6050_SLV_3_FIFO_EN MPU6050_D5
-#define MPU6050_WAIT_FOR_ES MPU6050_D6
-#define MPU6050_MULT_MST_EN MPU6050_D7
-
-// Combined definitions for the I2C_MST_CLK
-#define MPU6050_I2C_MST_CLK_0 (0)
-#define MPU6050_I2C_MST_CLK_1 (bit(MPU6050_I2C_MST_CLK0))
-#define MPU6050_I2C_MST_CLK_2 (bit(MPU6050_I2C_MST_CLK1))
-#define MPU6050_I2C_MST_CLK_3 (bit(MPU6050_I2C_MST_CLK1)|bit(MPU6050_I2C_MST_CLK0))
-#define MPU6050_I2C_MST_CLK_4 (bit(MPU6050_I2C_MST_CLK2))
-#define MPU6050_I2C_MST_CLK_5 (bit(MPU6050_I2C_MST_CLK2)|bit(MPU6050_I2C_MST_CLK0))
-#define MPU6050_I2C_MST_CLK_6 (bit(MPU6050_I2C_MST_CLK2)|bit(MPU6050_I2C_MST_CLK1))
-#define MPU6050_I2C_MST_CLK_7 (bit(MPU6050_I2C_MST_CLK2)|bit(MPU6050_I2C_MST_CLK1)|bit(MPU6050_I2C_MST_CLK0))
-#define MPU6050_I2C_MST_CLK_8 (bit(MPU6050_I2C_MST_CLK3))
-#define MPU6050_I2C_MST_CLK_9 (bit(MPU6050_I2C_MST_CLK3)|bit(MPU6050_I2C_MST_CLK0))
-#define MPU6050_I2C_MST_CLK_10 (bit(MPU6050_I2C_MST_CLK3)|bit(MPU6050_I2C_MST_CLK1))
-#define MPU6050_I2C_MST_CLK_11 (bit(MPU6050_I2C_MST_CLK3)|bit(MPU6050_I2C_MST_CLK1)|bit(MPU6050_I2C_MST_CLK0))
-#define MPU6050_I2C_MST_CLK_12 (bit(MPU6050_I2C_MST_CLK3)|bit(MPU6050_I2C_MST_CLK2))
-#define MPU6050_I2C_MST_CLK_13 (bit(MPU6050_I2C_MST_CLK3)|bit(MPU6050_I2C_MST_CLK2)|bit(MPU6050_I2C_MST_CLK0))
-#define MPU6050_I2C_MST_CLK_14 (bit(MPU6050_I2C_MST_CLK3)|bit(MPU6050_I2C_MST_CLK2)|bit(MPU6050_I2C_MST_CLK1))
-#define MPU6050_I2C_MST_CLK_15 (bit(MPU6050_I2C_MST_CLK3)|bit(MPU6050_I2C_MST_CLK2)|bit(MPU6050_I2C_MST_CLK1)|bit(MPU6050_I2C_MST_CLK0))
-
-// Alternative names for the combined definitions
-// The names uses I2C Master Clock Speed in kHz.
-#define MPU6050_I2C_MST_CLK_348KHZ MPU6050_I2C_MST_CLK_0
-#define MPU6050_I2C_MST_CLK_333KHZ MPU6050_I2C_MST_CLK_1
-#define MPU6050_I2C_MST_CLK_320KHZ MPU6050_I2C_MST_CLK_2
-#define MPU6050_I2C_MST_CLK_308KHZ MPU6050_I2C_MST_CLK_3
-#define MPU6050_I2C_MST_CLK_296KHZ MPU6050_I2C_MST_CLK_4
-#define MPU6050_I2C_MST_CLK_286KHZ MPU6050_I2C_MST_CLK_5
-#define MPU6050_I2C_MST_CLK_276KHZ MPU6050_I2C_MST_CLK_6
-#define MPU6050_I2C_MST_CLK_267KHZ MPU6050_I2C_MST_CLK_7
-#define MPU6050_I2C_MST_CLK_258KHZ MPU6050_I2C_MST_CLK_8
-#define MPU6050_I2C_MST_CLK_500KHZ MPU6050_I2C_MST_CLK_9
-#define MPU6050_I2C_MST_CLK_471KHZ MPU6050_I2C_MST_CLK_10
-#define MPU6050_I2C_MST_CLK_444KHZ MPU6050_I2C_MST_CLK_11
-#define MPU6050_I2C_MST_CLK_421KHZ MPU6050_I2C_MST_CLK_12
-#define MPU6050_I2C_MST_CLK_400KHZ MPU6050_I2C_MST_CLK_13
-#define MPU6050_I2C_MST_CLK_381KHZ MPU6050_I2C_MST_CLK_14
-#define MPU6050_I2C_MST_CLK_364KHZ MPU6050_I2C_MST_CLK_15
-
-// I2C_SLV0_ADDR Register
-// These are the names for the bits.
-// Use these only with the bit() macro.
-#define MPU6050_I2C_SLV0_RW MPU6050_D7
-
-// I2C_SLV0_CTRL Register
-// These are the names for the bits.
-// Use these only with the bit() macro.
-#define MPU6050_I2C_SLV0_LEN0 MPU6050_D0
-#define MPU6050_I2C_SLV0_LEN1 MPU6050_D1
-#define MPU6050_I2C_SLV0_LEN2 MPU6050_D2
-#define MPU6050_I2C_SLV0_LEN3 MPU6050_D3
-#define MPU6050_I2C_SLV0_GRP MPU6050_D4
-#define MPU6050_I2C_SLV0_REG_DIS MPU6050_D5
-#define MPU6050_I2C_SLV0_BYTE_SW MPU6050_D6
-#define MPU6050_I2C_SLV0_EN MPU6050_D7
-
-// A mask for the length
-#define MPU6050_I2C_SLV0_LEN_MASK 0x0F
-
-// I2C_SLV1_ADDR Register
-// These are the names for the bits.
-// Use these only with the bit() macro.
-#define MPU6050_I2C_SLV1_RW MPU6050_D7
-
-// I2C_SLV1_CTRL Register
-// These are the names for the bits.
-// Use these only with the bit() macro.
-#define MPU6050_I2C_SLV1_LEN0 MPU6050_D0
-#define MPU6050_I2C_SLV1_LEN1 MPU6050_D1
-#define MPU6050_I2C_SLV1_LEN2 MPU6050_D2
-#define MPU6050_I2C_SLV1_LEN3 MPU6050_D3
-#define MPU6050_I2C_SLV1_GRP MPU6050_D4
-#define MPU6050_I2C_SLV1_REG_DIS MPU6050_D5
-#define MPU6050_I2C_SLV1_BYTE_SW MPU6050_D6
-#define MPU6050_I2C_SLV1_EN MPU6050_D7
-
-// A mask for the length
-#define MPU6050_I2C_SLV1_LEN_MASK 0x0F
-
-// I2C_SLV2_ADDR Register
-// These are the names for the bits.
-// Use these only with the bit() macro.
-#define MPU6050_I2C_SLV2_RW MPU6050_D7
-
-// I2C_SLV2_CTRL Register
-// These are the names for the bits.
-// Use these only with the bit() macro.
-#define MPU6050_I2C_SLV2_LEN0 MPU6050_D0
-#define MPU6050_I2C_SLV2_LEN1 MPU6050_D1
-#define MPU6050_I2C_SLV2_LEN2 MPU6050_D2
-#define MPU6050_I2C_SLV2_LEN3 MPU6050_D3
-#define MPU6050_I2C_SLV2_GRP MPU6050_D4
-#define MPU6050_I2C_SLV2_REG_DIS MPU6050_D5
-#define MPU6050_I2C_SLV2_BYTE_SW MPU6050_D6
-#define MPU6050_I2C_SLV2_EN MPU6050_D7
-
-// A mask for the length
-#define MPU6050_I2C_SLV2_LEN_MASK 0x0F
-
-// I2C_SLV3_ADDR Register
-// These are the names for the bits.
-// Use these only with the bit() macro.
-#define MPU6050_I2C_SLV3_RW MPU6050_D7
-
-// I2C_SLV3_CTRL Register
-// These are the names for the bits.
-// Use these only with the bit() macro.
-#define MPU6050_I2C_SLV3_LEN0 MPU6050_D0
-#define MPU6050_I2C_SLV3_LEN1 MPU6050_D1
-#define MPU6050_I2C_SLV3_LEN2 MPU6050_D2
-#define MPU6050_I2C_SLV3_LEN3 MPU6050_D3
-#define MPU6050_I2C_SLV3_GRP MPU6050_D4
-#define MPU6050_I2C_SLV3_REG_DIS MPU6050_D5
-#define MPU6050_I2C_SLV3_BYTE_SW MPU6050_D6
-#define MPU6050_I2C_SLV3_EN MPU6050_D7
-
-// A mask for the length
-#define MPU6050_I2C_SLV3_LEN_MASK 0x0F
-
-// I2C_SLV4_ADDR Register
-// These are the names for the bits.
-// Use these only with the bit() macro.
-#define MPU6050_I2C_SLV4_RW MPU6050_D7
-
-// I2C_SLV4_CTRL Register
-// These are the names for the bits.
-// Use these only with the bit() macro.
-#define MPU6050_I2C_MST_DLY0 MPU6050_D0
-#define MPU6050_I2C_MST_DLY1 MPU6050_D1
-#define MPU6050_I2C_MST_DLY2 MPU6050_D2
-#define MPU6050_I2C_MST_DLY3 MPU6050_D3
-#define MPU6050_I2C_MST_DLY4 MPU6050_D4
-#define MPU6050_I2C_SLV4_REG_DIS MPU6050_D5
-#define MPU6050_I2C_SLV4_INT_EN MPU6050_D6
-#define MPU6050_I2C_SLV4_EN MPU6050_D7
-
-// A mask for the delay
-#define MPU6050_I2C_MST_DLY_MASK 0x1F
-
-// I2C_MST_STATUS Register
-// These are the names for the bits.
-// Use these only with the bit() macro.
-#define MPU6050_I2C_SLV0_NACK MPU6050_D0
-#define MPU6050_I2C_SLV1_NACK MPU6050_D1
-#define MPU6050_I2C_SLV2_NACK MPU6050_D2
-#define MPU6050_I2C_SLV3_NACK MPU6050_D3
-#define MPU6050_I2C_SLV4_NACK MPU6050_D4
-#define MPU6050_I2C_LOST_ARB MPU6050_D5
-#define MPU6050_I2C_SLV4_DONE MPU6050_D6
-#define MPU6050_PASS_THROUGH MPU6050_D7
-
-// I2C_PIN_CFG Register
-// These are the names for the bits.
-// Use these only with the bit() macro.
-#define MPU6050_CLKOUT_EN MPU6050_D0
-#define MPU6050_I2C_BYPASS_EN MPU6050_D1
-#define MPU6050_FSYNC_INT_EN MPU6050_D2
-#define MPU6050_FSYNC_INT_LEVEL MPU6050_D3
-#define MPU6050_INT_RD_CLEAR MPU6050_D4
-#define MPU6050_LATCH_INT_EN MPU6050_D5
-#define MPU6050_INT_OPEN MPU6050_D6
-#define MPU6050_INT_LEVEL MPU6050_D7
-
-// INT_ENABLE Register
-// These are the names for the bits.
-// Use these only with the bit() macro.
-#define MPU6050_DATA_RDY_EN MPU6050_D0
-#define MPU6050_I2C_MST_INT_EN MPU6050_D3
-#define MPU6050_FIFO_OFLOW_EN MPU6050_D4
-#define MPU6050_ZMOT_EN MPU6050_D5
-#define MPU6050_MOT_EN MPU6050_D6
-#define MPU6050_FF_EN MPU6050_D7
-
-// INT_STATUS Register
-// These are the names for the bits.
-// Use these only with the bit() macro.
-#define MPU6050_DATA_RDY_INT MPU6050_D0
-#define MPU6050_I2C_MST_INT MPU6050_D3
-#define MPU6050_FIFO_OFLOW_INT MPU6050_D4
-#define MPU6050_ZMOT_INT MPU6050_D5
-#define MPU6050_MOT_INT MPU6050_D6
-#define MPU6050_FF_INT MPU6050_D7
-
-// MOT_DETECT_STATUS Register
-// These are the names for the bits.
-// Use these only with the bit() macro.
-#define MPU6050_MOT_ZRMOT MPU6050_D0
-#define MPU6050_MOT_ZPOS MPU6050_D2
-#define MPU6050_MOT_ZNEG MPU6050_D3
-#define MPU6050_MOT_YPOS MPU6050_D4
-#define MPU6050_MOT_YNEG MPU6050_D5
-#define MPU6050_MOT_XPOS MPU6050_D6
-#define MPU6050_MOT_XNEG MPU6050_D7
-
-// IC2_MST_DELAY_CTRL Register
-// These are the names for the bits.
-// Use these only with the bit() macro.
-#define MPU6050_I2C_SLV0_DLY_EN MPU6050_D0
-#define MPU6050_I2C_SLV1_DLY_EN MPU6050_D1
-#define MPU6050_I2C_SLV2_DLY_EN MPU6050_D2
-#define MPU6050_I2C_SLV3_DLY_EN MPU6050_D3
-#define MPU6050_I2C_SLV4_DLY_EN MPU6050_D4
-#define MPU6050_DELAY_ES_SHADOW MPU6050_D7
-
-// SIGNAL_PATH_RESET Register
-// These are the names for the bits.
-// Use these only with the bit() macro.
-#define MPU6050_TEMP_RESET MPU6050_D0
-#define MPU6050_ACCEL_RESET MPU6050_D1
-#define MPU6050_GYRO_RESET MPU6050_D2
-
-// MOT_DETECT_CTRL Register
-// These are the names for the bits.
-// Use these only with the bit() macro.
-#define MPU6050_MOT_COUNT0 MPU6050_D0
-#define MPU6050_MOT_COUNT1 MPU6050_D1
-#define MPU6050_FF_COUNT0 MPU6050_D2
-#define MPU6050_FF_COUNT1 MPU6050_D3
-#define MPU6050_ACCEL_ON_DELAY0 MPU6050_D4
-#define MPU6050_ACCEL_ON_DELAY1 MPU6050_D5
-
-// Combined definitions for the MOT_COUNT
-#define MPU6050_MOT_COUNT_0 (0)
-#define MPU6050_MOT_COUNT_1 (bit(MPU6050_MOT_COUNT0))
-#define MPU6050_MOT_COUNT_2 (bit(MPU6050_MOT_COUNT1))
-#define MPU6050_MOT_COUNT_3 (bit(MPU6050_MOT_COUNT1)|bit(MPU6050_MOT_COUNT0))
-
-// Alternative names for the combined definitions
-#define MPU6050_MOT_COUNT_RESET MPU6050_MOT_COUNT_0
-
-// Combined definitions for the FF_COUNT
-#define MPU6050_FF_COUNT_0 (0)
-#define MPU6050_FF_COUNT_1 (bit(MPU6050_FF_COUNT0))
-#define MPU6050_FF_COUNT_2 (bit(MPU6050_FF_COUNT1))
-#define MPU6050_FF_COUNT_3 (bit(MPU6050_FF_COUNT1)|bit(MPU6050_FF_COUNT0))
-
-// Alternative names for the combined definitions
-#define MPU6050_FF_COUNT_RESET MPU6050_FF_COUNT_0
-
-// Combined definitions for the ACCEL_ON_DELAY
-#define MPU6050_ACCEL_ON_DELAY_0 (0)
-#define MPU6050_ACCEL_ON_DELAY_1 (bit(MPU6050_ACCEL_ON_DELAY0))
-#define MPU6050_ACCEL_ON_DELAY_2 (bit(MPU6050_ACCEL_ON_DELAY1))
-#define MPU6050_ACCEL_ON_DELAY_3 (bit(MPU6050_ACCEL_ON_DELAY1)|bit(MPU6050_ACCEL_ON_DELAY0))
-
-// Alternative names for the ACCEL_ON_DELAY
-#define MPU6050_ACCEL_ON_DELAY_0MS MPU6050_ACCEL_ON_DELAY_0
-#define MPU6050_ACCEL_ON_DELAY_1MS MPU6050_ACCEL_ON_DELAY_1
-#define MPU6050_ACCEL_ON_DELAY_2MS MPU6050_ACCEL_ON_DELAY_2
-#define MPU6050_ACCEL_ON_DELAY_3MS MPU6050_ACCEL_ON_DELAY_3
-
-// USER_CTRL Register
-// These are the names for the bits.
-// Use these only with the bit() macro.
-#define MPU6050_SIG_COND_RESET MPU6050_D0
-#define MPU6050_I2C_MST_RESET MPU6050_D1
-#define MPU6050_FIFO_RESET MPU6050_D2
-#define MPU6050_I2C_IF_DIS MPU6050_D4 // must be 0 for MPU-6050
-#define MPU6050_I2C_MST_EN MPU6050_D5
-#define MPU6050_FIFO_EN MPU6050_D6
-
-// PWR_MGMT_1 Register
-// These are the names for the bits.
-// Use these only with the bit() macro.
-#define MPU6050_CLKSEL0 MPU6050_D0
-#define MPU6050_CLKSEL1 MPU6050_D1
-#define MPU6050_CLKSEL2 MPU6050_D2
-#define MPU6050_TEMP_DIS MPU6050_D3 // 1: disable temperature sensor
-#define MPU6050_CYCLE MPU6050_D5 // 1: sample and sleep
-#define MPU6050_SLEEP MPU6050_D6 // 1: sleep mode
-#define MPU6050_DEVICE_RESET MPU6050_D7 // 1: reset to default values
-
-// Combined definitions for the CLKSEL
-#define MPU6050_CLKSEL_0 (0)
-#define MPU6050_CLKSEL_1 (bit(MPU6050_CLKSEL0))
-#define MPU6050_CLKSEL_2 (bit(MPU6050_CLKSEL1))
-#define MPU6050_CLKSEL_3 (bit(MPU6050_CLKSEL1)|bit(MPU6050_CLKSEL0))
-#define MPU6050_CLKSEL_4 (bit(MPU6050_CLKSEL2))
-#define MPU6050_CLKSEL_5 (bit(MPU6050_CLKSEL2)|bit(MPU6050_CLKSEL0))
-#define MPU6050_CLKSEL_6 (bit(MPU6050_CLKSEL2)|bit(MPU6050_CLKSEL1))
-#define MPU6050_CLKSEL_7 (bit(MPU6050_CLKSEL2)|bit(MPU6050_CLKSEL1)|bit(MPU6050_CLKSEL0))
-
-// Alternative names for the combined definitions
-#define MPU6050_CLKSEL_INTERNAL MPU6050_CLKSEL_0
-#define MPU6050_CLKSEL_X MPU6050_CLKSEL_1
-#define MPU6050_CLKSEL_Y MPU6050_CLKSEL_2
-#define MPU6050_CLKSEL_Z MPU6050_CLKSEL_3
-#define MPU6050_CLKSEL_EXT_32KHZ MPU6050_CLKSEL_4
-#define MPU6050_CLKSEL_EXT_19_2MHZ MPU6050_CLKSEL_5
-#define MPU6050_CLKSEL_RESERVED MPU6050_CLKSEL_6
-#define MPU6050_CLKSEL_STOP MPU6050_CLKSEL_7
-
-// PWR_MGMT_2 Register
-// These are the names for the bits.
-// Use these only with the bit() macro.
-#define MPU6050_STBY_ZG MPU6050_D0
-#define MPU6050_STBY_YG MPU6050_D1
-#define MPU6050_STBY_XG MPU6050_D2
-#define MPU6050_STBY_ZA MPU6050_D3
-#define MPU6050_STBY_YA MPU6050_D4
-#define MPU6050_STBY_XA MPU6050_D5
-#define MPU6050_LP_WAKE_CTRL0 MPU6050_D6
-#define MPU6050_LP_WAKE_CTRL1 MPU6050_D7
-
-// Combined definitions for the LP_WAKE_CTRL
-#define MPU6050_LP_WAKE_CTRL_0 (0)
-#define MPU6050_LP_WAKE_CTRL_1 (bit(MPU6050_LP_WAKE_CTRL0))
-#define MPU6050_LP_WAKE_CTRL_2 (bit(MPU6050_LP_WAKE_CTRL1))
-#define MPU6050_LP_WAKE_CTRL_3 (bit(MPU6050_LP_WAKE_CTRL1)|bit(MPU6050_LP_WAKE_CTRL0))
-
-// Alternative names for the combined definitions
-// The names uses the Wake-up Frequency.
-#define MPU6050_LP_WAKE_1_25HZ MPU6050_LP_WAKE_CTRL_0
-#define MPU6050_LP_WAKE_2_5HZ MPU6050_LP_WAKE_CTRL_1
-#define MPU6050_LP_WAKE_5HZ MPU6050_LP_WAKE_CTRL_2
-#define MPU6050_LP_WAKE_10HZ MPU6050_LP_WAKE_CTRL_3
-
-
-// Default I2C address for the MPU-6050 is 0x68.
-// But only if the AD0 pin is low.
-// Some sensor boards have AD0 high, and the
-// I2C address thus becomes 0x69.
-#define MPU6050_I2C_ADDRESS 0x68
-
-
-// Declaring an union for the registers and the axis values.
-// The byte order does not match the byte order of
-// the compiler and AVR chip.
-// The AVR chip (on the Arduino board) has the Low Byte
-// at the lower address.
-// But the MPU-6050 has a different order: High Byte at
-// lower address, so that has to be corrected.
-// The register part "reg" is only used internally,
-// and are swapped in code.
-typedef union accel_t_gyro_union
-{
- struct
- {
- uint8_t x_accel_h;
- uint8_t x_accel_l;
- uint8_t y_accel_h;
- uint8_t y_accel_l;
- uint8_t z_accel_h;
- uint8_t z_accel_l;
- uint8_t t_h;
- uint8_t t_l;
- uint8_t x_gyro_h;
- uint8_t x_gyro_l;
- uint8_t y_gyro_h;
- uint8_t y_gyro_l;
- uint8_t z_gyro_h;
- uint8_t z_gyro_l;
- } reg;
- struct
- {
- int x_accel;
- int y_accel;
- int z_accel;
- int temperature;
- int x_gyro;
- int y_gyro;
- int z_gyro;
- } value;
-};
-
-int MPU6050_init();
-int MPU6050_readout(accel_t_gyro_union* accel_t_gyro);
-
-#endif // MPU6050_H_INCLUDED
diff --git a/obdlogger/MultiLCD.cpp b/obdlogger/MultiLCD.cpp
deleted file mode 100644
index cff82c2..0000000
--- a/obdlogger/MultiLCD.cpp
+++ /dev/null
@@ -1,182 +0,0 @@
-#include <Arduino.h>
-#include "MultiLCD.h"
-
-const PROGMEM unsigned char font16x16[][32] = {
-{0x00,0xE0,0xF8,0xFC,0xFE,0x1E,0x07,0x07,0x07,0x07,0x1E,0xFE,0xFC,0xF8,0xF0,0x00,0x00,0x07,0x0F,0x3F,0x3F,0x7C,0x70,0x70,0x70,0x70,0x7C,0x3F,0x1F,0x1F,0x07,0x00},/*0*/
-{0x00,0x00,0x00,0x06,0x07,0x07,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0x7F,0x7F,0x7F,0x00,0x00,0x00,0x00,0x00,0x00},/*1*/
-{0x00,0x38,0x3C,0x3E,0x3E,0x0F,0x07,0x07,0x07,0xCF,0xFF,0xFE,0xFE,0x38,0x00,0x00,0x00,0x40,0x40,0x60,0x70,0x78,0x7C,0x7E,0x7F,0x77,0x73,0x71,0x70,0x70,0x00,0x00},/*2*/
-{0x00,0x18,0x1C,0x1E,0x1E,0x0F,0xC7,0xC7,0xE7,0xFF,0xFE,0xBE,0x9C,0x00,0x00,0x00,0x00,0x0C,0x1C,0x3C,0x3C,0x78,0x70,0x70,0x70,0x79,0x7F,0x3F,0x1F,0x0F,0x00,0x00},/*3*/
-{0x00,0x00,0x80,0xC0,0xE0,0x70,0x38,0x1C,0x1E,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x06,0x07,0x07,0x07,0x06,0x06,0x06,0x06,0x06,0x7F,0x7F,0x7F,0x7F,0x06,0x06,0x00},/*4*/
-{0x00,0x00,0x00,0x00,0xF0,0xFF,0xFF,0xFF,0xE7,0xE7,0xE7,0xE7,0xC7,0x87,0x00,0x00,0x00,0x00,0x38,0x78,0x71,0x70,0x70,0x70,0x70,0x70,0x39,0x3F,0x3F,0x1F,0x0F,0x00},/*5*/
-{0x00,0x80,0xE0,0xF0,0xF8,0xFC,0x7F,0x7F,0x6F,0x67,0xE1,0xE1,0xC0,0x80,0x00,0x00,0x00,0x0F,0x1F,0x3F,0x3F,0x78,0x70,0x70,0x70,0x70,0x78,0x3F,0x3F,0x1F,0x0F,0x00},/*6*/
-{0x00,0x07,0x07,0x07,0x07,0x07,0xC7,0xE7,0xF7,0xFF,0x7F,0x3F,0x1F,0x07,0x03,0x01,0x00,0x20,0x38,0x7C,0x7E,0x3F,0x0F,0x07,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*7*/
-{0x00,0x00,0x00,0x1C,0xBE,0xFE,0xFF,0xE7,0xC3,0xC3,0xE7,0xFF,0xFE,0xBE,0x1C,0x00,0x00,0x00,0x0E,0x3F,0x3F,0x7F,0x71,0x60,0x60,0x60,0x71,0x7F,0x3F,0x3F,0x0F,0x00},/*8*/
-{0x00,0x78,0xFC,0xFE,0xFE,0x8F,0x07,0x07,0x07,0x07,0x8F,0xFE,0xFE,0xFC,0xF8,0x00,0x00,0x00,0x00,0x01,0x43,0x43,0x73,0x7B,0x7F,0x7F,0x1F,0x0F,0x07,0x03,0x00,0x00},/*9*/
-};
-
-// The 7-bit ASCII character set...
-const PROGMEM unsigned char font5x8[][5] = {
- { 0x00, 0x00, 0x00, 0x00, 0x00 }, // 20 space
- { 0x00, 0x00, 0x5f, 0x00, 0x00 }, // 21 !
- { 0x00, 0x07, 0x00, 0x07, 0x00 }, // 22 "
- { 0x14, 0x7f, 0x14, 0x7f, 0x14 }, // 23 #
- { 0x24, 0x2a, 0x7f, 0x2a, 0x12 }, // 24 $
- { 0x23, 0x13, 0x08, 0x64, 0x62 }, // 25 %
- { 0x36, 0x49, 0x55, 0x22, 0x50 }, // 26 &
- { 0x00, 0x05, 0x03, 0x00, 0x00 }, // 27 '
- { 0x00, 0x1c, 0x22, 0x41, 0x00 }, // 28 (
- { 0x00, 0x41, 0x22, 0x1c, 0x00 }, // 29 )
- { 0x14, 0x08, 0x3e, 0x08, 0x14 }, // 2a *
- { 0x08, 0x08, 0x3e, 0x08, 0x08 }, // 2b +
- { 0x00, 0x50, 0x30, 0x00, 0x00 }, // 2c ,
- { 0x08, 0x08, 0x08, 0x08, 0x08 }, // 2d -
- { 0x00, 0x60, 0x60, 0x00, 0x00 }, // 2e .
- { 0x20, 0x10, 0x08, 0x04, 0x02 }, // 2f /
- { 0x3e, 0x51, 0x49, 0x45, 0x3e }, // 30 0
- { 0x00, 0x42, 0x7f, 0x40, 0x00 }, // 31 1
- { 0x42, 0x61, 0x51, 0x49, 0x46 }, // 32 2
- { 0x21, 0x41, 0x45, 0x4b, 0x31 }, // 33 3
- { 0x18, 0x14, 0x12, 0x7f, 0x10 }, // 34 4
- { 0x27, 0x45, 0x45, 0x45, 0x39 }, // 35 5
- { 0x3c, 0x4a, 0x49, 0x49, 0x30 }, // 36 6
- { 0x01, 0x71, 0x09, 0x05, 0x03 }, // 37 7
- { 0x36, 0x49, 0x49, 0x49, 0x36 }, // 38 8
- { 0x06, 0x49, 0x49, 0x29, 0x1e }, // 39 9
- { 0x00, 0x36, 0x36, 0x00, 0x00 }, // 3a :
- { 0x00, 0x56, 0x36, 0x00, 0x00 }, // 3b ;
- { 0x08, 0x14, 0x22, 0x41, 0x00 }, // 3c <
- { 0x14, 0x14, 0x14, 0x14, 0x14 }, // 3d =
- { 0x00, 0x41, 0x22, 0x14, 0x08 }, // 3e >
- { 0x02, 0x01, 0x51, 0x09, 0x06 }, // 3f ?
- { 0x32, 0x49, 0x79, 0x41, 0x3e }, // 40 @
- { 0x7e, 0x11, 0x11, 0x11, 0x7e }, // 41 A
- { 0x7f, 0x49, 0x49, 0x49, 0x36 }, // 42 B
- { 0x3e, 0x41, 0x41, 0x41, 0x22 }, // 43 C
- { 0x7f, 0x41, 0x41, 0x22, 0x1c }, // 44 D
- { 0x7f, 0x49, 0x49, 0x49, 0x41 }, // 45 E
- { 0x7f, 0x09, 0x09, 0x09, 0x01 }, // 46 F
- { 0x3e, 0x41, 0x49, 0x49, 0x7a }, // 47 G
- { 0x7f, 0x08, 0x08, 0x08, 0x7f }, // 48 H
- { 0x00, 0x41, 0x7f, 0x41, 0x00 }, // 49 I
- { 0x20, 0x40, 0x41, 0x3f, 0x01 }, // 4a J
- { 0x7f, 0x08, 0x14, 0x22, 0x41 }, // 4b K
- { 0x7f, 0x40, 0x40, 0x40, 0x40 }, // 4c L
- { 0x7f, 0x02, 0x0c, 0x02, 0x7f }, // 4d M
- { 0x7f, 0x04, 0x08, 0x10, 0x7f }, // 4e N
- { 0x3e, 0x41, 0x41, 0x41, 0x3e }, // 4f O
- { 0x7f, 0x09, 0x09, 0x09, 0x06 }, // 50 P
- { 0x3e, 0x41, 0x51, 0x21, 0x5e }, // 51 Q
- { 0x7f, 0x09, 0x19, 0x29, 0x46 }, // 52 R
- { 0x46, 0x49, 0x49, 0x49, 0x31 }, // 53 S
- { 0x01, 0x01, 0x7f, 0x01, 0x01 }, // 54 T
- { 0x3f, 0x40, 0x40, 0x40, 0x3f }, // 55 U
- { 0x1f, 0x20, 0x40, 0x20, 0x1f }, // 56 V
- { 0x3f, 0x40, 0x38, 0x40, 0x3f }, // 57 W
- { 0x63, 0x14, 0x08, 0x14, 0x63 }, // 58 X
- { 0x07, 0x08, 0x70, 0x08, 0x07 }, // 59 Y
- { 0x61, 0x51, 0x49, 0x45, 0x43 }, // 5a Z
- { 0x00, 0x7f, 0x41, 0x41, 0x00 }, // 5b [
- { 0x02, 0x04, 0x08, 0x10, 0x20 }, // 5c backslash
- { 0x00, 0x41, 0x41, 0x7f, 0x00 }, // 5d ]
- { 0x04, 0x02, 0x01, 0x02, 0x04 }, // 5e ^
- { 0x40, 0x40, 0x40, 0x40, 0x40 }, // 5f _
- { 0x00, 0x01, 0x02, 0x04, 0x00 }, // 60 `
- { 0x20, 0x54, 0x54, 0x54, 0x78 }, // 61 a
- { 0x7f, 0x48, 0x44, 0x44, 0x38 }, // 62 b
- { 0x38, 0x44, 0x44, 0x44, 0x20 }, // 63 c
- { 0x38, 0x44, 0x44, 0x48, 0x7f }, // 64 d
- { 0x38, 0x54, 0x54, 0x54, 0x18 }, // 65 e
- { 0x08, 0x7e, 0x09, 0x01, 0x02 }, // 66 f
- { 0x0c, 0x52, 0x52, 0x52, 0x3e }, // 67 g
- { 0x7f, 0x08, 0x04, 0x04, 0x78 }, // 68 h
- { 0x00, 0x44, 0x7d, 0x40, 0x00 }, // 69 i
- { 0x20, 0x40, 0x44, 0x3d, 0x00 }, // 6a j
- { 0x7f, 0x10, 0x28, 0x44, 0x00 }, // 6b k
- { 0x00, 0x41, 0x7f, 0x40, 0x00 }, // 6c l
- { 0x7c, 0x04, 0x18, 0x04, 0x78 }, // 6d m
- { 0x7c, 0x08, 0x04, 0x04, 0x78 }, // 6e n
- { 0x38, 0x44, 0x44, 0x44, 0x38 }, // 6f o
- { 0x7c, 0x14, 0x14, 0x14, 0x08 }, // 70 p
- { 0x08, 0x14, 0x14, 0x18, 0x7c }, // 71 q
- { 0x7c, 0x08, 0x04, 0x04, 0x08 }, // 72 r
- { 0x48, 0x54, 0x54, 0x54, 0x20 }, // 73 s
- { 0x04, 0x3f, 0x44, 0x40, 0x20 }, // 74 t
- { 0x3c, 0x40, 0x40, 0x20, 0x7c }, // 75 u
- { 0x1c, 0x20, 0x40, 0x20, 0x1c }, // 76 v
- { 0x3c, 0x40, 0x30, 0x40, 0x3c }, // 77 w
- { 0x44, 0x28, 0x10, 0x28, 0x44 }, // 78 x
- { 0x0c, 0x50, 0x50, 0x50, 0x3c }, // 79 y
- { 0x44, 0x64, 0x54, 0x4c, 0x44 }, // 7a z
- { 0x00, 0x08, 0x36, 0x41, 0x00 }, // 7b {
- { 0x00, 0x00, 0x7f, 0x00, 0x00 }, // 7c |
- { 0x00, 0x41, 0x36, 0x08, 0x00 }, // 7d }
- { 0x10, 0x08, 0x08, 0x10, 0x08 }, // 7e ~
- { 0x00, 0x00, 0x00, 0x00, 0x00 } // 7f
-};
-
-void LCD_OLED::write(char c)
-{
- char s[2] = {c};
- ScI2cMxDisplay8x16Str(OLED_ADDRESS, m_line, m_column, s);
- m_column += 8;
- if (m_column >= 128) {
- m_column = 0;
- m_line += 2;
- }
-}
-
-void LCD_OLED::print(const char* s)
-{
- ScI2cMxDisplay8x16Str(OLED_ADDRESS, m_line, m_column, s);
- m_column += (strlen(s) << 3);
- m_line += (m_column >> 7) << 1;
- m_column %= 0x7f;
-}
-
-void LCD_OLED::printLarge(const char* s)
-{
- delay(5);
- while (*s) {
- if (*s >= '0' && *s <= '9') {
- char data[32];
- memcpy_P(data, font16x16[*s - '0'], 32);
- ScI2cMxDisplayDot16x16(OLED_ADDRESS, m_line, m_column, data);
- } else {
- ScI2cMxFillArea(OLED_ADDRESS, m_line, m_line + 1, m_column, m_column + 16, 0);
- }
- m_column += 16;
- if (m_column >= 128) {
- m_column = 0;
- m_line += 2;
- }
- s++;
- }
-}
-
-void LCD_OLED::clear()
-{
- ScI2cMxFillArea(OLED_ADDRESS, 0, 7, 0, 127, 0);
- delay(10);
- setCursor(0, 0);
-}
-
-void LCD_OLED::begin()
-{
- I2cInit();
- ScI2cMxReset(OLED_ADDRESS);
- delay(10);
-}
-
-void LCD_PCD8544::printLarge(const char* s)
-{
- while (*s) {
- if (*s >= '0' && *s <= '9') {
- unsigned char data[32];
- memcpy_P(data, font16x16[*s - '0'], 32);
- drawBitmap(data, 16, 16);
- } else {
- column = (column + 16) % 84;
- }
- s++;
- }
-}
diff --git a/obdlogger/MultiLCD.h b/obdlogger/MultiLCD.h
deleted file mode 100644
index 5a8f7e3..0000000
--- a/obdlogger/MultiLCD.h
+++ /dev/null
@@ -1,84 +0,0 @@
-extern const PROGMEM unsigned char font16x32[][32];
-extern const PROGMEM unsigned char font5x8[][5];
-
-#include "PCD8544.h"
-
-class LCD_Common
-{
-public:
- virtual void backlight(bool on) {}
- virtual byte getLines() = 0;
- virtual byte getCols() = 0;
- virtual void changeLine() {}
-};
-
-class LCD_PCD8544 : public LCD_Common, public PCD8544
-{
-public:
- byte getLines() { return 6; }
- byte getCols() { return 14; }
- void printLarge(const char* s);
- void backlight(bool on)
- {
- pinMode(7, OUTPUT);
- digitalWrite(7, on ? HIGH : LOW);
- }
- void clearLine(byte line)
- {
- setCursor(0, line);
- for (byte i = 14; i > 0; i--) write(' ');
- }
-};
-
-#include "ZtLib.h"
-
-#define OLED_ADDRESS 0x27
-
-class LCD_OLED : public LCD_Common, public ZtLib
-{
-public:
- byte getLines() { return 4; }
- byte getCols() { return 16; }
- void setCursor(byte column, byte line)
- {
- m_column = column << 3;
- m_line = line << 1;
- }
- void changeLine()
- {
- m_column = 0;
- m_line += 2;
- }
- void write(char c);
- void print(const char* s);
- void printLarge(const char* s);
- void clear();
- void begin();
- void backlight(bool on) {}
- void clearLine(byte line)
- {
- setCursor(0, line);
- for (byte i = 16; i > 0; i--) write(' ');
- }
-private:
- unsigned char m_column;
- unsigned char m_line;
-};
-
-#include "LCD4Bit_mod.h"
-class LCD_1602 : public LCD_Common, public LCD4Bit_mod
-{
-public:
- byte getLines() { return 2; }
- byte getCols() { return 16; }
- void printLarge(const char* s)
- {
- print(s);
- }
- void clearLine(byte line)
- {
- setCursor(0, line);
- for (byte i = 16; i > 0; i--) write(' ');
- }
-};
-
diff --git a/obdlogger/OBD.cpp b/obdlogger/OBD.cpp
deleted file mode 100644
index 55f31e6..0000000
--- a/obdlogger/OBD.cpp
+++ /dev/null
@@ -1,286 +0,0 @@
-/*************************************************************************
-* OBD-II (ELM327) data accessing library for Arduino
-* Distributed under GPL v2.0
-* Copyright (c) 2012 Stanley Huang <stanleyhuangyc@gmail.com>
-* All rights reserved.
-*************************************************************************/
-
-#include <Arduino.h>
-#include <avr/pgmspace.h>
-#include "OBD.h"
-
-#define INIT_CMD_COUNT 4
-#define MAX_CMD_LEN 6
-
-const char PROGMEM s_initcmd[INIT_CMD_COUNT][MAX_CMD_LEN] = {"ATZ\r","ATE0\r","ATL1\r","ATI\r"};
-const char PROGMEM s_searching[] = "SEARCHING";
-const char PROGMEM s_cmd_fmt[] = "%02X%02X 1\r";
-const char PROGMEM s_cmd_sleep[] = "atlp\r";
-const char PROGMEM s_cmd_vin[] = "0902\r";
-const char PROGMEM s_response_begin[] = "41 ";
-
-unsigned int hex2uint16(const char *p)
-{
- char c = *p;
- unsigned int i = 0;
- for (char n = 0; c && n < 4; c = *(++p)) {
- if (c >= 'A' && c <= 'F') {
- c -= 7;
- } else if (c>='a' && c<='f') {
- c -= 39;
- } else if (c == ' ') {
- continue;
- } else if (c < '0' || c > '9') {
- break;
- }
- i = (i << 4) | (c & 0xF);
- n++;
- }
- return i;
-}
-
-unsigned char hex2uint8(const char *p)
-{
- unsigned char c1 = *p;
- unsigned char c2 = *(p + 1);
- if (c1 >= 'A' && c1 <= 'F')
- c1 -= 7;
- else if (c1 >='a' && c1 <= 'f')
- c1 -= 39;
- else if (c1 < '0' || c1 > '9')
- return 0;
-
- if (c2 >= 'A' && c2 <= 'F')
- c2 -= 7;
- else if (c2 >= 'a' && c2 <= 'f')
- c2 -= 39;
- else if (c2 < '0' || c2 > '9')
- return 0;
-
- return c1 << 4 | (c2 & 0xf);
-}
-
-void COBD::Query(unsigned char pid)
-{
- char cmd[8];
- sprintf_P(cmd, s_cmd_fmt, dataMode, pid);
- write(cmd);
-}
-
-bool COBD::ReadSensor(byte pid, int& result, bool passive)
-{
- // send a query command
- Query(pid);
- // wait for reponse
- bool hasData;
- unsigned long tick = millis();
- do {
- DataIdleLoop();
- } while (!(hasData = available()) && millis() - tick < OBD_TIMEOUT_SHORT);
- if (!hasData) {
- errors++;
- return false;
- }
- // receive and parse the response
- return GetResponseParsed(pid, result);
-}
-
-bool COBD::available()
-{
- return OBDUART.available();
-}
-
-char COBD::read()
-{
- return OBDUART.read();
-}
-
-void COBD::write(const char* s)
-{
- OBDUART.write(s);
-}
-
-void COBD::write(const char c)
-{
- OBDUART.write(c);
-}
-
-int COBD::GetConvertedValue(byte pid, char* data)
-{
- int result;
- switch (pid) {
- case PID_RPM:
- result = GetLargeValue(data) >> 2;
- break;
- case PID_FUEL_PRESSURE:
- result = GetSmallValue(data) * 3;
- break;
- case PID_COOLANT_TEMP:
- case PID_INTAKE_TEMP:
- case PID_AMBIENT_TEMP:
- result = GetTemperatureValue(data);
- break;
- case PID_ABS_ENGINE_LOAD:
- result = GetLargeValue(data) * 100 / 255;
- break;
- case PID_MAF_FLOW:
- result = GetLargeValue(data) / 100;
- break;
- case PID_THROTTLE:
- case PID_ENGINE_LOAD:
- case PID_FUEL_LEVEL:
- result = GetPercentageValue(data);
- break;
- case PID_TIMING_ADVANCE:
- result = (GetSmallValue(data) - 128) >> 1;
- break;
- case PID_DISTANCE:
- case PID_RUNTIME:
- result = GetLargeValue(data);
- break;
- default:
- result = GetSmallValue(data);
- }
- return result;
-}
-
-char* COBD::GetResponse(byte& pid, char* buffer)
-{
- unsigned long startTime = millis();
- byte i = 0;
-
- for (;;) {
- if (available()) {
- char c = read();
- buffer[i] = c;
- if (++i == OBD_RECV_BUF_SIZE - 1) {
- // buffer overflow
- break;
- }
- if (c == '>' && i > 6) {
- // prompt char reached
- break;
- }
- } else {
- buffer[i] = 0;
- unsigned int timeout;
- if (dataMode != 1 || strstr_P(buffer, s_searching)) {
- timeout = OBD_TIMEOUT_LONG;
- } else {
- timeout = OBD_TIMEOUT_SHORT;
- }
- if (millis() - startTime > timeout) {
- // timeout
- errors++;
- break;
- }
- DataIdleLoop();
- }
- }
- buffer[i] = 0;
-
- char *p = buffer;
- while ((p = strstr_P(p, s_response_begin))) {
- p += 3;
- byte curpid = hex2uint8(p);
- if (pid == 0) pid = curpid;
- if (curpid == pid) {
- errors = 0;
- p += 2;
- if (*p == ' ')
- return p + 1;
- }
- }
- return 0;
-}
-
-bool COBD::GetResponseParsed(byte& pid, int& result)
-{
- char buffer[OBD_RECV_BUF_SIZE];
- char* data = GetResponse(pid, buffer);
- if (!data) {
- // try recover next time
- write('\r');
- return false;
- }
- result = GetConvertedValue(pid, data);
- return true;
-}
-
-void COBD::Sleep(int seconds)
-{
- char cmd[MAX_CMD_LEN];
- strcpy_P(cmd, s_cmd_sleep);
- write(cmd);
- if (seconds) {
- delay((unsigned long)seconds << 10);
- write('\r');
- }
-}
-
-bool COBD::IsValidPID(byte pid)
-{
- if (pid >= 0x7f)
- return false;
- pid--;
- byte i = pid >> 3;
- byte b = 0x80 >> (pid & 0x7);
- return pidmap[i] & b;
-}
-
-bool COBD::Init(bool passive)
-{
- unsigned long currentMillis;
- unsigned char n;
- char prompted;
- char buffer[OBD_RECV_BUF_SIZE];
-
- for (unsigned char i = 0; i < INIT_CMD_COUNT; i++) {
- if (!passive) {
- char cmd[MAX_CMD_LEN];
- strcpy_P(cmd, s_initcmd[i]);
- write(cmd);
- }
- n = 0;
- prompted = 0;
- currentMillis = millis();
- for (;;) {
- if (available()) {
- char c = read();
- if (c == '>') {
- buffer[n] = 0;
- prompted++;
- } else if (n < OBD_RECV_BUF_SIZE - 1) {
- buffer[n++] = c;
- }
- } else if (prompted) {
- break;
- } else {
- unsigned long elapsed = millis() - currentMillis;
- if (elapsed > OBD_TIMEOUT_INIT) {
- // init timeout
- //WriteData("\r");
- return false;
- }
- InitIdleLoop();
- }
- }
- }
-
- // load pid map
- memset(pidmap, 0, sizeof(pidmap));
- for (byte i = 0; i < 4; i++) {
- byte pid = i * 0x20;
- Query(pid);
- char* data = GetResponse(pid, buffer);
- if (!data) break;
- data--;
- for (byte n = 0; n < 4; n++) {
- if (data[n * 3] != ' ')
- break;
- pidmap[i * 4 + n] = hex2uint8(data + n * 3 + 1);
- }
- }
- errors = 0;
- return true;
-}
diff --git a/obdlogger/OBD.h b/obdlogger/OBD.h
deleted file mode 100644
index 9662dac..0000000
--- a/obdlogger/OBD.h
+++ /dev/null
@@ -1,84 +0,0 @@
-/*************************************************************************
-* OBD-II (ELM327) data accessing library for Arduino
-* Distributed under GPL v2.0
-* Copyright (c) 2012 Stanley Huang <stanleyhuangyc@gmail.com>
-* All rights reserved.
-*************************************************************************/
-
-#define OBD_TIMEOUT_SHORT 2000 /* ms */
-#define OBD_TIMEOUT_LONG 7000 /* ms */
-#define OBD_TIMEOUT_INIT 3000 /* ms */
-#define OBD_SERIAL_BAUDRATE 38400
-#define OBD_RECV_BUF_SIZE 64
-
-#ifndef OBDUART
-#if defined(__AVR_ATmega32U4__) || defined(__AVR_ATmega2560__) || defined(__AVR_ATmega1280__)
-#define OBDUART Serial1
-#else
-#define OBDUART Serial
-#endif
-#endif
-
-// mode 0 pids
-#define PID_RPM 0x0C
-#define PID_SPEED 0x0D
-#define PID_THROTTLE 0x11
-#define PID_ENGINE_LOAD 0x04
-#define PID_COOLANT_TEMP 0x05
-#define PID_INTAKE_TEMP 0x0F
-#define PID_MAF_FLOW 0x10
-#define PID_ABS_ENGINE_LOAD 0x43
-#define PID_AMBIENT_TEMP 0x46
-#define PID_FUEL_PRESSURE 0x0A
-#define PID_INTAKE_MAP 0x0B
-#define PID_BAROMETRIC 0x33
-#define PID_TIMING_ADVANCE 0x0E
-#define PID_FUEL_LEVEL 0x2F
-#define PID_RUNTIME 0x1F
-#define PID_DISTANCE 0x31
-
-unsigned int hex2uint16(const char *p);
-unsigned char hex2uint8(const char *p);
-
-class COBD
-{
-public:
- COBD():dataMode(1),errors(0) {}
- bool Init(bool passive = false);
- bool ReadSensor(byte pid, int& result, bool passive = false);
- bool IsValidPID(byte pid);
- void Sleep(int seconds);
- // Query and GetResponse for advanced usage only
- void Query(byte pid);
- char* GetResponse(byte& pid, char* buffer);
- bool GetResponseParsed(byte& pid, int& result);
- void SetDataMode(byte mode) { dataMode = mode; }
- byte errors;
- //char recvBuf[OBD_RECV_BUF_SIZE];
-protected:
- static int GetConvertedValue(byte pid, char* data);
- static int GetPercentageValue(char* data)
- {
- return (int)hex2uint8(data) * 100 / 255;
- }
- static int GetLargeValue(char* data)
- {
- return hex2uint16(data);
- }
- static int GetSmallValue(char* data)
- {
- return hex2uint8(data);
- }
- static int GetTemperatureValue(char* data)
- {
- return (int)hex2uint8(data) - 40;
- }
- virtual bool available();
- virtual char read();
- virtual void write(const char* s);
- virtual void write(const char c);
- virtual void InitIdleLoop() {}
- virtual void DataIdleLoop() {}
- byte pidmap[4 * 4];
- byte dataMode;
-};
diff --git a/obdlogger/PCD8544.cpp b/obdlogger/PCD8544.cpp
deleted file mode 100644
index a54bfc8..0000000
--- a/obdlogger/PCD8544.cpp
+++ /dev/null
@@ -1,313 +0,0 @@
-/*
- * PCD8544 - Interface with Philips PCD8544 (or compatible) LCDs.
- *
- * Copyright (c) 2010 Carlos Rodrigues <cefrodrigues@gmail.com>
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-
-
-#include "PCD8544.h"
-
-#include <Arduino.h>
-#include <avr/pgmspace.h>
-
-
-#define PCD8544_CMD LOW
-#define PCD8544_DATA HIGH
-
-extern const PROGMEM unsigned char font5x8[][5];
-
-/*
- * If this was a ".h", it would get added to sketches when using
- * the "Sketch -> Import Library..." menu on the Arduino IDE...
- */
-
-PCD8544::PCD8544(unsigned char sclk, unsigned char sdin,
- unsigned char dc, unsigned char reset,
- unsigned char sce):
- pin_sclk(sclk),
- pin_sdin(sdin),
- pin_dc(dc),
- pin_reset(reset),
- pin_sce(sce)
-{}
-
-
-void PCD8544::begin(unsigned char width, unsigned char height, unsigned char model)
-{
- this->width = width;
- this->height = height;
-
- this->column = 0;
- this->line = 0;
-
- // Sanitize the custom glyphs...
- memset(this->custom, 0, sizeof(this->custom));
-
- // All pins are outputs (these displays cannot be read)...
- pinMode(this->pin_sclk, OUTPUT);
- pinMode(this->pin_sdin, OUTPUT);
- pinMode(this->pin_dc, OUTPUT);
- pinMode(this->pin_reset, OUTPUT);
- pinMode(this->pin_sce, OUTPUT);
-
- // Reset the controller state...
- digitalWrite(this->pin_reset, HIGH);
- digitalWrite(this->pin_sce, HIGH);
- digitalWrite(this->pin_reset, LOW);
- delay(100);
- digitalWrite(this->pin_reset, HIGH);
-
- // Set the LCD parameters...
- this->send(PCD8544_CMD, 0x21); // extended instruction set control (H=1)
- this->send(PCD8544_CMD, 0x13); // bias system (1:48)
-
- if (model == CHIP_ST7576) {
- this->send(PCD8544_CMD, 0xe0); // higher Vop, too faint at default
- this->send(PCD8544_CMD, 0x05); // partial display mode
- } else {
- this->send(PCD8544_CMD, 0xc2); // default Vop (3.06 + 66 * 0.06 = 7V)
- }
-
- this->send(PCD8544_CMD, 0x20); // extended instruction set control (H=0)
- this->send(PCD8544_CMD, 0x09); // all display segments on
-
- // Clear RAM contents...
- this->clear();
-
- // Activate LCD...
- this->send(PCD8544_CMD, 0x08); // display blank
- this->send(PCD8544_CMD, 0x0c); // normal mode (0x0d = inverse mode)
- delay(100);
-
- // Place the cursor at the origin...
- this->send(PCD8544_CMD, 0x80);
- this->send(PCD8544_CMD, 0x40);
-}
-
-
-void PCD8544::stop()
-{
- this->clear();
- this->setPower(false);
-}
-
-
-void PCD8544::clear()
-{
- this->setCursor(0, 0);
-
- for (unsigned short i = 0; i < this->width * (this->height/8); i++) {
- this->send(PCD8544_DATA, 0x00);
- }
-
- this->setCursor(0, 0);
-}
-
-
-void PCD8544::clearLine()
-{
- this->setCursor(0, this->line);
-
- for (unsigned char i = 0; i < this->width; i++) {
- this->send(PCD8544_DATA, 0x00);
- }
-
- this->setCursor(0, this->line);
-}
-
-
-void PCD8544::setPower(bool on)
-{
- this->send(PCD8544_CMD, on ? 0x20 : 0x24);
-}
-
-
-inline void PCD8544::display()
-{
- this->setPower(true);
-}
-
-
-inline void PCD8544::noDisplay()
-{
- this->setPower(false);
-}
-
-
-void PCD8544::setInverse(bool inverse)
-{
- this->send(PCD8544_CMD, inverse ? 0x0d : 0x0c);
-}
-
-
-void PCD8544::home()
-{
- this->setCursor(0, this->line);
-}
-
-
-void PCD8544::setCursor(unsigned char column, unsigned char line)
-{
- this->column = (column * 6 % this->width);
- this->line = (line % (this->height/9 + 1));
-
- this->send(PCD8544_CMD, 0x80 | this->column);
- this->send(PCD8544_CMD, 0x40 | this->line);
-}
-
-
-void PCD8544::createChar(unsigned char chr, const unsigned char *glyph)
-{
- // ASCII 0-31 only...
- if (chr >= ' ') {
- return;
- }
-
- this->custom[chr] = glyph;
-}
-
-
-#if ARDUINO < 100
-void PCD8544::write(uint8_t chr)
-#else
-size_t PCD8544::write(uint8_t chr)
-#endif
-{
- // ASCII 7-bit only...
- if (chr >= 0x80) {
-#if ARDUINO < 100
- return;
-#else
- return 0;
-#endif
- }
-
- const unsigned char *glyph;
- unsigned char pgm_buffer[5];
-
- if (chr >= ' ') {
- // Regular ASCII characters are kept in flash to save RAM...
- memcpy_P(pgm_buffer, &font5x8[chr - ' '], sizeof(pgm_buffer));
- glyph = pgm_buffer;
- } else {
- // Custom glyphs, on the other hand, are stored in RAM...
- if (custom[chr]) {
- glyph = custom[chr];
- } else {
- // Default to a space character if unset...
- memcpy_P(pgm_buffer, &font5x8[0], sizeof(pgm_buffer));
- glyph = pgm_buffer;
- }
- }
-
- // Output one column at a time...
- for (unsigned char i = 0; i < 5; i++) {
- this->send(PCD8544_DATA, glyph[i]);
- }
-
- // One column between characters...
- this->send(PCD8544_DATA, 0x00);
-
- // Update the cursor position...
- this->column = (this->column + 6) % this->width;
-
- if (this->column == 0) {
- this->line = (this->line + 1) % (this->height/9 + 1);
- }
-
-#if ARDUINO >= 100
- return 1;
-#endif
-}
-
-
-void PCD8544::drawBitmap(const unsigned char *data, unsigned char columns, unsigned char lines)
-{
- unsigned char scolumn = this->column;
- unsigned char sline = this->line;
-
- // The bitmap will be clipped at the right/bottom edge of the display...
- unsigned char mx = (scolumn + columns > this->width) ? (this->width - scolumn) : columns;
- unsigned char my = (sline + lines > this->height/8) ? (this->height/8 - sline) : lines;
-
- for (unsigned char y = 0; y < my; y++) {
- this->setCursor(scolumn, sline + y);
-
- for (unsigned char x = 0; x < mx; x++) {
- this->send(PCD8544_DATA, data[y * columns + x]);
- }
- }
-
- // Leave the cursor in a consistent position...
- this->setCursor(scolumn + columns, sline);
-}
-
-
-void PCD8544::drawColumn(unsigned char lines, unsigned char value)
-{
- unsigned char scolumn = this->column;
- unsigned char sline = this->line;
-
- // Keep "value" within range...
- if (value > lines*8) {
- value = lines*8;
- }
-
- // Find the line where "value" resides...
- unsigned char mark = (lines*8 - 1 - value)/8;
-
- // Clear the lines above the mark...
- for (unsigned char line = 0; line < mark; line++) {
- this->setCursor(scolumn, sline + line);
- this->send(PCD8544_DATA, 0x00);
- }
-
- // Compute the byte to draw at the "mark" line...
- unsigned char b = 0xff;
- for (unsigned char i = 0; i < lines*8 - mark*8 - value; i++) {
- b <<= 1;
- }
-
- this->setCursor(scolumn, sline + mark);
- this->send(PCD8544_DATA, b);
-
- // Fill the lines below the mark...
- for (unsigned char line = mark + 1; line < lines; line++) {
- this->setCursor(scolumn, sline + line);
- this->send(PCD8544_DATA, 0xff);
- }
-
- // Leave the cursor in a consistent position...
- this->setCursor(scolumn + 1, sline);
-}
-
-
-void PCD8544::send(unsigned char type, unsigned char data)
-{
- digitalWrite(this->pin_dc, type);
-
- digitalWrite(this->pin_sce, LOW);
- shiftOut(this->pin_sdin, this->pin_sclk, MSBFIRST, data);
- digitalWrite(this->pin_sce, HIGH);
-}
-
-
-/* vim: set expandtab ts=4 sw=4: */
diff --git a/obdlogger/PCD8544.h b/obdlogger/PCD8544.h
deleted file mode 100644
index c6e8d43..0000000
--- a/obdlogger/PCD8544.h
+++ /dev/null
@@ -1,124 +0,0 @@
-/*
- * PCD8544 - Interface with Philips PCD8544 (or compatible) LCDs.
- *
- * Copyright (c) 2010 Carlos Rodrigues <cefrodrigues@gmail.com>
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-
-
-#ifndef PCD8544_H
-#define PCD8544_H
-
-
-#if ARDUINO < 100
-#include <WProgram.h>
-#else
-#include <Arduino.h>
-#endif
-
-
-// Chip variants supported...
-#define CHIP_PCD8544 0
-#define CHIP_ST7576 1
-
-
-class PCD8544: public Print {
- public:
- // All the pins can be changed from the default values...
- PCD8544(unsigned char sclk = 2, /* clock (display pin 2) */
- unsigned char sdin = 3, /* data-in (display pin 3) */
- unsigned char dc = 4, /* data select (display pin 4) */
- unsigned char reset = 6, /* reset (display pin 8) */
- unsigned char sce = 5); /* enable (display pin 5) */
-
- // Display initialization (dimensions in pixels)...
- void begin(unsigned char width=84, unsigned char height=48, unsigned char model=CHIP_PCD8544);
- void stop();
-
- // Erase everything on the display...
- void clear();
- void clearLine(); // ...or just the current line
-
- // Control the display's power state...
- void setPower(bool on);
-
- // For compatibility with the LiquidCrystal library...
- void display();
- void noDisplay();
-
- // Activate white-on-black mode (whole display)...
- void setInverse(bool inverse);
-
- // Place the cursor at the start of the current line...
- void home();
-
- // Place the cursor at position (column, line)...
- void setCursor(unsigned char column, unsigned char line);
-
- // Assign a user-defined glyph (5x8) to an ASCII character (0-31)...
- void createChar(unsigned char chr, const unsigned char *glyph);
-
- // Write an ASCII character at the current cursor position (7-bit)...
-#if ARDUINO < 100
- virtual void write(uint8_t chr);
-#else
- virtual size_t write(uint8_t chr);
-#endif
-
- // Draw a bitmap at the current cursor position...
- void drawBitmap(const unsigned char *data, unsigned char columns, unsigned char lines);
-
- // Draw a chart element at the current cursor position...
- void drawColumn(unsigned char lines, unsigned char value);
-
- void changeLine()
- {
- column = 0;
- line ++;
- }
- protected:
- // Current cursor position...
- unsigned char column;
- unsigned char line;
-
- private:
- unsigned char pin_sclk;
- unsigned char pin_sdin;
- unsigned char pin_dc;
- unsigned char pin_reset;
- unsigned char pin_sce;
-
- // The size of the display, in pixels...
- unsigned char width;
- unsigned char height;
-
-
- // User-defined glyphs (below the ASCII space character)...
- const unsigned char *custom[' '];
-
- // Send a command or data to the display...
- void send(unsigned char type, unsigned char data);
-};
-
-
-#endif /* PCD8544_H */
-
-
-/* vim: set expandtab ts=4 sw=4: */
diff --git a/obdlogger/README.txt b/obdlogger/README.txt
index e94646e..79e7c67 100644
--- a/obdlogger/README.txt
+++ b/obdlogger/README.txt
@@ -4,6 +4,8 @@ http://obd.arduinodev.com
The recorded data is stored in CSV format and the file can be illustrated into a graphic chart by a free service at:
http://obd.arduinodev.com/view.html
+To compile the code with Arduino IDE, please copy all library files from the libraries directory to Arduino's libraries directory.
+
To open the project file (obdlogger.cbp), please download CodeBlocks Arduino Edition (http://www.arduinodev.com/codeblocks).
The source code is distributed under GPL license.
diff --git a/obdlogger/TinyGPS.cpp b/obdlogger/TinyGPS.cpp
deleted file mode 100644
index 00a683c..0000000
--- a/obdlogger/TinyGPS.cpp
+++ /dev/null
@@ -1,426 +0,0 @@
-/*
-TinyGPS - a small GPS library for Arduino providing basic NMEA parsing
-Based on work by and "distance_to" and "course_to" courtesy of Maarten Lamers.
-Suggestion to add satellites(), course_to(), and cardinal(), by Matt Monson.
-Copyright (C) 2008-2012 Mikal Hart
-All rights reserved.
-
-This library is free software; you can redistribute it and/or
-modify it under the terms of the GNU Lesser General Public
-License as published by the Free Software Foundation; either
-version 2.1 of the License, or (at your option) any later version.
-
-This library is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-Lesser General Public License for more details.
-
-You should have received a copy of the GNU Lesser General Public
-License along with this library; if not, write to the Free Software
-Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-*/
-
-#include "TinyGPS.h"
-
-#define _GPRMC_TERM "GPRMC"
-#define _GPGGA_TERM "GPGGA"
-
-TinyGPS::TinyGPS()
- : _time(GPS_INVALID_TIME)
- , _date(GPS_INVALID_DATE)
- , _latitude(GPS_INVALID_ANGLE)
- , _longitude(GPS_INVALID_ANGLE)
- , _altitude(GPS_INVALID_ALTITUDE)
- , _speed(GPS_INVALID_SPEED)
- , _course(GPS_INVALID_ANGLE)
- , _hdop(GPS_INVALID_HDOP)
- , _numsats(GPS_INVALID_SATELLITES)
- , _last_time_fix(GPS_INVALID_FIX_TIME)
- , _last_position_fix(GPS_INVALID_FIX_TIME)
- , _parity(0)
- , _is_checksum_term(false)
- , _sentence_type(_GPS_SENTENCE_OTHER)
- , _term_number(0)
- , _term_offset(0)
- , _gps_data_good(false)
-#ifndef _GPS_NO_STATS
- , _encoded_characters(0)
- , _good_sentences(0)
- , _failed_checksum(0)
-#endif
-{
- _term[0] = '\0';
-}
-
-//
-// public methods
-//
-
-bool TinyGPS::encode(char c)
-{
- bool valid_sentence = false;
-
-#ifndef _GPS_NO_STATS
- ++_encoded_characters;
-#endif
- switch(c)
- {
- case ',': // term terminators
- _parity ^= c;
- case '\r':
- case '\n':
- case '*':
- if (_term_offset < sizeof(_term))
- {
- _term[_term_offset] = 0;
- valid_sentence = term_complete();
- }
- ++_term_number;
- _term_offset = 0;
- _is_checksum_term = c == '*';
- return valid_sentence;
-
- case '$': // sentence begin
- _term_number = _term_offset = 0;
- _parity = 0;
- _sentence_type = _GPS_SENTENCE_OTHER;
- _is_checksum_term = false;
- _gps_data_good = false;
- return valid_sentence;
- }
-
- // ordinary characters
- if (_term_offset < sizeof(_term) - 1)
- _term[_term_offset++] = c;
- if (!_is_checksum_term)
- _parity ^= c;
-
- return valid_sentence;
-}
-
-#ifndef _GPS_NO_STATS
-void TinyGPS::stats(unsigned long *chars, unsigned short *sentences, unsigned short *failed_cs)
-{
- if (chars) *chars = _encoded_characters;
- if (sentences) *sentences = _good_sentences;
- if (failed_cs) *failed_cs = _failed_checksum;
-}
-#endif
-
-//
-// internal utilities
-//
-int TinyGPS::from_hex(char a)
-{
- if (a >= 'A' && a <= 'F')
- return a - 'A' + 10;
- else if (a >= 'a' && a <= 'f')
- return a - 'a' + 10;
- else
- return a - '0';
-}
-
-unsigned long TinyGPS::parse_decimal()
-{
- char *p = _term;
- bool isneg = *p == '-';
- if (isneg) ++p;
- unsigned long ret = 100UL * gpsatol(p);
- while (gpsisdigit(*p)) ++p;
- if (*p == '.')
- {
- if (gpsisdigit(p[1]))
- {
- ret += 10 * (p[1] - '0');
- if (gpsisdigit(p[2]))
- ret += p[2] - '0';
- }
- }
- return isneg ? -ret : ret;
-}
-
-unsigned long TinyGPS::parse_degrees()
-{
- char *p;
- unsigned long left = gpsatol(_term);
- unsigned long tenk_minutes = (left % 100UL) * 10000UL;
- for (p=_term; gpsisdigit(*p); ++p);
- if (*p == '.')
- {
- unsigned long mult = 1000;
- while (gpsisdigit(*++p))
- {
- tenk_minutes += mult * (*p - '0');
- mult /= 10;
- }
- }
- return (left / 100) * 100000 + tenk_minutes / 6;
-}
-
-#define COMBINE(sentence_type, term_number) (((unsigned)(sentence_type) << 5) | term_number)
-
-// Processes a just-completed term
-// Returns true if new sentence has just passed checksum test and is validated
-bool TinyGPS::term_complete()
-{
- if (_is_checksum_term)
- {
- byte checksum = 16 * from_hex(_term[0]) + from_hex(_term[1]);
- if (checksum == _parity)
- {
- if (_gps_data_good)
- {
-#ifndef _GPS_NO_STATS
- ++_good_sentences;
-#endif
- _last_time_fix = _new_time_fix;
- _last_position_fix = _new_position_fix;
-
- switch(_sentence_type)
- {
- case _GPS_SENTENCE_GPRMC:
- _time = _new_time;
- _date = _new_date;
- _latitude = _new_latitude;
- _longitude = _new_longitude;
- _speed = _new_speed;
- _course = _new_course;
- break;
- case _GPS_SENTENCE_GPGGA:
- _altitude = _new_altitude;
- _time = _new_time;
- _latitude = _new_latitude;
- _longitude = _new_longitude;
- _numsats = _new_numsats;
- _hdop = _new_hdop;
- break;
- }
-
- return true;
- }
- }
-
-#ifndef _GPS_NO_STATS
- else
- ++_failed_checksum;
-#endif
- return false;
- }
-
- // the first term determines the sentence type
- if (_term_number == 0)
- {
- if (!gpsstrcmp(_term, _GPRMC_TERM))
- _sentence_type = _GPS_SENTENCE_GPRMC;
- else if (!gpsstrcmp(_term, _GPGGA_TERM))
- _sentence_type = _GPS_SENTENCE_GPGGA;
- else
- _sentence_type = _GPS_SENTENCE_OTHER;
- return false;
- }
-
- if (_sentence_type != _GPS_SENTENCE_OTHER && _term[0])
- switch(COMBINE(_sentence_type, _term_number))
- {
- case COMBINE(_GPS_SENTENCE_GPRMC, 1): // Time in both sentences
- case COMBINE(_GPS_SENTENCE_GPGGA, 1):
- _new_time = parse_decimal();
- _new_time_fix = millis();
- break;
- case COMBINE(_GPS_SENTENCE_GPRMC, 2): // GPRMC validity
- _gps_data_good = _term[0] == 'A';
- break;
- case COMBINE(_GPS_SENTENCE_GPRMC, 3): // Latitude
- case COMBINE(_GPS_SENTENCE_GPGGA, 2):
- _new_latitude = parse_degrees();
- _new_position_fix = millis();
- break;
- case COMBINE(_GPS_SENTENCE_GPRMC, 4): // N/S
- case COMBINE(_GPS_SENTENCE_GPGGA, 3):
- if (_term[0] == 'S')
- _new_latitude = -_new_latitude;
- break;
- case COMBINE(_GPS_SENTENCE_GPRMC, 5): // Longitude
- case COMBINE(_GPS_SENTENCE_GPGGA, 4):
- _new_longitude = parse_degrees();
- break;
- case COMBINE(_GPS_SENTENCE_GPRMC, 6): // E/W
- case COMBINE(_GPS_SENTENCE_GPGGA, 5):
- if (_term[0] == 'W')
- _new_longitude = -_new_longitude;
- break;
- case COMBINE(_GPS_SENTENCE_GPRMC, 7): // Speed (GPRMC)
- _new_speed = parse_decimal();
- break;
- case COMBINE(_GPS_SENTENCE_GPRMC, 8): // Course (GPRMC)
- _new_course = parse_decimal();
- break;
- case COMBINE(_GPS_SENTENCE_GPRMC, 9): // Date (GPRMC)
- _new_date = gpsatol(_term);
- break;
- case COMBINE(_GPS_SENTENCE_GPGGA, 6): // Fix data (GPGGA)
- _gps_data_good = _term[0] > '0';
- break;
- case COMBINE(_GPS_SENTENCE_GPGGA, 7): // Satellites used (GPGGA)
- _new_numsats = (unsigned char)atoi(_term);
- break;
- case COMBINE(_GPS_SENTENCE_GPGGA, 8): // HDOP
- _new_hdop = parse_decimal();
- break;
- case COMBINE(_GPS_SENTENCE_GPGGA, 9): // Altitude (GPGGA)
- _new_altitude = parse_decimal();
- break;
- }
-
- return false;
-}
-
-long TinyGPS::gpsatol(const char *str)
-{
- long ret = 0;
- while (gpsisdigit(*str))
- ret = 10 * ret + *str++ - '0';
- return ret;
-}
-
-int TinyGPS::gpsstrcmp(const char *str1, const char *str2)
-{
- while (*str1 && *str1 == *str2)
- ++str1, ++str2;
- return *str1;
-}
-
-/* static */
-float TinyGPS::distance_between (float lat1, float long1, float lat2, float long2)
-{
- // returns distance in meters between two positions, both specified
- // as signed decimal-degrees latitude and longitude. Uses great-circle
- // distance computation for hypothetical sphere of radius 6372795 meters.
- // Because Earth is no exact sphere, rounding errors may be up to 0.5%.
- // Courtesy of Maarten Lamers
- float delta = radians(long1-long2);
- float sdlong = sin(delta);
- float cdlong = cos(delta);
- lat1 = radians(lat1);
- lat2 = radians(lat2);
- float slat1 = sin(lat1);
- float clat1 = cos(lat1);
- float slat2 = sin(lat2);
- float clat2 = cos(lat2);
- delta = (clat1 * slat2) - (slat1 * clat2 * cdlong);
- delta = sq(delta);
- delta += sq(clat2 * sdlong);
- delta = sqrt(delta);
- float denom = (slat1 * slat2) + (clat1 * clat2 * cdlong);
- delta = atan2(delta, denom);
- return delta * 6372795;
-}
-
-float TinyGPS::course_to (float lat1, float long1, float lat2, float long2)
-{
- // returns course in degrees (North=0, West=270) from position 1 to position 2,
- // both specified as signed decimal-degrees latitude and longitude.
- // Because Earth is no exact sphere, calculated course may be off by a tiny fraction.
- // Courtesy of Maarten Lamers
- float dlon = radians(long2-long1);
- lat1 = radians(lat1);
- lat2 = radians(lat2);
- float a1 = sin(dlon) * cos(lat2);
- float a2 = sin(lat1) * cos(lat2) * cos(dlon);
- a2 = cos(lat1) * sin(lat2) - a2;
- a2 = atan2(a1, a2);
- if (a2 < 0.0)
- {
- a2 += TWO_PI;
- }
- return degrees(a2);
-}
-
-const char *TinyGPS::cardinal (float course)
-{
- static const char* directions[] = {"N", "NNE", "NE", "ENE", "E", "ESE", "SE", "SSE", "S", "SSW", "SW", "WSW", "W", "WNW", "NW", "NNW"};
-
- int direction = (int)((course + 11.25f) / 22.5f);
- return directions[direction % 16];
-}
-
-// lat/long in hundred thousandths of a degree and age of fix in milliseconds
-void TinyGPS::get_position(long *latitude, long *longitude, unsigned long *fix_age)
-{
- if (latitude) *latitude = _latitude;
- if (longitude) *longitude = _longitude;
- if (fix_age) *fix_age = _last_position_fix == GPS_INVALID_FIX_TIME ?
-GPS_INVALID_AGE : millis() - _last_position_fix;
-}
-
-// date as ddmmyy, time as hhmmsscc, and age in milliseconds
-void TinyGPS::get_datetime(unsigned long *date, unsigned long *time, unsigned long *age)
-{
- if (date) *date = _date;
- if (time) *time = _time;
- if (age) *age = _last_time_fix == GPS_INVALID_FIX_TIME ?
-GPS_INVALID_AGE : millis() - _last_time_fix;
-}
-
-void TinyGPS::f_get_position(float *latitude, float *longitude, unsigned long *fix_age)
-{
- long lat, lon;
- get_position(&lat, &lon, fix_age);
- *latitude = lat == GPS_INVALID_ANGLE ? GPS_INVALID_F_ANGLE : (lat / 100000.0);
- *longitude = lat == GPS_INVALID_ANGLE ? GPS_INVALID_F_ANGLE : (lon / 100000.0);
-}
-
-void TinyGPS::crack_datetime(int *year, byte *month, byte *day,
- byte *hour, byte *minute, byte *second, byte *hundredths, unsigned long *age)
-{
- unsigned long date, time;
- get_datetime(&date, &time, age);
- if (year)
- {
- *year = date % 100;
- *year += *year > 80 ? 1900 : 2000;
- }
- if (month) *month = (date / 100) % 100;
- if (day) *day = date / 10000;
- if (hour) *hour = time / 1000000;
- if (minute) *minute = (time / 10000) % 100;
- if (second) *second = (time / 100) % 100;
- if (hundredths) *hundredths = time % 100;
-}
-
-float TinyGPS::f_altitude()
-{
- return _altitude == GPS_INVALID_ALTITUDE ? GPS_INVALID_F_ALTITUDE : _altitude / 100.0;
-}
-
-float TinyGPS::f_course()
-{
- return _course == GPS_INVALID_ANGLE ? GPS_INVALID_F_ANGLE : _course / 100.0;
-}
-
-float TinyGPS::f_speed_knots()
-{
- return _speed == GPS_INVALID_SPEED ? GPS_INVALID_F_SPEED : _speed / 100.0;
-}
-
-float TinyGPS::f_speed_mph()
-{
- float sk = f_speed_knots();
- return sk == GPS_INVALID_F_SPEED ? GPS_INVALID_F_SPEED : _GPS_MPH_PER_KNOT * f_speed_knots();
-}
-
-float TinyGPS::f_speed_mps()
-{
- float sk = f_speed_knots();
- return sk == GPS_INVALID_F_SPEED ? GPS_INVALID_F_SPEED : _GPS_MPS_PER_KNOT * f_speed_knots();
-}
-
-float TinyGPS::f_speed_kmph()
-{
- float sk = f_speed_knots();
- return sk == GPS_INVALID_F_SPEED ? GPS_INVALID_F_SPEED : _GPS_KMPH_PER_KNOT * f_speed_knots();
-}
-
-const float TinyGPS::GPS_INVALID_F_ANGLE = 1000.0;
-const float TinyGPS::GPS_INVALID_F_ALTITUDE = 1000000.0;
-const float TinyGPS::GPS_INVALID_F_SPEED = -1.0;
diff --git a/obdlogger/TinyGPS.h b/obdlogger/TinyGPS.h
deleted file mode 100644
index 89d4148..0000000
--- a/obdlogger/TinyGPS.h
+++ /dev/null
@@ -1,153 +0,0 @@
-/*
-TinyGPS - a small GPS library for Arduino providing basic NMEA parsing
-Based on work by and "distance_to" and "course_to" courtesy of Maarten Lamers.
-Suggestion to add satellites(), course_to(), and cardinal(), by Matt Monson.
-Copyright (C) 2008-2012 Mikal Hart
-All rights reserved.
-
-This library is free software; you can redistribute it and/or
-modify it under the terms of the GNU Lesser General Public
-License as published by the Free Software Foundation; either
-version 2.1 of the License, or (at your option) any later version.
-
-This library is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-Lesser General Public License for more details.
-
-You should have received a copy of the GNU Lesser General Public
-License along with this library; if not, write to the Free Software
-Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-*/
-
-#ifndef TinyGPS_h
-#define TinyGPS_h
-
-#if defined(ARDUINO) && ARDUINO >= 100
-#include "Arduino.h"
-#else
-#include "WProgram.h"
-#endif
-
-#define _GPS_VERSION 12 // software version of this library
-#define _GPS_MPH_PER_KNOT 1.15077945
-#define _GPS_MPS_PER_KNOT 0.51444444
-#define _GPS_KMPH_PER_KNOT 1.852
-#define _GPS_MILES_PER_METER 0.00062137112
-#define _GPS_KM_PER_METER 0.001
-// #define _GPS_NO_STATS
-
-class TinyGPS
-{
-public:
- enum {
- GPS_INVALID_AGE = 0xFFFFFFFF, GPS_INVALID_ANGLE = 999999999,
- GPS_INVALID_ALTITUDE = 999999999, GPS_INVALID_DATE = 0,
- GPS_INVALID_TIME = 0xFFFFFFFF, GPS_INVALID_SPEED = 999999999,
- GPS_INVALID_FIX_TIME = 0xFFFFFFFF, GPS_INVALID_SATELLITES = 0xFF,
- GPS_INVALID_HDOP = 0xFFFFFFFF
- };
-
- static const float GPS_INVALID_F_ANGLE, GPS_INVALID_F_ALTITUDE, GPS_INVALID_F_SPEED;
-
- TinyGPS();
- bool encode(char c); // process one character received from GPS
- TinyGPS &operator << (char c) {encode(c); return *this;}
-
- // lat/long in hundred thousandths of a degree and age of fix in milliseconds
- void get_position(long *latitude, long *longitude, unsigned long *fix_age = 0);
-
- // date as ddmmyy, time as hhmmsscc, and age in milliseconds
- void get_datetime(unsigned long *date, unsigned long *time, unsigned long *age = 0);
-
- // signed altitude in centimeters (from GPGGA sentence)
- inline long altitude() { return _altitude; }
-
- // course in last full GPRMC sentence in 100th of a degree
- inline unsigned long course() { return _course; }
-
- // speed in last full GPRMC sentence in 100ths of a knot
- inline unsigned long speed() { return _speed; }
-
- // satellites used in last full GPGGA sentence
- inline unsigned short satellites() { return _numsats; }
-
- // horizontal dilution of precision in 100ths
- inline unsigned long hdop() { return _hdop; }
-
- void f_get_position(float *latitude, float *longitude, unsigned long *fix_age = 0);
- void crack_datetime(int *year, byte *month, byte *day,
- byte *hour, byte *minute, byte *second, byte *hundredths = 0, unsigned long *fix_age = 0);
- float f_altitude();
- float f_course();
- float f_speed_knots();
- float f_speed_mph();
- float f_speed_mps();
- float f_speed_kmph();
-
- static int library_version() { return _GPS_VERSION; }
-
- static float distance_between (float lat1, float long1, float lat2, float long2);
- static float course_to (float lat1, float long1, float lat2, float long2);
- static const char *cardinal(float course);
-
-#ifndef _GPS_NO_STATS
- void stats(unsigned long *chars, unsigned short *good_sentences, unsigned short *failed_cs);
-#endif
-
-private:
- enum {_GPS_SENTENCE_GPGGA, _GPS_SENTENCE_GPRMC, _GPS_SENTENCE_OTHER};
-
- // properties
- unsigned long _time, _new_time;
- unsigned long _date, _new_date;
- long _latitude, _new_latitude;
- long _longitude, _new_longitude;
- long _altitude, _new_altitude;
- unsigned long _speed, _new_speed;
- unsigned long _course, _new_course;
- unsigned long _hdop, _new_hdop;
- unsigned short _numsats, _new_numsats;
-
- unsigned long _last_time_fix, _new_time_fix;
- unsigned long _last_position_fix, _new_position_fix;
-
- // parsing state variables
- byte _parity;
- bool _is_checksum_term;
- char _term[15];
- byte _sentence_type;
- byte _term_number;
- byte _term_offset;
- bool _gps_data_good;
-
-#ifndef _GPS_NO_STATS
- // statistics
- unsigned long _encoded_characters;
- unsigned short _good_sentences;
- unsigned short _failed_checksum;
- unsigned short _passed_checksum;
-#endif
-
- // internal utilities
- int from_hex(char a);
- unsigned long parse_decimal();
- unsigned long parse_degrees();
- bool term_complete();
- bool gpsisdigit(char c) { return c >= '0' && c <= '9'; }
- long gpsatol(const char *str);
- int gpsstrcmp(const char *str1, const char *str2);
-};
-
-#if !defined(ARDUINO)
-// Arduino 0012 workaround
-#undef int
-#undef char
-#undef long
-#undef byte
-#undef float
-#undef abs
-#undef round
-#endif
-
-#endif
diff --git a/obdlogger/ZtLib.cpp b/obdlogger/ZtLib.cpp
deleted file mode 100644
index f8b55df..0000000
--- a/obdlogger/ZtLib.cpp
+++ /dev/null
@@ -1,601 +0,0 @@
-/*
- ZtLib.cpp - ZT module Drive Library for Wiring & Arduino
- Copyright (c) 2012 Alvin Li(Kozig/www.kozig.com). All right reserved.
- This library is free software;
- This library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- Version:V1.1
-*/
-
-extern "C" {
- #include <stdlib.h>
- #include <string.h>
- #include <inttypes.h>
- #include "../Wire/utility/twi.h"
-}
-
-#include "ZtLib.h"
-
-///ZT.SEG8B4A036A PART///-------------------------------------------------------------------s
-unsigned char codetable[] =
-{
- 0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F, 0x77, 0x7C,0x39,0x5E,0x79,0x71,0x00
-};
-
-// Public Methods //////////////////////////////////////////////////////////////
-/*
- * Function I2cInit
- * Desc TWI/I2C init
- * Input none
- * Output none
- */
-void ZtLib::I2cInit(void)
-{
- twi_init();
-}
-/*
- * Function Seg8b4a036aSleep
- * Desc Set ZT.SEG8B4A036A Go to Sleep
- * Input addr:ZT.SEG8B4A036A Address
- * Output 0 .. success
- * 1 .. length to long for buffer
- * 2 .. address send, NACK received
- * 3 .. data send, NACK received
- * 4 .. other twi error (lost bus arbitration, bus error, ..)
- */
-int ZtLib::Seg8b4a036aSleep(uint8_t addr)
-{
- uint8_t buff[5]={REG_SLEEP, SLEEP_ON, 0, 0, 0};
-
- return twi_writeTo(addr, buff, 5, 1, 1);
-}
-/*
- * Function Seg8b4a036aUnSleep
- * Desc Set ZT.SEG8B4A036A Wait Up From Sleep
- * Input addr:ZT.SEG8B4A036A Address
- * Output 0 .. success
- * 1 .. length to long for buffer
- * 2 .. address send, NACK received
- * 3 .. data send, NACK received
- * 4 .. other twi error (lost bus arbitration, bus error, ..)
- */
-int ZtLib::Seg8b4a036aUnSleep(uint8_t addr)
-{
- uint8_t buff[5]={REG_SLEEP, SLEEP_OFF, 0, 0, 0};
-
- return twi_writeTo(addr, buff, 5, 1, 1);
-}
-/*
- * Function Seg8b4a036aReadState
- * Desc Read ZT.SEG8B4A036A Status
- * Input addr:ZT.SEG8B4A036A Address
- * Output !=0xFF ZT.SC-I2CMx Status
- * 0xFF .. other twi error (lost bus arbitration, bus error, ..)
- */
-int ZtLib::Seg8b4a036aReadState(uint8_t addr)
-{
- uint8_t state = 0xFF;
- uint8_t temp;
- uint8_t buff[1] = {REG_STATUS};
- temp = twi_writeTo(addr, buff, 1, 1, 0); // no stop
- if (temp ==0)
- {
- temp = twi_readFrom(addr, buff, 1, 1);
- }
- if (temp==1)
- {
- state = buff[0];
- }
-
- return state;
-}
-/*
- * Function Seg8b4a036aReadVersion
- * Desc Read ZT.SEG8B4A036A Fireware Version
- * Input addr:ZT.SEG8B4A036A Address
- *buf:Version Buffer
- * Output .. number bytes of Version Read out
- */
-int ZtLib::Seg8b4a036aReadVersion(uint8_t addr, uint8_t *buf)
-{
- uint8_t state = 0xFF;
- uint8_t temp;
- uint8_t regv[1] = {REG_VERSION};
- temp = twi_writeTo(addr, regv, 1, 1, 0); // no stop
- if (temp ==0)
- {
- temp = twi_readFrom(addr, &(*buf), 19, 1);
- }
- return temp;
-}
-/*
- * Function Seg8b4a036aDisplayDec
- * Desc ZT.SEG8B4A036A Display decimal numeral
- * Input addr:ZT.SEG8B4A036A Address
- val: Display Val
- bitnum:Display Bit Number
- dotbit: Dot Display
- * Output 0 .. success
- * 1 .. length to long for buffer
- * 2 .. address send, NACK received
- * 3 .. data send, NACK received
- * 4 .. other twi error (lost bus arbitration, bus error, ..)
- */
-int ZtLib::Seg8b4a036aDisplayDec(uint8_t addr,unsigned short val, uint8_t bitnum, uint8_t dotbit)
-{
- uint8_t i;
- uint8_t segnum[5];
- if (val>9999) return 0xFF;
-
- segnum[0] = REG_DAT;
- segnum[1] = val%10;
- segnum[2] = (val%100)/10;
- segnum[3] = (val/100)%10;
- segnum[4] = val/1000;
- for (i=1; i<5; i++)
- {
- segnum[i] = codetable[segnum[i]];
- if (dotbit&0x01)
- {
- segnum[i] |= 0x80;
- }
- dotbit >>= 1;
- }
-
- if (bitnum==DISP_0BIT) {segnum[4] = 0;segnum[3] = 0;segnum[2] = 0;segnum[1] = 0;}
- else if (bitnum==DISP_1BIT) {segnum[4] = 0;segnum[3] = 0;segnum[2] = 0;}
- else if (bitnum==DISP_2BIT) {segnum[4] = 0;segnum[3] = 0;}
- else if (bitnum==DISP_3BIT) {segnum[4] = 0;}
- else if (bitnum==DISP_AUTO)
- {
- if (val<10) {segnum[4] = 0;segnum[3] = 0;segnum[2] = 0;}
- else if (val<100) {segnum[4] = 0;segnum[3] = 0;}
- else if (val<1000) {segnum[4] = 0;}
- }
-
- return twi_writeTo(addr, segnum, 5, 1, 1);
-}
-/*
- * Function Seg8b4a036aDisplayHex
- * Desc Read ZT.SEG8B4A036A Display hexadecimal number
- * Input addr:ZT.SEG8B4A036A Address
- val: Display Val
- bitnum:Display Bit Number
- dotbit: Dot Display
- * Output 0 .. success
- * 1 .. length to long for buffer
- * 2 .. address send, NACK received
- * 3 .. data send, NACK received
- * 4 .. other twi error (lost bus arbitration, bus error, ..)
- */
-int ZtLib::Seg8b4a036aDisplayHex(uint8_t addr,unsigned short val, uint8_t bitnum, uint8_t dotbit)
-{
- uint8_t i;
- unsigned short temp;
- uint8_t segnum[5];
- segnum[0] = REG_DAT;
- temp = val;
- for (i=1; i<5; i++)
- {
- segnum[i] = temp&0x000F;
- temp >>= 4;
- segnum[i] = codetable[segnum[i]];
- if (dotbit&0x01)
- {
- segnum[i] |= 0x80;
- }
- dotbit >>= 1;
- }
-
- if (bitnum==DISP_0BIT) {segnum[4] = 0;segnum[3] = 0;segnum[2] = 0;segnum[1] = 0;}
- else if (bitnum==DISP_1BIT) {segnum[4] = 0;segnum[3] = 0;segnum[2] = 0;}
- else if (bitnum==DISP_2BIT) {segnum[4] = 0;segnum[3] = 0;}
- else if (bitnum==DISP_3BIT) {segnum[4] = 0;}
- else if (bitnum==DISP_AUTO)
- {
- if (!(val&0xFFF0)) {segnum[4] = 0;segnum[3] = 0;segnum[2] = 0;}
- else if (!(val&0xFF00)) {segnum[4] = 0;segnum[3] = 0;}
- else if (!(val&0xF000)) {segnum[4] = 0;}
- }
-
- return twi_writeTo(addr, segnum, 5, 1, 1);
-}
-/*
- * Function Seg8b4a036aSetBrightness
- * Desc Set ZT.SEG8B4A036A Brightness
- * Input addr:ZT.SEG8B4A036A Address
- OnDelay:
- OffDelay:
- * Output 0 .. success
- * 1 .. length to long for buffer
- * 2 .. address send, NACK received
- * 3 .. data send, NACK received
- * 4 .. other twi error (lost bus arbitration, bus error, ..)
- */
-int ZtLib::Seg8b4a036aSetBrightness(uint8_t addr, uint8_t OnDelay, uint8_t OffDelay)
-{
- uint8_t buff[5] = {REG_BRIGHTNESS, OnDelay, OffDelay, 0, 0};
- return twi_writeTo(addr, buff, 5, 1, 1);
-}
-/*
- * Function Seg8b4a036aSetAddress
- * Desc Set ZT.SEG8B4A036A New Address
- * Input val:ZT.SEG8B4A036A Address New Address
- * Output 0 .. success
- * 1 .. length to long for buffer
- * 2 .. address send, NACK received
- * 3 .. data send, NACK received
- * 4 .. other twi error (lost bus arbitration, bus error, ..)
- */
-int ZtLib::Seg8b4a036aSetAddress(uint8_t val)
-{
- uint8_t buff[2] = {REG_ADDRESS, val};
- return twi_writeTo(ZTSEG8B4A036A_DADDR, buff, 2, 1, 1);
-}
-/*
- * Function Seg8b4a036aDisplayBuff
- * Desc Set ZT.SEG8B4A036A Brightness
- * Input addr:ZT.SEG8B4A036A Address
- *buf: Display buffer
- * Output 0 .. success
- * 1 .. length to long for buffer
- * 2 .. address send, NACK received
- * 3 .. data send, NACK received
- * 4 .. other twi error (lost bus arbitration, bus error, ..)
- */
-int ZtLib::Seg8b4a036aDisplayBuff(uint8_t addr,uint8_t *buf)
-{
- uint8_t buff[5]={REG_DAT, buf[0], buf[1], buf[2], buf[3]};
-
- return twi_writeTo(addr, buff, 5, 1, 1);
-}
-
-
-///ZT.ScI2cMx PART///-------------------------------------------------------------------
-/*
- * Function ScI2cMxReadState
- * Desc Read ZT.SC-I2CMx Status
- * Input addr:ZT.SC-I2CMx Address
- * Output !=0xFF ZT.SC-I2CMx Status
- * 0xFF .. other twi error (lost bus arbitration, bus error, ..)
- */
-int ZtLib::ScI2cMxReadState(uint8_t addr)
-{
- uint8_t state = 0xFF;
- uint8_t temp;
- uint8_t buff[1] = {REG_STATUS};
- temp = twi_writeTo(addr, buff, 1, 1, 0); // no stop
- if (temp ==0)
- {
- temp = twi_readFrom(addr, buff, 1, 1);
- }
- if (temp==1)
- {
- state = buff[0];
- }
-
- return state;
-}
-
-/*
- * Function ScI2cMxReadVersion
- * Desc Read ZT.SC-I2CMx Fireware Version
- * Input addr:ZT.SC-I2CMx Address
- *buf:Version Buffer
- * Output !=0xFF ZT.SC-I2CMx Status
- * othe .. number bytes of Version Read out
- */
-int ZtLib::ScI2cMxReadVersion(uint8_t addr, uint8_t *buf)
-{
- uint8_t state = 0xFF;
- uint8_t temp;
- uint8_t regv[1] = {REG_VERSION};
- temp = twi_writeTo(addr, regv, 1, 1, 0); // no stop
- if (temp ==0)
- {
- temp = twi_readFrom(addr, &(*buf), 16, 1);
- }
- return temp;
-}
-/*
- * Function ScI2cMxSetAddress
- * Desc Set ZT.SC-I2CMx New Address
- * Input val:ZT.SC-I2CMx Address New Address
- * Output 0 .. success
- * 1 .. length to long for buffer
- * 2 .. address send, NACK received
- * 3 .. data send, NACK received
- * 4 .. other twi error (lost bus arbitration, bus error, ..)
- */
-int ZtLib::ScI2cMxSetAddress(uint8_t newaddr)
-{
- uint8_t buff[2] = {REG_ADDRESS, newaddr};
- return twi_writeTo(ZTSCI2CMX_DADDRESS, buff, 2, 1, 1);
-}
-
-/*
- * Function ScI2cMxSetBrightness
- * Desc Set ZT.SC-I2CMx Brightness
- * Input addr:ZT.SC-I2CMx Address
- val: Brightness 0~0xFF
- * Output 0 .. success
- * 1 .. length to long for buffer
- * 2 .. address send, NACK received
- * 3 .. data send, NACK received
- * 4 .. other twi error (lost bus arbitration, bus error, ..)
- */
-int ZtLib::ScI2cMxSetBrightness(uint8_t addr, uint8_t val)
-{
- uint8_t buff[2] = {REG_BRIGHTNESS, val};
- return twi_writeTo(addr, buff, 2, 1, 1);
-}
-/*
- * Function ScI2cMxSetVcomH
- * Desc Set ZT.SC-I2CMx VcomH
- * Input addr:ZT.SC-I2CMx Address
- val: Brightness 0~7
- * Output 0 .. success
- * 1 .. length to long for buffer
- * 2 .. address send, NACK received
- * 3 .. data send, NACK received
- * 4 .. other twi error (lost bus arbitration, bus error, ..)
- */
-int ZtLib::ScI2cMxSetVcomH(uint8_t addr, uint8_t val)
-{
- uint8_t buff[2] = {REG_VCOMH, val};
- return twi_writeTo(addr, buff, 2, 1, 1);
-}
-
-/*
- * Function ScI2cMxDisplay8x16Str
- * Desc ZT.SC-I2CMx Display 8x16 English String
- * Input addr:ZT.SC-I2CMx Address
- page: location page
- column: location column
- *str: 8X16 English String
- * Output 0 .. success
- * 1 .. length to long for buffer
- * 2 .. address send, NACK received
- * 3 .. data send, NACK received
- * 4 .. other twi error (lost bus arbitration, bus error, ..)
- */
-int ZtLib::ScI2cMxDisplay8x16Str(uint8_t addr, uint8_t page, uint8_t column, const char *str)
-{
- uint8_t i=0;
- uint8_t buff[19];
- buff[0] = REG_8X16STR;
- buff[1] = page;
- buff[2] = column;
- i=0;
- while ((*str != '\0') && (i<16))
- {
- buff[i+3] = (uint8_t)*str++;
- i++;
- }
- return twi_writeTo(addr, buff, i+3, 1, 1);
-}
-/*
- * Function ScI2cMxFillArea
- * Desc ZT.SC-I2CMx Fill Area
- * Input addr:ZT.SC-I2CMx Address
- spage: start page
- epage: end page
- scolumn: start column
- ecolumn: end column
- filldata: fill data
- * Output 0 .. success
- * 1 .. length to long for buffer
- * 2 .. address send, NACK received
- * 3 .. data send, NACK received
- * 4 .. other twi error (lost bus arbitration, bus error, ..)
- */
-int ZtLib::ScI2cMxFillArea(uint8_t addr, uint8_t spage, uint8_t epage,uint8_t scolumn, uint8_t ecolumn,uint8_t filldata)
-{
- uint8_t buff[6] = {REG_FILL_AREA, spage, epage, scolumn, ecolumn, filldata};
- return twi_writeTo(addr, buff, 6, 1, 1);
-}
-/*
- * Function ScI2cMxScrollingHorizontal
- * Desc ZT.SC-I2CMx Scrolling Horizontal
- * Input addr:ZT.SC-I2CMx Address
- lr: Scroll direction
- spage: start page
- epage: end page
- frames: Scroll fram
- * Output 0 .. success
- * 1 .. length to long for buffer
- * 2 .. address send, NACK received
- * 3 .. data send, NACK received
- * 4 .. other twi error (lost bus arbitration, bus error, ..)
- */
-int ZtLib::ScI2cMxScrollingHorizontal(uint8_t addr, uint8_t lr, uint8_t spage, uint8_t epage,uint8_t frames)
-{
- uint8_t buff[9] = {REG_CMD, 0x2E, 0x00, spage, frames, epage, 0x00, 0xFF, 0x2F};
- twi_writeTo(addr, buff, 2, 1, 1);
- buff[0] = REG_CMD;
- buff[1] = lr;
- for (int i=0; i<10; i++);
- return twi_writeTo(addr, buff, 9, 1, 1);
-}
-/*
- * Function ScI2cMxScrollingHorizontal
- * Desc ZT.SC-I2CMx Scrolling Vertical
- * Input addr:ZT.SC-I2CMx Address
- lr: Scroll direction
- rowsfixed: rows fixed
- rowsscroll: rows scroll
- scrollstep: scroll step
- stepdelay: step delay
- * Output 0 .. success
- * 1 .. length to long for buffer
- * 2 .. address send, NACK received
- * 3 .. data send, NACK received
- * 4 .. other twi error (lost bus arbitration, bus error, ..)
- */
-int ZtLib::ScI2cMxScrollingVertical(uint8_t addr, uint8_t scrollupdown, uint8_t rowsfixed, uint8_t rowsscroll, uint8_t scrollstep, uint8_t stepdelay)
-{
- uint8_t buff[6] = {REG_SCROVER, scrollupdown, rowsfixed, rowsscroll, scrollstep, stepdelay};
- return twi_writeTo(addr, buff, 6, 1, 1);
-}
-/*
- * function ScI2cMxScrollingVerticalHorizontal
- * Desc Continuous Vertical / Horizontal / Diagonal Scrolling (Partial or Full Screen)
- * input :
- Sdirection: Scrolling Direction
- "0x00" (Vertical & Rightward)
- "0x01" (Vertical & Leftward)
- spage: Define Start Page Address (Horizontal / Diagonal Scrolling)
- epage: Define End Page Address (Horizontal / Diagonal Scrolling)
- fixedarea: Set Top Fixed Area (Vertical Scrolling)
- scrollarea: Set Vertical Scroll Area (Vertical Scrolling)
- frames: Set Time Interval between Each Scroll Step in Terms of Frame Frequency
- offset: Set Numbers of Row Scroll per Step (Vertical / Diagonal Scrolling)
- * Output 0 .. success
- * 1 .. length to long for buffer
- * 2 .. address send, NACK received
- * 3 .. data send, NACK received
- * 4 .. other twi error (lost bus arbitration, bus error, ..)
- */
-int ZtLib::ScI2cMxScrollingVerticalHorizontal(uint8_t addr, uint8_t Sdirection, uint8_t spage, uint8_t epage, uint8_t fixedarea, uint8_t scrollarea, uint8_t offset, uint8_t frames)
-{
- uint8_t buff[8] = {REG_SCROVERHOR, Sdirection, spage, epage, fixedarea, scrollarea, offset, frames};
- return twi_writeTo(addr, buff, 8, 1, 1);
-}
-/*
- * Function ScI2cMxDeactivateScroll
- * Desc ZT.SC-I2CMx Deactivate Scroll
- * Input addr:ZT.SC-I2CMx Address
- * Output 0 .. success
- * 1 .. length to long for buffer
- * 2 .. address send, NACK received
- * 3 .. data send, NACK received
- * 4 .. other twi error (lost bus arbitration, bus error, ..)
- */
-int ZtLib::ScI2cMxDeactivateScroll(uint8_t addr)
-{
- uint8_t buff[2] = {REG_CMD, 0x2E};
- return twi_writeTo(addr, buff, 2, 1, 1);
-}
-
-/*
- * Function ScI2cMxReset
- * Desc ZT.SC-I2CMx Reset OLED
- * Input addr:ZT.SC-I2CMx Address
- * Output 0 .. success
- * 1 .. length to long for buffer
- * 2 .. address send, NACK received
- * 3 .. data send, NACK received
- * 4 .. other twi error (lost bus arbitration, bus error, ..)
- */
-int ZtLib::ScI2cMxReset(uint8_t addr)
-{
- uint8_t buff[2] = {REG_RESET,RESET_OLED};
- return twi_writeTo(addr, buff, 2, 1, 1);
-}
-
-/*
- * Function ScI2cMxSetLocation
- * Desc Set ZT.SC-I2CMx SetLocation
- * Input addr:ZT.SC-I2CMx Address
- * Output 0 .. success
- * 1 .. length to long for buffer
- * 2 .. address send, NACK received
- * 3 .. data send, NACK received
- * 4 .. other twi error (lost bus arbitration, bus error, ..)
- */
-int ZtLib::ScI2cMxSetLocation(uint8_t addr, uint8_t page,uint8_t column)
-{
- uint8_t buff[4] = {REG_CMD, (0xB0|page), (column%16), (column/16+0x10)};
- return twi_writeTo(addr, buff, 4, 1, 1);
-}
-/*
- * Function ScI2cMxDisplayDot16x16
- * Desc Set ZT.SC-I2CMx Display 16*16 Dot
- * Input addr:ZT.SC-I2CMx Address
- page:page
- column:column
- *str:16*16 Dot Data
- * Output 0 .. success
- * 1 .. length to long for buffer
- * 2 .. address send, NACK received
- * 3 .. data send, NACK received
- * 4 .. other twi error (lost bus arbitration, bus error, ..)
- */
-void ZtLib::ScI2cMxDisplayDot16x16(uint8_t addr, uint8_t page, uint8_t column, const char *str)
-{
- uint8_t buff[17];
- buff[0] = REG_DAT;
- ScI2cMxSetLocation(addr, page, column);
- for (int i=0; i<16; i++)
- {
- buff[i+1] = str[i];
- }
- twi_writeTo(addr, buff, 17, 1, 1);
- ScI2cMxSetLocation(addr, page+1, column);
- for (int i=0; i<16; i++)
- {
- buff[i+1] = str[i+16];
- }
- twi_writeTo(addr, buff, 17, 1, 1);
-}
-/*
- * Function ScI2cMxDisplayArea
- * Desc Set ZT.SC-I2CMx Display Area
- * Input addr:ZT.SC-I2CMx Address
- spage: start page
- epage: end page
- scolumn: start column
- ecolumn: end column
- *pt: Data
- * Output 0 .. success
- * 1 .. length to long for buffer
- * 2 .. address send, NACK received
- * 3 .. data send, NACK received
- * 4 .. other twi error (lost bus arbitration, bus error, ..)
- */
-void ZtLib::ScI2cMxDisplayArea(uint8_t addr, uint8_t spage, uint8_t epage, uint8_t scolumn, uint8_t ecolumn, const char *pt)
-{
- uint8_t i = 0;
- uint8_t j = 0;
- uint8_t h = 0;
- uint8_t w = 0;
- uint16_t cnt = 0;
- uint8_t buff[32];
- buff[0] = REG_DAT;
-
- h = epage - spage;
- w = ecolumn - scolumn;
-
- while ( j<h )
- {
- ScI2cMxSetLocation(addr, spage + j, scolumn);
- uint8_t p=w;
- while(p)
- {
- if(p>=31)
- {
- for (int n=0; n<31; n++)
- {
- buff[1+n] = pt[cnt++];
- }
- twi_writeTo(addr, buff, 32, 1, 1);
- p -= 31;
- }
- else
- {
- int n;
- for (n=0; n<p; n++)
- {
- buff[1+n] = pt[cnt++];
- }
- twi_writeTo(addr, buff, n+1, 1, 1);
- p -= n;
- }
- }
- j++;
- }
-}
-
-// Preinstantiate Objects //////////////////////////////////////////////////////
-
diff --git a/obdlogger/ZtLib.h b/obdlogger/ZtLib.h
deleted file mode 100644
index b93ccc1..0000000
--- a/obdlogger/ZtLib.h
+++ /dev/null
@@ -1,127 +0,0 @@
-/*
- ZtLib.cpp - ZT module Drive Library for Wiring & Arduino
- Copyright (c) 2012 Alvin Li(Kozig/www.kozig.com). All right reserved.
- This library is free software;
- This library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- Version:V1.1
-*/
-
-#ifndef __ZTLIB_H__
-#define __ZTLIB_H__
-
-#include <inttypes.h>
-
-//////////////////
-#define ZTSEG8B4A036A_DADDR 0x51
-#define SET_ADDR 0x61
-#define WRITE_CODE 0xAA
-#define WRITE_CMD 0x55
-
-#define DOT_NONE (0)
-#define DOT_BIT1 (1<<0)
-#define DOT_BIT2 (1<<1)
-#define DOT_BIT3 (1<<2)
-#define DOT_BIT4 (1<<3)
-
-#define DISP_0BIT (0)
-#define DISP_1BIT (1)
-#define DISP_2BIT (2)
-#define DISP_3BIT (3)
-#define DISP_4BIT (4)
-#define DISP_AUTO (5)
-///////////////////////////////////
-
-#define ZTSCI2CMX_DADDRESS 0x51
-// Ä£¿é¼Ä´æÆ÷µØÖ·
-#define REG_CMD 0x01
-#define REG_DAT 0x02
-#define REG_RESET 0x03
- #define RESET_OLED 0x06
-#define REG_VERSION 0x1F
-#define REG_SLEEP 0x04
- #define SLEEP_ON 0xA5
- #define SLEEP_OFF 0xA1
-#define REG_VCOMH 0x05
-#define REG_STATUS 0x06
- #define STATUS_RUN 0x00
- #define STATUS_RUN 0x00
- #define STATUS_SLEEP 0x01
- #define STATUS_SET_ADDRESS 0x02
- #define STATUS_TEST 0x04
- #define STATUS_BUSY 0x10
-
-#define REG_ADDRESS 0x08
-#define REG_BRIGHTNESS 0x0A
-#define REG_8X16STR 0x52
-#define REG_OLED_XY 0x60
-#define REG_FILL_AREA 0x61
-#define REG_SCROHOR 0x62
-#define REG_SCROVER 0x63
-#define REG_SCROVERHOR 0x64
-
-#define PAGE0 0x00
-#define PAGE1 0x01
-#define PAGE2 0x02
-#define PAGE3 0x03
-#define PAGE4 0x04
-#define PAGE5 0x05
-#define PAGE6 0x06
-#define PAGE7 0x07
-
-#define SCROLL_UP 0x01
-#define SCROLL_DOWN 0x00
-#define SCROLL_RIGHT 0x26
-#define SCROLL_LEFT 0x27
-#define SCROLL_VR 0x29
-#define SCROLL_VL 0x2A
-
-#define FRAMS_2 0x07
-#define FRAMS_3 0x04
-#define FRAMS_4 0x05
-#define FRAMS_5 0x00
-#define FRAMS_25 0x06
-#define FRAMS_64 0x01
-#define FRAMS_128 0x02
-#define FRAMS_256 0x03
-
-class ZtLib
-{
- private:
-
- public:
- void I2cInit(void);
-// Module ZT.SEG8B4A036A FUNCTION
- int Seg8b4a036aSleep(uint8_t);
- int Seg8b4a036aUnSleep(uint8_t);
- int Seg8b4a036aReadState(uint8_t addr);
- int Seg8b4a036aReadVersion(uint8_t addr, uint8_t *buf);
- int Seg8b4a036aDisplayDec(uint8_t,unsigned short, uint8_t, uint8_t);
- int Seg8b4a036aDisplayHex(uint8_t,unsigned short, uint8_t, uint8_t);
- int Seg8b4a036aSetBrightness(uint8_t, uint8_t, uint8_t);
- int Seg8b4a036aSetAddress(uint8_t);
- int Seg8b4a036aDisplayBuff(uint8_t,uint8_t *);
-// Module ZT.SC-I2CMx
- int ScI2cMxReadState(uint8_t);
- int ScI2cMxReadVersion(uint8_t, uint8_t *);
- int ScI2cMxSetAddress(uint8_t);
- int ScI2cMxSetBrightness(uint8_t, uint8_t);
- int ScI2cMxSetVcomH(uint8_t, uint8_t);
- int ScI2cMxDisplay8x16Str(uint8_t, uint8_t, uint8_t, const char *);
- int ScI2cMxFillArea(uint8_t, uint8_t, uint8_t,uint8_t, uint8_t,uint8_t);
- int ScI2cMxScrollingHorizontal(uint8_t, uint8_t, uint8_t, uint8_t,uint8_t);
- int ScI2cMxScrollingVertical(uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t);
- int ScI2cMxScrollingVerticalHorizontal(uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t);
- int ScI2cMxDeactivateScroll(uint8_t);
- int ScI2cMxReset(uint8_t);
- int ScI2cMxSetLocation(uint8_t, uint8_t, uint8_t);
- void ScI2cMxDisplayDot16x16(uint8_t, uint8_t, uint8_t, const char *);
- void ScI2cMxDisplayArea(uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, const char *);
-};
-
-
-extern ZtLib ZT;
-
-#endif
-
diff --git a/obdlogger/images.h b/obdlogger/images.h
new file mode 100644
index 0000000..2f92ee1
--- /dev/null
+++ b/obdlogger/images.h
@@ -0,0 +1,5 @@
+static const PROGMEM uint8_t tick[16 *16 / 8] =
+{0x00,0x80,0xC0,0xE0,0xC0,0x80,0x00,0x80,0xC0,0xE0,0xF0,0xF8,0xFC,0x78,0x30,0x00,0x00,0x01,0x03,0x07,0x0F,0x1F,0x1F,0x1F,0x0F,0x07,0x03,0x01,0x00,0x00,0x00,0x00};
+
+static const PROGMEM uint8_t cross[16 *16 / 8] =
+{0x00,0x0C,0x1C,0x3C,0x78,0xF0,0xE0,0xC0,0xE0,0xF0,0x78,0x3C,0x1C,0x0C,0x00,0x00,0x00,0x30,0x38,0x3C,0x1E,0x0F,0x07,0x03,0x07,0x0F,0x1E,0x3C,0x38,0x30,0x00,0x00};
diff --git a/obdlogger/obdlogger.cbp b/obdlogger/obdlogger.cbp
index 909ed27..91b4fe8 100644
--- a/obdlogger/obdlogger.cbp
+++ b/obdlogger/obdlogger.cbp
@@ -447,7 +447,7 @@
<Option type="1" />
<Option compiler="avrgcc" />
<Compiler>
- <Add option="-O2" />
+ <Add option="-O3" />
<Add option="-x c++" />
<Add option="-mmcu=$(MCU)" />
<Add option="-DF_CPU=16000000L" />
@@ -582,20 +582,6 @@
<Compiler>
<Add directory="." />
</Compiler>
- <Unit filename="LCD4Bit_mod.cpp" />
- <Unit filename="LCD4Bit_mod.h" />
- <Unit filename="MPU6050.cpp" />
- <Unit filename="MPU6050.h" />
- <Unit filename="MultiLCD.cpp" />
- <Unit filename="MultiLCD.h" />
- <Unit filename="OBD.cpp" />
- <Unit filename="OBD.h" />
- <Unit filename="PCD8544.cpp" />
- <Unit filename="PCD8544.h" />
- <Unit filename="TinyGPS.cpp" />
- <Unit filename="TinyGPS.h" />
- <Unit filename="ZtLib.cpp" />
- <Unit filename="ZtLib.h" />
<Unit filename="obdlogger.ino">
<Option compile="1" />
<Option link="1" />
diff --git a/obdlogger/obdlogger.ino b/obdlogger/obdlogger.ino
index 0e62cd0..4b81f8b 100644
--- a/obdlogger/obdlogger.ino
+++ b/obdlogger/obdlogger.ino
@@ -9,16 +9,17 @@
#include <Wire.h>
#include "OBD.h"
#include "SD.h"
-#include "Multilcd.h"
+#include "MultiLCD.h"
#include "TinyGPS.h"
#include "MPU6050.h"
+#include "images.h"
/**************************************
* Choose SD pin here
**************************************/
//#define SD_CS_PIN 4 // ethernet shield
-#define SD_CS_PIN 7 // microduino
-//#define SD_CS_PIN 10 // SD breakout
+//#define SD_CS_PIN 7 // microduino
+#define SD_CS_PIN 10 // SD breakout
/**************************************
* Config GPS here
@@ -30,7 +31,8 @@
/**************************************
* Choose LCD model here
**************************************/
-#define USE_OLED
+#define USE_SSD1306
+//#define USE_ZTOLED
//#define USE_LCD1602
//#define USE_LCD4884
@@ -38,10 +40,8 @@
* Other options
**************************************/
#define USE_MPU6050
-#define OBD_MIN_INTERVAL 100 /* ms */
+#define OBD_MIN_INTERVAL 50 /* ms */
#define GPS_DATA_TIMEOUT 2000 /* ms */
-//#define CONSOLE Serial
-//#define FAKE_OBD_DATA
// logger states
#define STATE_SD_READY 0x1
@@ -88,15 +88,22 @@ SdVolume volume;
File sdfile;
// enable one LCD
-#if defined(USE_OLED)
-LCD_OLED lcd; /* for I2C OLED module */
+#if defined(USE_ZTOLED)
+LCD_ZTOLED lcd; /* for ZT OLED module */
#define LCD_LINES 4
+#define CHAR_WIDTH 6
+#elif defined(USE_SSD1306)
+LCD_SSD1306 lcd; /* for SSD1306 OLED module */
+#define LCD_LINES 8
+#define CHAR_WIDTH 6
#elif defined(USE_LCD1602)
LCD_1602 lcd; /* for LCD1602 shield */
#define LCD_LINES 2
+#define CHAR_WIDTH 1
#elif defined(USE_LCD4884)
LCD_PCD8544 lcd; /* for LCD4884 shield or Nokia 5100 screen module */
#define LCD_LINES 5
+#define CHAR_WIDTH 6
#endif
static uint32_t fileSize = 0;
@@ -106,6 +113,11 @@ static uint32_t lastGPSDataTime = 0;
static uint16_t lastSpeed = -1;
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 CLogger : public COBD
{
@@ -113,6 +125,8 @@ public:
CLogger():state(0) {}
void Setup()
{
+ lastGPSDataTime = 0;
+
ShowStates();
#ifdef USE_MPU6050
@@ -127,33 +141,28 @@ public:
state |= STATE_GPS_CONNECTED;
break;
}
- } while (millis() - t <= 1000);
+ } while (millis() - t <= 2000);
#endif
-#ifndef FAKE_OBD_DATA
do {
ShowStates();
} while (!Init());
-#endif
state |= STATE_OBD_READY;
ShowStates();
- delay(500);
ShowPidsInfo();
+ delay(3000);
-#ifndef FAKE_OBD_DATA
ReadSensor(PID_DISTANCE, startDistance);
-#endif
// open file for logging
if (!(state & STATE_SD_READY)) {
- do {
- delay(1000);
- } while (!CheckSD());
- state |= STATE_SD_READY;
- ShowStates();
+ if (CheckSD()) {
+ state |= STATE_SD_READY;
+ ShowStates();
+ }
}
fileSize = 0;
@@ -161,9 +170,6 @@ public:
sprintf(filename, FILE_NAME_FORMAT, fileIndex);
sdfile = SD.open(filename, FILE_WRITE);
if (!sdfile) {
- lcd.setCursor(0, 0);
- lcd.print("File Error");
- delay(3000);
}
InitScreen();
@@ -175,15 +181,18 @@ public:
LogData(PID_RPM);
+#ifdef GPSUART
if (millis() - lastGPSDataTime > GPS_DATA_TIMEOUT || gps.satellites() < 3) {
// GPS not ready
state &= ~STATE_GPS_READY;
- LogData(PID_SPEED);
} else {
// GPS ready
state |= STATE_GPS_READY;
}
-
+ LogData(PID_SPEED);
+#else
+ LogData(PID_SPEED);
+#endif
LogData(PID_THROTTLE);
if (state & STATE_ACC_READY) {
@@ -213,6 +222,7 @@ public:
bool CheckSD()
{
lcd.setCursor(0, 0);
+ lcd.setFont(FONT_SIZE_MEDIUM);
state &= ~STATE_SD_READY;
pinMode(SS, OUTPUT);
if (card.init(SPI_HALF_SPEED, SD_CS_PIN)) {
@@ -250,12 +260,13 @@ public:
lcd.print(buf);
} else {
lcd.clear();
- lcd.print("No SD Card ");
+ lcd.print("SD");
+ lcd.draw(cross, 32, 0, 16, 16);
return false;
}
if (!SD.begin(SD_CS_PIN)) {
- lcd.setCursor(8, 0);
+ lcd.setCursor(8 * CHAR_WIDTH, 0);
lcd.print("Bad SD");
return false;
}
@@ -269,7 +280,7 @@ public:
}
}
if (!fileIndex) {
- lcd.setCursor(8, 8);
+ lcd.setCursor(8 * CHAR_WIDTH, 8);
lcd.print("Bad File");
return false;
}
@@ -277,7 +288,8 @@ public:
filename[2] = '[';
filename[8] = ']';
filename[9] = 0;
- lcd.setCursor(9, 0);
+ lcd.setCursor(127 - 7 * CHAR_WIDTH, 0);
+ lcd.setFont(FONT_SIZE_SMALL);
lcd.print(filename + 2);
state |= STATE_SD_READY;
return true;
@@ -286,50 +298,62 @@ private:
void InitIdleLoop()
{
// called while initializing
+ char buf[10];
+ unsigned int t = (millis() - startTime) / 1000;
+ sprintf(buf, "%02u:%02u", t / 60, t % 60);
+ lcd.setFont(FONT_SIZE_SMALL);
+ lcd.setCursor(97, 7);
+ lcd.print(buf);
#ifdef GPSUART
// detect GPS signal
- if (GPSUART.available()) {
- char c = GPSUART.read();
- if (gps.encode(c)) {
- state |= STATE_GPS_READY;
- lastGPSDataTime = millis();
-#ifdef CONSOLE
- unsigned long date, time;
- gps.get_datetime(&date, &time, 0);
- long lat, lon;
- gps.get_position(&lat, &lon, 0);
- CONSOLE.print("Time:");
- CONSOLE.print(time);
- CONSOLE.print(" LAT:");
- CONSOLE.print(lat);
- CONSOLE.print(" LON:");
- CONSOLE.println(lon);
- } else if (!(state & STATE_GPS_READY)) {
- CONSOLE.write(c);
-#endif
- }
+ ProcessGPS();
+ if (lastGPSDataTime) {
+ state |= STATE_GPS_READY;
}
+#endif
#ifdef USE_MPU6050
if (state & STATE_ACC_READY) {
accel_t_gyro_union data;
MPU6050_readout(&data);
char buf[8];
- sprintf(buf, "X:%4d", data.value.x_accel / 190);
- lcd.setCursor(10, 1);
- lcd.print(buf);
+ lcd.setFont(FONT_SIZE_SMALL);
#if LCD_LINES > 2
- sprintf(buf, "Y:%4d", data.value.y_accel / 190);
- lcd.setCursor(10, 2);
+ int temp = (data.value.temperature + 12412) / 340;
+ sprintf(buf, "TEMP%3dC", temp);
+ lcd.setCursor(80, 2);
lcd.print(buf);
- sprintf(buf, "Z:%4d", data.value.z_accel / 190);
- lcd.setCursor(10, 3);
+
+ sprintf(buf, "AX%3d", data.value.x_accel / 160);
+ lcd.setCursor(98, 3);
+ lcd.print(buf);
+ sprintf(buf, "AY%3d", data.value.y_accel / 160);
+ lcd.setCursor(98, 4);
+ lcd.print(buf);
+ sprintf(buf, "AZ%3d", data.value.z_accel / 160);
+ lcd.setCursor(98, 5);
+ lcd.print(buf);
+
+ sprintf(buf, "GX%3d", data.value.x_gyro >> 10);
+ lcd.setCursor(66, 3);
+ lcd.print(buf);
+ sprintf(buf, "GY%3d", data.value.y_gyro >> 10);
+ lcd.setCursor(66, 4);
+ lcd.print(buf);
+ sprintf(buf, "GZ%3d", data.value.z_gyro >> 10);
+ lcd.setCursor(66, 5);
+ lcd.print(buf);
+
+#else
+ sprintf(buf, "X:%3d", data.value.x_accel / 160);
+ lcd.setFont(FONT_SIZE_SMALL);
+ lcd.setCursor(10 * CHAR_WIDTH, 1);
lcd.print(buf);
#endif
- delay(100);
+ delay(50);
}
#endif
-#endif
}
+#ifdef GPSUART
void DataIdleLoop()
{
if (GPSUART.available())
@@ -349,7 +373,7 @@ private:
char buf[32];
unsigned long date, time;
gps.get_datetime(&date, &time, 0);
- len = sprintf(buf, "%u,F0,%ld %ld\n", elapsed, date, time);
+ len = sprintf(buf, "%u,F0,%06ld %08ld\n", elapsed, date, time);
sdfile.write((uint8_t*)buf, len);
unsigned int speed = (unsigned int)(gps.speed() * 1852 / 100 / 1000);
@@ -358,7 +382,7 @@ private:
// that's when previous speed is zero and current speed is also zero
if (!(speed == 0 && lastSpeed == 0) && gps.satellites() >= 3) {
// lastSpeed will be updated
- ShowSensorData(PID_SPEED, speed);
+ //ShowSensorData(PID_SPEED, speed);
len = sprintf(buf, "%u,F1,%u\n", elapsed, speed);
sdfile.write((uint8_t*)buf, len);
@@ -367,24 +391,40 @@ private:
len = sprintf(buf, "%u,F2,%ld %ld\n", elapsed, lat, lon);
sdfile.write((uint8_t*)buf, len);
- // display LAT/LON if screen is big enough
+ len = sprintf(buf, "%u,F3,%ld\n", elapsed, gps.altitude());
+ sdfile.write((uint8_t*)buf, len);
+
+ lcd.setFont(FONT_SIZE_SMALL);
+#if LCD_LINES > 2
+ if (((unsigned int)dataTime / 3000) & 1) {
+ sprintf(buf, "LAT:%d.%ld ", (int)(lat / 100000), lat % 100000);
+ lcd.setCursor(0, 6);
+ lcd.print(buf);
+ sprintf(buf, "LON:%d.%ld ", (int)(lon / 100000), lon % 100000);
+ lcd.setCursor(0, 7);
+ lcd.print(buf);
+ } else {
+ lcd.setCursor(0, 6);
+ sprintf(buf, "ALT:%um SAT:%u", (unsigned int)(gps.altitude() / 100), (unsigned int)gps.satellites());
+ lcd.print(buf);
+ lcd.setCursor(0, 7);
+ sprintf(buf, "TIME:%08ld ", time);
+ lcd.print(buf);
+ }
+#else
if (((unsigned int)dataTime / 1000) & 1)
sprintf(buf, "%d.%ld ", (int)(lat / 100000), lat % 100000);
else
sprintf(buf, "%d.%ld ", (int)(lon / 100000), lon % 100000);
-#if LCD_LINES > 2
- lcd.setCursor(0, 3);
-#else
lcd.setCursor(0, 1);
-#endif
lcd.print(buf);
+#endif
- len = sprintf(buf, "%u,F3,%ld\n", elapsed, gps.altitude());
- sdfile.write((uint8_t*)buf, len);
}
lastDataTime = dataTime;
lastGPSDataTime = dataTime;
}
+#endif
void ProcessAccelerometer()
{
#ifdef USE_MPU6050
@@ -414,7 +454,6 @@ private:
int value;
uint32_t start = millis();
-#ifndef FAKE_OBD_DATA
// send a query to OBD adapter for specified OBD-II pid
Query(pid);
// wait for reponse
@@ -428,6 +467,9 @@ private:
return;
}
+ // display data while waiting for OBD response
+ ShowSensorData(lastPID, lastData);
+
// get response from OBD adapter
pid = 0;
char* data = GetResponse(pid, buffer);
@@ -442,8 +484,8 @@ private:
// convert raw data to normal value
value = GetConvertedValue(pid, data);
- // display data on screen
- ShowSensorData(pid, value);
+ lastPID = pid;
+ lastData = value;
// log data to SD card
char buf[32];
@@ -460,73 +502,44 @@ private:
// display logged data size
char buf[7];
sprintf(buf, "%4uKB", (int)(fileSize >> 10));
- lcd.setCursor(10, 3);
+ lcd.setFont(FONT_SIZE_SMALL);
+ lcd.setCursor(92, 7);
lcd.print(buf);
lastFileSize = fileSize;
}
-#else
- switch (pid) {
- case PID_RPM:
- value = 600 + (start / 10) % 6400;
- break;
- case PID_SPEED:
- value = (start / 200) % 220;
- break;
- case PID_THROTTLE:
- value = (start / 100) % 100;
- break;
- case PID_DISTANCE:
- value = start / 60000;
- break;
- default:
- value = 0;
- }
- lastDataTime = millis();
- // display data on screen
- ShowSensorData(pid, value);
-#endif
+
// if OBD response is very fast, go on processing other data for a while
+#ifdef OBD_MIN_INTERVAL
while (millis() - start < OBD_MIN_INTERVAL) {
DataIdleLoop();
}
+#endif
}
void ShowPidsInfo()
{
- char buffer[16];
+ char buffer[24];
+ byte pidlist[] = {PID_RPM, PID_SPEED, PID_THROTTLE, PID_ENGINE_LOAD, PID_ABS_ENGINE_LOAD, PID_MAF_FLOW, PID_INTAKE_MAP, PID_FUEL_LEVEL, PID_FUEL_PRESSURE, PID_COOLANT_TEMP, PID_INTAKE_TEMP, PID_AMBIENT_TEMP, PID_TIMING_ADVANCE, PID_BAROMETRIC};
+ const char* namelist[] = {"RPM", "SPEED", "THROTTLE", "ENG.LOAD1", "ENG.LOAD2", "MAF", "MAP", "FUEL LV.", "FUEL PRE.", "COOLANT", "INTAKE","AMBIENT", "IGNITION", "BARO"};
+ byte i = 0;
lcd.clear();
- sprintf(buffer, "RPM:%c", IsValidPID(PID_RPM) ? 'Y' : 'N');
- lcd.print(buffer);
- lcd.setCursor(7, 0);
- sprintf(buffer, "SPD:%c", IsValidPID(PID_SPEED) ? 'Y' : 'N');
- lcd.print(buffer);
-
- lcd.setCursor(0, 1);
- sprintf(buffer, "THR:%c", IsValidPID(PID_THROTTLE) ? 'Y' : 'N');
- lcd.print(buffer);
- lcd.setCursor(7, 1);
- sprintf(buffer, "LOD:%c", IsValidPID(PID_ENGINE_LOAD) ? 'Y' : 'N');
- lcd.print(buffer);
-
- lcd.setCursor(0, 2);
- sprintf(buffer, "MAF:%c", IsValidPID(PID_MAF_FLOW) ? 'Y' : 'N');
- lcd.print(buffer);
- lcd.setCursor(7, 2);
- sprintf(buffer, "MAP:%c", IsValidPID(PID_INTAKE_MAP) ? 'Y' : 'N');
- lcd.print(buffer);
-
- lcd.setCursor(0, 3);
- sprintf(buffer, "FLV:%c", IsValidPID(PID_FUEL_LEVEL) ? 'Y' : 'N');
- lcd.print(buffer);
- lcd.setCursor(7, 3);
- sprintf(buffer, "FPR:%c", IsValidPID(PID_FUEL_PRESSURE) ? 'Y' : 'N');
- lcd.print(buffer);
- delay(3000);
+ lcd.setFont(FONT_SIZE_SMALL);
+ for (; i < sizeof(pidlist) / sizeof(pidlist[0]) / 2; i++) {
+ lcd.setCursor(0, i);
+ sprintf(buffer, "%s:%c", namelist[i], IsValidPID(PID_RPM) ? '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], IsValidPID(PID_RPM) ? 'Y' : 'N');
+ lcd.print(buffer);
+ }
}
void Reconnect()
{
sdfile.close();
lcd.clear();
- lcd.print("Reconnecting...");
+ lcd.setFont(FONT_SIZE_MEDIUM);
+ lcd.print("Reconnecting");
state &= ~(STATE_OBD_READY | STATE_ACC_READY | STATE_DATE_SAVED);
//digitalWrite(SD_CS_PIN, LOW);
for (int i = 0; !Init(); i++) {
@@ -540,21 +553,19 @@ private:
// screen layout related stuff
void ShowStates()
{
- lcd.setCursor(0, 1);
- lcd.print("GPS:");
- if (state & STATE_GPS_READY)
- lcd.print("Yes");
- else if (state & STATE_GPS_CONNECTED)
- lcd.print("--");
- else
- lcd.print("No");
-#if LCD_LINES > 2
+ lcd.setFont(FONT_SIZE_MEDIUM);
lcd.setCursor(0, 2);
- lcd.print("ACC:");
- lcd.print((state & STATE_ACC_READY) ? "Yes" : "No");
- lcd.setCursor(0, 3);
- lcd.print("OBD:");
- lcd.print((state & STATE_OBD_READY) ? "Yes" : "No");
+ lcd.print("OBD");
+ lcd.draw((state & STATE_OBD_READY) ? tick : cross, 32, 16, 16, 16);
+#if LCD_LINES > 2
+ lcd.setCursor(0, 4);
+ lcd.print("ACC");
+ lcd.draw((state & STATE_ACC_READY) ? tick : cross, 32, 32, 16, 16);
+ lcd.setCursor(0, 6);
+ if (!(state & STATE_GPS_READY)) {
+ lcd.print("GPS");
+ lcd.draw((state & STATE_GPS_CONNECTED) ? tick : cross, 32, 48, 16, 16);
+ }
#endif
}
virtual void ShowSensorData(byte pid, int value)
@@ -562,32 +573,38 @@ private:
char buf[8];
switch (pid) {
case PID_RPM:
- sprintf(buf, "%4u", (unsigned int)value % 10000);
#if LCD_LINES <= 2
lcd.setCursor(8, 0);
#else
- lcd.setCursor(4, 2);
+ lcd.setCursor(64, 0);
#endif
- lcd.print(buf);
+ lcd.setFont(FONT_SIZE_XLARGE);
+ lcd.printInt((unsigned int)value % 10000, 4);
break;
case PID_SPEED:
if (lastSpeed != value) {
- sprintf(buf, "%3u", (unsigned int)value % 1000);
lcd.setCursor(0, 0);
- lcd.printLarge(buf);
+ lcd.setFont(FONT_SIZE_XLARGE);
+ lcd.printInt((unsigned int)value % 1000, 3);
lastSpeed = value;
}
break;
#if LCD_LINES > 2
case PID_THROTTLE:
- sprintf(buf, "%2d", value % 100);
- lcd.setCursor(13, 2);
- lcd.print(buf);
+ lcd.setCursor(24, 4);
+ lcd.setFont(FONT_SIZE_MEDIUM);
+ lcd.printInt(value % 100, 3);
+ break;
+ case PID_INTAKE_TEMP:
+ lcd.setCursor(96, 4);
+ lcd.setFont(FONT_SIZE_MEDIUM);
+ lcd.printInt(value, 3);
break;
case PID_DISTANCE:
if ((unsigned int)value >= startDistance) {
sprintf(buf, "%4ukm", ((unsigned int)value - startDistance) % 1000);
- lcd.setCursor(10, 0);
+ lcd.setFont(FONT_SIZE_SMALL);
+ lcd.setCursor(92, 6);
lcd.print(buf);
}
break;
@@ -599,23 +616,24 @@ private:
byte n;
/* 0~1.5g -> 0~8 */
g /= 85 * 25;
- lcd.setCursor(0, 1);
+ lcd.setFont(FONT_SIZE_SMALL);
+ lcd.setCursor(0, 3);
if (g == 0) {
lcd.clearLine(1);
- } else if (g < 0 && g >= -8) {
- for (n = 0; n < 8 + g; n++) {
+ } else if (g < 0 && g >= -10) {
+ for (n = 0; n < 10 + g; n++) {
lcd.write(' ');
}
- for (; n < 8; n++) {
+ for (; n < 10; n++) {
lcd.write('<');
}
lcd.print(" ");
- } else if (g > 0 && g < 8) {
+ } else if (g > 0 && g < 10) {
lcd.print(" ");
for (n = 0; n < g; n++) {
lcd.write('>');
}
- for (; n < 8; n++) {
+ for (; n < 10; n++) {
lcd.write(' ');
}
}
@@ -624,20 +642,25 @@ private:
{
lcd.clear();
lcd.backlight(true);
+ lcd.setFont(FONT_SIZE_SMALL);
#if LCD_LINES <= 2
lcd.setCursor(4, 0);
+ lcd.print("kph");
#else
- lcd.setCursor(6, 0);
+ lcd.setCursor(24, 2);
+ lcd.print("km/h");
#endif
- lcd.print("kph");
#if LCD_LINES <= 2
lcd.setCursor(13, 0);
lcd.print("rpm");
#else
- lcd.setCursor(0, 2);
- lcd.print("RPM:");
- lcd.setCursor(9, 2);
- lcd.print("THR: %");
+ lcd.setCursor(110, 2);
+ lcd.print("rpm");
+ lcd.setCursor(0, 5);
+ lcd.setCursor(0, 4);
+ lcd.print("THR: %");
+ lcd.setCursor(73, 4);
+ lcd.print("AIR: C");
#endif
}
};
@@ -652,32 +675,26 @@ void setup()
lcd.print("OBD/GPS Logger");
lcd.setCursor(0, 1);
lcd.print("Initializing...");
- lcd.setCursor(0, 1);
-#if defined(USE_OLED)
- // for I2C OLED
- Wire.begin();
-#endif
-
-#ifdef CONSOLE
- CONSOLE.begin(115200);
-#endif
// start serial communication at the adapter defined baudrate
OBDUART.begin(OBD_SERIAL_BAUDRATE);
#ifdef GPSUART
#ifdef GPS_OPEN_BAUDRATE
GPSUART.begin(GPS_OPEN_BAUDRATE);
+ delay(10);
GPSUART.println(PMTK_SET_BAUDRATE);
GPSUART.end();
#endif
GPSUART.begin(GPS_BAUDRATE);
// switching to 10Hz mode, effective only for MTK3329
//GPSUART.println(PMTK_SET_NMEA_OUTPUT_ALLDATA);
- GPSUART.println(PMTK_SET_NMEA_UPDATE_10HZ);
+ //GPSUART.println(PMTK_SET_NMEA_UPDATE_5HZ);
#endif
delay(500);
+ //lcd.setColor(0x7FF);
+ lcd.setCursor(0, 2);
logger.CheckSD();
logger.Setup();
}