From 6c94f4fcda140f3e95a4a723a222219cc83e7776 Mon Sep 17 00:00:00 2001 From: Stanley Huang Date: Sun, 6 Jul 2014 21:41:11 +1000 Subject: Update OBD-II logger for Arduino Nano --- nanologger/MicroLCD.cpp | 49 ++++++--- nanologger/MicroLCD.h | 37 +++++-- nanologger/nanologger.cbp | 241 +------------------------------------------ nanologger/nanologger.depend | 71 ------------- nanologger/nanologger.ino | 24 ++--- 5 files changed, 78 insertions(+), 344 deletions(-) delete mode 100644 nanologger/nanologger.depend (limited to 'nanologger') diff --git a/nanologger/MicroLCD.cpp b/nanologger/MicroLCD.cpp index b4caf3c..a602b18 100644 --- a/nanologger/MicroLCD.cpp +++ b/nanologger/MicroLCD.cpp @@ -292,8 +292,6 @@ void LCD_SSD1306::setCursor(byte column, byte line) size_t LCD_SSD1306::write(uint8_t c) { - uint8_t twbrbackup = TWBR; - TWBR = 18; // upgrade to 400KHz! if (c == '\n') { setCursor(0, m_row + ((m_font == FONT_SIZE_SMALL) ? 1 : 2)); return 1; @@ -301,6 +299,10 @@ size_t LCD_SSD1306::write(uint8_t c) m_col = 0; return 1; } +#ifdef TWBR + uint8_t twbrbackup = TWBR; + TWBR = 18; // upgrade to 400KHz! +#endif #ifndef MEMORY_SAVING if (m_font == FONT_SIZE_SMALL) { #endif @@ -385,14 +387,18 @@ size_t LCD_SSD1306::write(uint8_t c) } } #endif +#ifdef TWBR TWBR = twbrbackup; +#endif return 1; } void LCD_SSD1306::writeDigit(byte n) { +#ifdef TWBR uint8_t twbrbackup = TWBR; TWBR = 18; // upgrade to 400KHz! +#endif if (m_font == FONT_SIZE_SMALL) { Wire.beginTransmission(_i2caddr); Wire.write(0x40); @@ -542,7 +548,9 @@ void LCD_SSD1306::writeDigit(byte n) } m_col += (m_flags & FLAG_PIXEL_DOUBLE_H) ? 30 : 16; } +#ifdef TWBR TWBR = twbrbackup; +#endif } void LCD_SSD1306::draw(const PROGMEM byte* buffer, byte width, byte height) @@ -551,13 +559,13 @@ void LCD_SSD1306::draw(const PROGMEM byte* buffer, byte width, byte height) ssd1306_command(SSD1306_SETHIGHCOLUMN | 0x0); // hi col = 0 ssd1306_command(SSD1306_SETSTARTLINE | 0x0); // line #0 - // save I2C bitrate - uint8_t twbrbackup = TWBR; - TWBR = 18; // upgrade to 400KHz! - const PROGMEM byte *p = buffer; height >>= 3; width >>= 3; +#ifdef TWBR + uint8_t twbrbackup = TWBR; + TWBR = 18; // upgrade to 400KHz! +#endif for (byte i = 0; i < height; i++) { // send a bunch of data in one xmission ssd1306_command(0xB0 + i + m_row);//set page address @@ -573,8 +581,10 @@ void LCD_SSD1306::draw(const PROGMEM byte* buffer, byte width, byte height) Wire.endTransmission(); } } - TWBR = twbrbackup; m_col += width; +#ifdef TWBR + TWBR = twbrbackup; +#endif } void LCD_SSD1306::clearLine(byte line) @@ -583,9 +593,10 @@ void LCD_SSD1306::clearLine(byte line) ssd1306_command(SSD1306_SETHIGHCOLUMN | 0x0); // hi col = 0 ssd1306_command(SSD1306_SETSTARTLINE | 0x0); // line #0 - // save I2C bitrate +#ifdef TWBR uint8_t twbrbackup = TWBR; TWBR = 18; // upgrade to 400KHz! +#endif // send a bunch of data in one xmission ssd1306_command(0xB0 + line);//set page address @@ -600,8 +611,9 @@ void LCD_SSD1306::clearLine(byte line) } Wire.endTransmission(); } - +#ifdef TWBR TWBR = twbrbackup; +#endif } void LCD_SSD1306::clear(byte x, byte y, byte width, byte height) @@ -610,13 +622,13 @@ void LCD_SSD1306::clear(byte x, byte y, byte width, byte height) ssd1306_command(SSD1306_SETHIGHCOLUMN | 0x0); // hi col = 0 ssd1306_command(SSD1306_SETSTARTLINE | 0x0); // line #0 - // save I2C bitrate - uint8_t twbrbackup = TWBR; - TWBR = 18; // upgrade to 400KHz! - height >>= 3; width >>= 3; y >>= 3; +#ifdef TWBR + uint8_t twbrbackup = TWBR; + TWBR = 18; // upgrade to 400KHz! +#endif for (byte i = 0; i < height; i++) { // send a bunch of data in one xmission ssd1306_command(0xB0 + i + y);//set page address @@ -632,7 +644,14 @@ void LCD_SSD1306::clear(byte x, byte y, byte width, byte height) Wire.endTransmission(); } } - - setCursor(0, 0); +#ifdef TWBR TWBR = twbrbackup; +#endif + setCursor(0, 0); +} + +void LCD_SSD1306::setContrast(byte Contrast) +{ + ssd1306_command(SSD1306_SETCONTRAST); + ssd1306_command(Contrast); } diff --git a/nanologger/MicroLCD.h b/nanologger/MicroLCD.h index e421505..51781ab 100644 --- a/nanologger/MicroLCD.h +++ b/nanologger/MicroLCD.h @@ -1,13 +1,14 @@ /************************************************************************* -* Arduino Text Display Library for Multiple LCDs +* Arduino Text & Bitmap Display Library for multiple models of monochrome LCD display * Distributed under GPL v2.0 -* Copyright (c) 2013 Stanley Huang +* Copyright (c) 2013-2014 Stanley Huang * All rights reserved. +* For more information, please visit http://arduinodev.com *************************************************************************/ -#if !defined(__AVR_ATmega2560__) && !defined(__AVR_ATmega1280__) && !defined(__AVR_ATmega644P__) +#include + //#define MEMORY_SAVING -#endif typedef enum { FONT_SIZE_SMALL = 0, @@ -32,10 +33,10 @@ class LCD_Common { public: LCD_Common():m_font(FONT_SIZE_SMALL),m_flags(0) {} - void setFont(FONT_SIZE size) { m_font = size; } + void setFontSize(FONT_SIZE size) { m_font = size; } void setFlags(byte flags) { m_flags = flags; } virtual void backlight(bool on) {} - virtual void draw(const PROGMEM byte* buffer, byte x, byte y, byte width, byte height) {} + virtual void draw(const PROGMEM byte* buffer, byte width, byte height) {} void printInt(uint16_t value, int8_t padding = -1); void printLong(uint32_t value, int8_t padding = -1); protected: @@ -62,6 +63,7 @@ class LCD_SSD1306 : public LCD_Common, public SSD1306, public Print { public: void setCursor(byte column, byte line); + void setContrast(byte Contrast); void draw(const PROGMEM byte* buffer, byte width, byte height); size_t write(uint8_t c); void clear(byte x = 0, byte y = 0, byte width = 128, byte height = 64); @@ -92,3 +94,26 @@ private: byte m_col; byte m_row; }; + +#include "PCD8544.h" + +class LCD_PCD8544 : public LCD_Common, public PCD8544 +{ +public: + byte getLines() { return 6; } + byte getCols() { return 14; } + 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(' '); + } + void draw(const PROGMEM byte* buffer, byte width, byte height); +private: + void writeDigit(byte n); +}; + diff --git a/nanologger/nanologger.cbp b/nanologger/nanologger.cbp index c45b7ad..6024094 100644 --- a/nanologger/nanologger.cbp +++ b/nanologger/nanologger.cbp @@ -98,42 +98,6 @@ - - - - - - - - - - - - - - @@ -595,6 +355,7 @@ + diff --git a/nanologger/nanologger.depend b/nanologger/nanologger.depend deleted file mode 100644 index 6f4664c..0000000 --- a/nanologger/nanologger.depend +++ /dev/null @@ -1,71 +0,0 @@ -# depslib dependency file v1.0 -1394256987 source:e:\arduino\arduinoobd\nanologger\microlcd.cpp - - - "MicroLCD.h" - -1371033101 d:\apps\codeblocks\arduino\hardware\arduino\cores\arduino\arduino.h - - - - - - - "binary.h" - "WCharacter.h" - "WString.h" - "HardwareSerial.h" - "pins_arduino.h" - -1362986950 d:\apps\codeblocks\arduino\hardware\arduino\cores\arduino\binary.h - -1362986950 d:\apps\codeblocks\arduino\hardware\arduino\cores\arduino\wcharacter.h - - -1371033133 d:\apps\codeblocks\arduino\hardware\arduino\cores\arduino\wstring.h - - - - - -1362986950 d:\apps\codeblocks\arduino\hardware\arduino\cores\arduino\hardwareserial.h - - "Stream.h" - "USBAPI.h" - -1371032829 d:\apps\codeblocks\arduino\hardware\arduino\cores\arduino\stream.h - - "Print.h" - -1362986950 d:\apps\codeblocks\arduino\hardware\arduino\cores\arduino\print.h - - - "WString.h" - "Printable.h" - -1362986950 d:\apps\codeblocks\arduino\hardware\arduino\cores\arduino\printable.h - - -1362986950 d:\apps\codeblocks\arduino\hardware\arduino\cores\arduino\new.h - - -1362986950 d:\apps\codeblocks\arduino\hardware\arduino\cores\arduino\usbapi.h - -1362986950 d:\apps\codeblocks\arduino\hardware\arduino\variants\eightanaloginputs\pins_arduino.h - "../standard/pins_arduino.h" - -1362986950 d:\apps\codeblocks\arduino\hardware\arduino\variants\standard\pins_arduino.h - - -1394121163 e:\arduino\arduinoobd\nanologger\microlcd.h - "SSD1306.h" - -1371132197 e:\arduino\arduinoobd\nanologger\ssd1306.h - "Arduino.h" - "WProgram.h" - -1394121227 source:e:\arduino\arduinoobd\nanologger\sh1106.cpp - - - "MicroLCD.h" - diff --git a/nanologger/nanologger.ino b/nanologger/nanologger.ino index 10c1b5e..cc03a53 100644 --- a/nanologger/nanologger.ino +++ b/nanologger/nanologger.ino @@ -72,7 +72,7 @@ public: #if ENABLE_DATA_LOG uint16_t index = openFile(); - lcd.setFont(FONT_SIZE_SMALL); + lcd.setFontSize(FONT_SIZE_SMALL); lcd.setCursor(86, 0); if (index) { lcd.write('['); @@ -120,7 +120,7 @@ public: // display distance travelled (GPS) char buf[10]; sprintf(buf, "%4ukm", (uint16_t)(distance / 1000)); - lcd.setFont(FONT_SIZE_SMALL); + lcd.setFontSize(FONT_SIZE_SMALL); lcd.setCursor(92, 6); lcd.print(buf); @@ -138,7 +138,7 @@ public: // display logged data size char buf[7]; sprintf(buf, "%4uKB", (int)(dataSize >> 10)); - lcd.setFont(FONT_SIZE_SMALL); + lcd.setFontSize(FONT_SIZE_SMALL); lcd.setCursor(92, 7); lcd.print(buf); } @@ -246,7 +246,7 @@ private: closeFile(); #endif lcd.clear(); - lcd.setFont(FONT_SIZE_MEDIUM); + lcd.setFontSize(FONT_SIZE_MEDIUM); lcd.print("Reconnecting"); startTime = millis(); state &= ~(STATE_OBD_READY | STATE_ACC_READY); @@ -277,7 +277,7 @@ private: // screen layout related stuff void showStates() { - lcd.setFont(FONT_SIZE_MEDIUM); + lcd.setFontSize(FONT_SIZE_MEDIUM); lcd.setCursor(0, 4); lcd.print("OBD "); showTickCross(state & STATE_OBD_READY); @@ -291,26 +291,26 @@ private: switch (pid) { case PID_RPM: lcd.setCursor(64, 0); - lcd.setFont(FONT_SIZE_XLARGE); + lcd.setFontSize(FONT_SIZE_XLARGE); lcd.printInt((unsigned int)value % 10000, 4); break; case PID_SPEED: if (lastSpeed != value) { lcd.setCursor(0, 0); - lcd.setFont(FONT_SIZE_XLARGE); + lcd.setFontSize(FONT_SIZE_XLARGE); lcd.printInt((unsigned int)value % 1000, 3); lastSpeed = value; } break; case PID_THROTTLE: lcd.setCursor(24, 5); - lcd.setFont(FONT_SIZE_SMALL); + lcd.setFontSize(FONT_SIZE_SMALL); lcd.printInt(value % 100, 3); break; case PID_INTAKE_TEMP: if (value < 1000) { lcd.setCursor(102, 5); - lcd.setFont(FONT_SIZE_SMALL); + lcd.setFontSize(FONT_SIZE_SMALL); lcd.printInt(value, 3); } break; @@ -349,7 +349,7 @@ private: { lcd.clear(); lcd.backlight(true); - lcd.setFont(FONT_SIZE_SMALL); + lcd.setFontSize(FONT_SIZE_SMALL); lcd.setCursor(24, 3); lcd.print("km/h"); lcd.setCursor(110, 3); @@ -366,14 +366,14 @@ static COBDLogger logger; void setup() { lcd.begin(); - lcd.setFont(FONT_SIZE_MEDIUM); + lcd.setFontSize(FONT_SIZE_MEDIUM); lcd.println("NanoLogger"); logger.begin(); logger.initSender(); #if ENABLE_DATA_LOG - lcd.setFont(FONT_SIZE_MEDIUM); + lcd.setFontSize(FONT_SIZE_MEDIUM); lcd.setCursor(0, 2); logger.checkSD(); #endif -- cgit v1.2.3