From df4f9660834d1b7c64466812c5ede06de2eb1d45 Mon Sep 17 00:00:00 2001 From: Stanley Huang Date: Wed, 21 Aug 2013 13:27:39 +0800 Subject: update MicroLCD library --- gpslogger/MicroLCD.cpp | 119 +++++++++++++++++++++++++------------------------ gpslogger/MicroLCD.h | 9 +--- obdlogger/MicroLCD.cpp | 119 +++++++++++++++++++++++++------------------------ obdlogger/MicroLCD.h | 7 --- 4 files changed, 121 insertions(+), 133 deletions(-) diff --git a/gpslogger/MicroLCD.cpp b/gpslogger/MicroLCD.cpp index d632506..19a45fa 100644 --- a/gpslogger/MicroLCD.cpp +++ b/gpslogger/MicroLCD.cpp @@ -406,18 +406,17 @@ void LCD_SSD1306::writeDigit(byte n) } Wire.endTransmission(); m_col += 6; - } else if (m_font == FONT_SIZE_MEDIUM) { -#ifndef MEMORY_SAVING + } else if (m_font == FONT_SIZE_XLARGE) { if (n <= 9) { - n += '0' - 0x21; + byte i; ssd1306_command(0xB0 + m_row);//set page address ssd1306_command(m_col & 0xf);//set lower column address ssd1306_command(0x10 | (m_col >> 4));//set higher column address Wire.beginTransmission(_i2caddr); Wire.write(0x40); - for (byte i = 0; i <= 14; i += 2) { - byte d = pgm_read_byte_near(&font8x16_terminal[n][i]); + for (i = 0; i < 16; i ++) { + byte d = pgm_read_byte_near(&digits16x24[n][i * 3]); Wire.write(d); if (m_flags & FLAG_PIXEL_DOUBLE_H) Wire.write(d); } @@ -429,8 +428,21 @@ void LCD_SSD1306::writeDigit(byte n) Wire.beginTransmission(_i2caddr); Wire.write(0x40); - for (byte i = 1; i <= 15; i += 2) { - byte d = pgm_read_byte_near(&font8x16_terminal[n][i]); + for (i = 0; i < 16; i ++) { + byte d = pgm_read_byte_near(&digits16x24[n][i * 3 + 1]); + Wire.write(d); + if (m_flags & FLAG_PIXEL_DOUBLE_H) Wire.write(d); + } + Wire.endTransmission(); + + ssd1306_command(0xB0 + m_row + 2);//set page address + ssd1306_command(m_col & 0xf);//set lower column address + ssd1306_command(0x10 | (m_col >> 4));//set higher column address + + Wire.beginTransmission(_i2caddr); + Wire.write(0x40); + for (i = 0; i < 16; i ++) { + byte d = pgm_read_byte_near(&digits16x24[n][i * 3 + 2]); Wire.write(d); if (m_flags & FLAG_PIXEL_DOUBLE_H) Wire.write(d); } @@ -442,7 +454,7 @@ void LCD_SSD1306::writeDigit(byte n) Wire.beginTransmission(_i2caddr); Wire.write(0x40); - for (byte i = (m_flags & FLAG_PIXEL_DOUBLE_H) ? 16 : 8; i > 0; i--) { + for (byte i = (m_flags & FLAG_PIXEL_DOUBLE_H) ? 32 : 16; i > 0; i--) { Wire.write(0); } Wire.endTransmission(); @@ -453,38 +465,35 @@ void LCD_SSD1306::writeDigit(byte n) Wire.beginTransmission(_i2caddr); Wire.write(0x40); - for (byte i = (m_flags & FLAG_PIXEL_DOUBLE_H) ? 16 : 8; i > 0; i--) { + for (byte i = (m_flags & FLAG_PIXEL_DOUBLE_H) ? 32 : 16; i > 0; i--) { Wire.write(0); } Wire.endTransmission(); - } - m_col += (m_flags & FLAG_PIXEL_DOUBLE_H) ? 17 : 9; -#else - Wire.beginTransmission(_i2caddr); - Wire.write(0x40); - if (n <= 9) { - for (byte i = 0; i < 8; i++) { - Wire.write(pgm_read_byte_near(&digits8x8[n][i])); - } - } else { - for (byte i = 0; i < 8; i++) { + + ssd1306_command(0xB0 + m_row + 2);//set page address + ssd1306_command(m_col & 0xf);//set lower column address + ssd1306_command(0x10 | (m_col >> 4));//set higher column address + + Wire.beginTransmission(_i2caddr); + Wire.write(0x40); + for (byte i = (m_flags & FLAG_PIXEL_DOUBLE_H) ? 32 : 16; i > 0; i--) { Wire.write(0); } + Wire.endTransmission(); } - Wire.endTransmission(); - m_col += 8; -#endif - } else if (m_font == FONT_SIZE_LARGE) { + m_col += (m_flags & FLAG_PIXEL_DOUBLE_H) ? 30 : 16; +#ifndef MEMORY_SAVING + } else if (m_font == FONT_SIZE_MEDIUM) { if (n <= 9) { - byte i; + n += '0' - 0x21; ssd1306_command(0xB0 + m_row);//set page address ssd1306_command(m_col & 0xf);//set lower column address ssd1306_command(0x10 | (m_col >> 4));//set higher column address Wire.beginTransmission(_i2caddr); Wire.write(0x40); - for (i = 0; i < 16; i ++) { - byte d = pgm_read_byte_near(&digits16x16[n][i]); + for (byte i = 0; i <= 14; i += 2) { + byte d = pgm_read_byte_near(&font8x16_terminal[n][i]); Wire.write(d); if (m_flags & FLAG_PIXEL_DOUBLE_H) Wire.write(d); } @@ -496,8 +505,8 @@ void LCD_SSD1306::writeDigit(byte n) Wire.beginTransmission(_i2caddr); Wire.write(0x40); - for (; i < 32; i ++) { - byte d = pgm_read_byte_near(&digits16x16[n][i]); + for (byte i = 1; i <= 15; i += 2) { + byte d = pgm_read_byte_near(&font8x16_terminal[n][i]); Wire.write(d); if (m_flags & FLAG_PIXEL_DOUBLE_H) Wire.write(d); } @@ -509,7 +518,7 @@ void LCD_SSD1306::writeDigit(byte n) Wire.beginTransmission(_i2caddr); Wire.write(0x40); - for (byte i = (m_flags & FLAG_PIXEL_DOUBLE_H) ? 32 : 16; i > 0; i--) { + for (byte i = (m_flags & FLAG_PIXEL_DOUBLE_H) ? 16 : 8; i > 0; i--) { Wire.write(0); } Wire.endTransmission(); @@ -520,13 +529,13 @@ void LCD_SSD1306::writeDigit(byte n) Wire.beginTransmission(_i2caddr); Wire.write(0x40); - for (byte i = (m_flags & FLAG_PIXEL_DOUBLE_H) ? 32 : 16; i > 0; i--) { + for (byte i = (m_flags & FLAG_PIXEL_DOUBLE_H) ? 16 : 8; i > 0; i--) { Wire.write(0); } Wire.endTransmission(); } - m_col += (m_flags & FLAG_PIXEL_DOUBLE_H) ? 30 : 16; - } else if (m_font == FONT_SIZE_XLARGE) { + m_col += (m_flags & FLAG_PIXEL_DOUBLE_H) ? 17 : 9; + } else { if (n <= 9) { byte i; ssd1306_command(0xB0 + m_row);//set page address @@ -536,7 +545,7 @@ void LCD_SSD1306::writeDigit(byte n) Wire.beginTransmission(_i2caddr); Wire.write(0x40); for (i = 0; i < 16; i ++) { - byte d = pgm_read_byte_near(&digits16x24[n][i * 3]); + byte d = pgm_read_byte_near(&digits16x16[n][i]); Wire.write(d); if (m_flags & FLAG_PIXEL_DOUBLE_H) Wire.write(d); } @@ -548,21 +557,8 @@ void LCD_SSD1306::writeDigit(byte n) Wire.beginTransmission(_i2caddr); Wire.write(0x40); - for (i = 0; i < 16; i ++) { - byte d = pgm_read_byte_near(&digits16x24[n][i * 3 + 1]); - Wire.write(d); - if (m_flags & FLAG_PIXEL_DOUBLE_H) Wire.write(d); - } - Wire.endTransmission(); - - ssd1306_command(0xB0 + m_row + 2);//set page address - ssd1306_command(m_col & 0xf);//set lower column address - ssd1306_command(0x10 | (m_col >> 4));//set higher column address - - Wire.beginTransmission(_i2caddr); - Wire.write(0x40); - for (i = 0; i < 16; i ++) { - byte d = pgm_read_byte_near(&digits16x24[n][i * 3 + 2]); + for (; i < 32; i ++) { + byte d = pgm_read_byte_near(&digits16x16[n][i]); Wire.write(d); if (m_flags & FLAG_PIXEL_DOUBLE_H) Wire.write(d); } @@ -589,19 +585,24 @@ void LCD_SSD1306::writeDigit(byte n) Wire.write(0); } Wire.endTransmission(); - - ssd1306_command(0xB0 + m_row + 2);//set page address - ssd1306_command(m_col & 0xf);//set lower column address - ssd1306_command(0x10 | (m_col >> 4));//set higher column address - - Wire.beginTransmission(_i2caddr); - Wire.write(0x40); - for (byte i = (m_flags & FLAG_PIXEL_DOUBLE_H) ? 32 : 16; i > 0; i--) { + } + m_col += (m_flags & FLAG_PIXEL_DOUBLE_H) ? 30 : 16; +#else + } else { + Wire.beginTransmission(_i2caddr); + Wire.write(0x40); + if (n <= 9) { + for (byte i = 0; i < 8; i++) { + Wire.write(pgm_read_byte_near(&digits8x8[n][i])); + } + } else { + for (byte i = 0; i < 8; i++) { Wire.write(0); } - Wire.endTransmission(); } - m_col += (m_flags & FLAG_PIXEL_DOUBLE_H) ? 30 : 16; + Wire.endTransmission(); + m_col += 8; +#endif } TWBR = twbrbackup; } diff --git a/gpslogger/MicroLCD.h b/gpslogger/MicroLCD.h index 6b01495..a22a2ce 100644 --- a/gpslogger/MicroLCD.h +++ b/gpslogger/MicroLCD.h @@ -6,7 +6,7 @@ *************************************************************************/ #if !defined(__AVR_ATmega2560__) && !defined(__AVR_ATmega1280__) && !defined(__AVR_ATmega644P__) -//#define MEMORY_SAVING +#define MEMORY_SAVING #endif typedef enum { @@ -21,13 +21,6 @@ typedef enum { #define FLAG_PIXEL_DOUBLE_V 4 #define FLAG_PIXEL_DOUBLE (FLAG_PIXEL_DOUBLE_H | FLAG_PIXEL_DOUBLE_V) -extern const PROGMEM unsigned char font5x8[][5]; -extern const PROGMEM unsigned char digits8x8[][8] ; -extern const PROGMEM unsigned char digits16x16[][32]; -extern const PROGMEM unsigned char digits16x24[][48]; -extern const PROGMEM unsigned char font8x16_doslike[][16]; -extern const PROGMEM unsigned char font8x16_terminal[][16]; - class LCD_Common { public: diff --git a/obdlogger/MicroLCD.cpp b/obdlogger/MicroLCD.cpp index d632506..19a45fa 100644 --- a/obdlogger/MicroLCD.cpp +++ b/obdlogger/MicroLCD.cpp @@ -406,18 +406,17 @@ void LCD_SSD1306::writeDigit(byte n) } Wire.endTransmission(); m_col += 6; - } else if (m_font == FONT_SIZE_MEDIUM) { -#ifndef MEMORY_SAVING + } else if (m_font == FONT_SIZE_XLARGE) { if (n <= 9) { - n += '0' - 0x21; + byte i; ssd1306_command(0xB0 + m_row);//set page address ssd1306_command(m_col & 0xf);//set lower column address ssd1306_command(0x10 | (m_col >> 4));//set higher column address Wire.beginTransmission(_i2caddr); Wire.write(0x40); - for (byte i = 0; i <= 14; i += 2) { - byte d = pgm_read_byte_near(&font8x16_terminal[n][i]); + for (i = 0; i < 16; i ++) { + byte d = pgm_read_byte_near(&digits16x24[n][i * 3]); Wire.write(d); if (m_flags & FLAG_PIXEL_DOUBLE_H) Wire.write(d); } @@ -429,8 +428,21 @@ void LCD_SSD1306::writeDigit(byte n) Wire.beginTransmission(_i2caddr); Wire.write(0x40); - for (byte i = 1; i <= 15; i += 2) { - byte d = pgm_read_byte_near(&font8x16_terminal[n][i]); + for (i = 0; i < 16; i ++) { + byte d = pgm_read_byte_near(&digits16x24[n][i * 3 + 1]); + Wire.write(d); + if (m_flags & FLAG_PIXEL_DOUBLE_H) Wire.write(d); + } + Wire.endTransmission(); + + ssd1306_command(0xB0 + m_row + 2);//set page address + ssd1306_command(m_col & 0xf);//set lower column address + ssd1306_command(0x10 | (m_col >> 4));//set higher column address + + Wire.beginTransmission(_i2caddr); + Wire.write(0x40); + for (i = 0; i < 16; i ++) { + byte d = pgm_read_byte_near(&digits16x24[n][i * 3 + 2]); Wire.write(d); if (m_flags & FLAG_PIXEL_DOUBLE_H) Wire.write(d); } @@ -442,7 +454,7 @@ void LCD_SSD1306::writeDigit(byte n) Wire.beginTransmission(_i2caddr); Wire.write(0x40); - for (byte i = (m_flags & FLAG_PIXEL_DOUBLE_H) ? 16 : 8; i > 0; i--) { + for (byte i = (m_flags & FLAG_PIXEL_DOUBLE_H) ? 32 : 16; i > 0; i--) { Wire.write(0); } Wire.endTransmission(); @@ -453,38 +465,35 @@ void LCD_SSD1306::writeDigit(byte n) Wire.beginTransmission(_i2caddr); Wire.write(0x40); - for (byte i = (m_flags & FLAG_PIXEL_DOUBLE_H) ? 16 : 8; i > 0; i--) { + for (byte i = (m_flags & FLAG_PIXEL_DOUBLE_H) ? 32 : 16; i > 0; i--) { Wire.write(0); } Wire.endTransmission(); - } - m_col += (m_flags & FLAG_PIXEL_DOUBLE_H) ? 17 : 9; -#else - Wire.beginTransmission(_i2caddr); - Wire.write(0x40); - if (n <= 9) { - for (byte i = 0; i < 8; i++) { - Wire.write(pgm_read_byte_near(&digits8x8[n][i])); - } - } else { - for (byte i = 0; i < 8; i++) { + + ssd1306_command(0xB0 + m_row + 2);//set page address + ssd1306_command(m_col & 0xf);//set lower column address + ssd1306_command(0x10 | (m_col >> 4));//set higher column address + + Wire.beginTransmission(_i2caddr); + Wire.write(0x40); + for (byte i = (m_flags & FLAG_PIXEL_DOUBLE_H) ? 32 : 16; i > 0; i--) { Wire.write(0); } + Wire.endTransmission(); } - Wire.endTransmission(); - m_col += 8; -#endif - } else if (m_font == FONT_SIZE_LARGE) { + m_col += (m_flags & FLAG_PIXEL_DOUBLE_H) ? 30 : 16; +#ifndef MEMORY_SAVING + } else if (m_font == FONT_SIZE_MEDIUM) { if (n <= 9) { - byte i; + n += '0' - 0x21; ssd1306_command(0xB0 + m_row);//set page address ssd1306_command(m_col & 0xf);//set lower column address ssd1306_command(0x10 | (m_col >> 4));//set higher column address Wire.beginTransmission(_i2caddr); Wire.write(0x40); - for (i = 0; i < 16; i ++) { - byte d = pgm_read_byte_near(&digits16x16[n][i]); + for (byte i = 0; i <= 14; i += 2) { + byte d = pgm_read_byte_near(&font8x16_terminal[n][i]); Wire.write(d); if (m_flags & FLAG_PIXEL_DOUBLE_H) Wire.write(d); } @@ -496,8 +505,8 @@ void LCD_SSD1306::writeDigit(byte n) Wire.beginTransmission(_i2caddr); Wire.write(0x40); - for (; i < 32; i ++) { - byte d = pgm_read_byte_near(&digits16x16[n][i]); + for (byte i = 1; i <= 15; i += 2) { + byte d = pgm_read_byte_near(&font8x16_terminal[n][i]); Wire.write(d); if (m_flags & FLAG_PIXEL_DOUBLE_H) Wire.write(d); } @@ -509,7 +518,7 @@ void LCD_SSD1306::writeDigit(byte n) Wire.beginTransmission(_i2caddr); Wire.write(0x40); - for (byte i = (m_flags & FLAG_PIXEL_DOUBLE_H) ? 32 : 16; i > 0; i--) { + for (byte i = (m_flags & FLAG_PIXEL_DOUBLE_H) ? 16 : 8; i > 0; i--) { Wire.write(0); } Wire.endTransmission(); @@ -520,13 +529,13 @@ void LCD_SSD1306::writeDigit(byte n) Wire.beginTransmission(_i2caddr); Wire.write(0x40); - for (byte i = (m_flags & FLAG_PIXEL_DOUBLE_H) ? 32 : 16; i > 0; i--) { + for (byte i = (m_flags & FLAG_PIXEL_DOUBLE_H) ? 16 : 8; i > 0; i--) { Wire.write(0); } Wire.endTransmission(); } - m_col += (m_flags & FLAG_PIXEL_DOUBLE_H) ? 30 : 16; - } else if (m_font == FONT_SIZE_XLARGE) { + m_col += (m_flags & FLAG_PIXEL_DOUBLE_H) ? 17 : 9; + } else { if (n <= 9) { byte i; ssd1306_command(0xB0 + m_row);//set page address @@ -536,7 +545,7 @@ void LCD_SSD1306::writeDigit(byte n) Wire.beginTransmission(_i2caddr); Wire.write(0x40); for (i = 0; i < 16; i ++) { - byte d = pgm_read_byte_near(&digits16x24[n][i * 3]); + byte d = pgm_read_byte_near(&digits16x16[n][i]); Wire.write(d); if (m_flags & FLAG_PIXEL_DOUBLE_H) Wire.write(d); } @@ -548,21 +557,8 @@ void LCD_SSD1306::writeDigit(byte n) Wire.beginTransmission(_i2caddr); Wire.write(0x40); - for (i = 0; i < 16; i ++) { - byte d = pgm_read_byte_near(&digits16x24[n][i * 3 + 1]); - Wire.write(d); - if (m_flags & FLAG_PIXEL_DOUBLE_H) Wire.write(d); - } - Wire.endTransmission(); - - ssd1306_command(0xB0 + m_row + 2);//set page address - ssd1306_command(m_col & 0xf);//set lower column address - ssd1306_command(0x10 | (m_col >> 4));//set higher column address - - Wire.beginTransmission(_i2caddr); - Wire.write(0x40); - for (i = 0; i < 16; i ++) { - byte d = pgm_read_byte_near(&digits16x24[n][i * 3 + 2]); + for (; i < 32; i ++) { + byte d = pgm_read_byte_near(&digits16x16[n][i]); Wire.write(d); if (m_flags & FLAG_PIXEL_DOUBLE_H) Wire.write(d); } @@ -589,19 +585,24 @@ void LCD_SSD1306::writeDigit(byte n) Wire.write(0); } Wire.endTransmission(); - - ssd1306_command(0xB0 + m_row + 2);//set page address - ssd1306_command(m_col & 0xf);//set lower column address - ssd1306_command(0x10 | (m_col >> 4));//set higher column address - - Wire.beginTransmission(_i2caddr); - Wire.write(0x40); - for (byte i = (m_flags & FLAG_PIXEL_DOUBLE_H) ? 32 : 16; i > 0; i--) { + } + m_col += (m_flags & FLAG_PIXEL_DOUBLE_H) ? 30 : 16; +#else + } else { + Wire.beginTransmission(_i2caddr); + Wire.write(0x40); + if (n <= 9) { + for (byte i = 0; i < 8; i++) { + Wire.write(pgm_read_byte_near(&digits8x8[n][i])); + } + } else { + for (byte i = 0; i < 8; i++) { Wire.write(0); } - Wire.endTransmission(); } - m_col += (m_flags & FLAG_PIXEL_DOUBLE_H) ? 30 : 16; + Wire.endTransmission(); + m_col += 8; +#endif } TWBR = twbrbackup; } diff --git a/obdlogger/MicroLCD.h b/obdlogger/MicroLCD.h index 1206414..a22a2ce 100644 --- a/obdlogger/MicroLCD.h +++ b/obdlogger/MicroLCD.h @@ -21,13 +21,6 @@ typedef enum { #define FLAG_PIXEL_DOUBLE_V 4 #define FLAG_PIXEL_DOUBLE (FLAG_PIXEL_DOUBLE_H | FLAG_PIXEL_DOUBLE_V) -extern const PROGMEM unsigned char font5x8[][5]; -extern const PROGMEM unsigned char digits8x8[][8] ; -extern const PROGMEM unsigned char digits16x16[][32]; -extern const PROGMEM unsigned char digits16x24[][48]; -extern const PROGMEM unsigned char font8x16_doslike[][16]; -extern const PROGMEM unsigned char font8x16_terminal[][16]; - class LCD_Common { public: -- cgit v1.2.3