From f99f21926e515cf93e2af35eb82808f337998738 Mon Sep 17 00:00:00 2001 From: Stanley Huang Date: Mon, 10 Jun 2013 13:21:54 +0800 Subject: update OBD logger --- obdlogger/LCD4Bit_mod.cpp | 209 --------------- obdlogger/LCD4Bit_mod.h | 47 ---- obdlogger/MPU6050.cpp | 196 -------------- obdlogger/MPU6050.h | 644 ---------------------------------------------- obdlogger/MultiLCD.cpp | 182 ------------- obdlogger/MultiLCD.h | 84 ------ obdlogger/OBD.cpp | 286 -------------------- obdlogger/OBD.h | 84 ------ obdlogger/PCD8544.cpp | 313 ---------------------- obdlogger/PCD8544.h | 124 --------- obdlogger/README.txt | 2 + obdlogger/TinyGPS.cpp | 426 ------------------------------ obdlogger/TinyGPS.h | 153 ----------- obdlogger/ZtLib.cpp | 601 ------------------------------------------ obdlogger/ZtLib.h | 127 --------- obdlogger/images.h | 5 + obdlogger/obdlogger.cbp | 16 +- obdlogger/obdlogger.ino | 349 +++++++++++++------------ 18 files changed, 191 insertions(+), 3657 deletions(-) delete mode 100644 obdlogger/LCD4Bit_mod.cpp delete mode 100644 obdlogger/LCD4Bit_mod.h delete mode 100644 obdlogger/MPU6050.cpp delete mode 100644 obdlogger/MPU6050.h delete mode 100644 obdlogger/MultiLCD.cpp delete mode 100644 obdlogger/MultiLCD.h delete mode 100644 obdlogger/OBD.cpp delete mode 100644 obdlogger/OBD.h delete mode 100644 obdlogger/PCD8544.cpp delete mode 100644 obdlogger/PCD8544.h delete mode 100644 obdlogger/TinyGPS.cpp delete mode 100644 obdlogger/TinyGPS.h delete mode 100644 obdlogger/ZtLib.cpp delete mode 100644 obdlogger/ZtLib.h create mode 100644 obdlogger/images.h (limited to 'obdlogger') 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 - -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 -#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() && ireg.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 - -// 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< -#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 -* All rights reserved. -*************************************************************************/ - -#include -#include -#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 -* 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 - * - * 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 -#include - - -#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 - * - * 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 -#else -#include -#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 - #include - #include - #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=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 - -////////////////// -#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 @@