diff options
author | Stanley Huang <stanleyhuangyc@gmail.com> | 2013-08-16 15:29:22 +0800 |
---|---|---|
committer | Stanley Huang <stanleyhuangyc@gmail.com> | 2013-08-16 15:29:22 +0800 |
commit | 13d3017ab8323689111175b287451ffc142eeb07 (patch) | |
tree | 32504d9a67e5fb8b94cc7f25a8b2e70e40564a02 /obdlogger | |
parent | 6cb3c04fa37588eddf1341d77d1d70cfd8a2fcb3 (diff) | |
download | 2021-arduino-obd-13d3017ab8323689111175b287451ffc142eeb07.tar.gz 2021-arduino-obd-13d3017ab8323689111175b287451ffc142eeb07.tar.bz2 2021-arduino-obd-13d3017ab8323689111175b287451ffc142eeb07.zip |
using new MicroLCD library (saving memory)
Diffstat (limited to 'obdlogger')
-rw-r--r-- | obdlogger/MicroLCD.cpp (renamed from obdlogger/fonts.cpp) | 559 | ||||
-rw-r--r-- | obdlogger/MicroLCD.h (renamed from obdlogger/MultiLCD.h) | 0 | ||||
-rw-r--r-- | obdlogger/MultiLCD.cpp | 463 | ||||
-rw-r--r-- | obdlogger/obdlogger.ino | 2 |
4 files changed, 463 insertions, 561 deletions
diff --git a/obdlogger/fonts.cpp b/obdlogger/MicroLCD.cpp index 403e954..d632506 100644 --- a/obdlogger/fonts.cpp +++ b/obdlogger/MicroLCD.cpp @@ -1,6 +1,15 @@ +/************************************************************************* +* Arduino Text Display Library for Multiple LCDs +* Distributed under GPL v2.0 +* Copyright (c) 2013 Stanley Huang <stanleyhuangyc@live.com> +* All rights reserved. +*************************************************************************/ + #include <Arduino.h> -#include "MultiLCD.h" +#include <Wire.h> +#include "MicroLCD.h" +// fonts data const PROGMEM unsigned char digits16x24[][48] = { {0x00,0x00,0x00,0xF0,0xFF,0x0F,0xFC,0xFF,0x3F,0xFE,0xFF,0x7F,0xFE,0xFF,0x7F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x07,0x00,0xE0,0x07,0x00,0xE0,0x07,0x00,0xE0,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFE,0xFF,0x7F,0xFE,0xFF,0x7F,0xFC,0xFF,0x3F,0xF0,0xFF,0x0F},/*"0",0*/ {0x00,0x00,0x00,0x70,0x00,0x00,0x70,0x00,0x00,0x70,0x00,0x00,0x78,0x00,0x00,0xF8,0x00,0x00,0xFC,0xFF,0xFF,0xFE,0xFF,0xFF,0xFE,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"1",0*/ @@ -139,102 +148,6 @@ const PROGMEM unsigned char font5x8[][5] = { }; #ifndef MEMORY_SAVING -const PROGMEM unsigned char font8x16_doslike[][16] = { -{0x00,0x00,0x00,0x00,0x78,0x00,0xFC,0x09,0xFC,0x09,0x78,0x00,0x00,0x00,0x00,0x00},/*"!*/ -{0x00,0x00,0x0E,0x00,0x1E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1E,0x00,0x0E,0x00},/*""*/ -{0x20,0x02,0xF8,0x1F,0xF8,0x1F,0x20,0x02,0x20,0x02,0xF8,0x1F,0xF8,0x1F,0x20,0x02},/*"#*/ -{0x00,0x00,0x38,0x06,0x7C,0x0C,0x44,0x08,0xFF,0x3F,0x47,0x38,0xCC,0x0F,0x98,0x07},/*"$*/ -{0x10,0x08,0x38,0x0C,0x28,0x06,0x38,0x03,0x90,0x05,0xC0,0x0E,0x60,0x0A,0x30,0x0E},/*"%*/ -{0x80,0x07,0xD8,0x0F,0x7C,0x08,0x64,0x08,0xE4,0x08,0xBC,0x07,0x18,0x0F,0x80,0x09},/*"&*/ -{0x00,0x00,0x10,0x00,0x1C,0x00,0x0C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"'*/ -{0x00,0x00,0x00,0x00,0xF0,0x03,0xF8,0x07,0x0C,0x0C,0x04,0x08,0x00,0x00,0x00,0x00},/*"(*/ -{0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x08,0x0C,0x0C,0xF8,0x07,0xF0,0x03,0x00,0x00},/*")*/ -{0x80,0x00,0xA0,0x02,0xE0,0x03,0xC0,0x01,0xC0,0x01,0xE0,0x03,0xA0,0x02,0x80,0x00},/*"**/ -{0x80,0x00,0x80,0x00,0x80,0x00,0xE0,0x03,0xE0,0x03,0x80,0x00,0x80,0x00,0x80,0x00},/*"+0*/ -{0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x3C,0x00,0x1C,0x00,0x00,0x00,0x00,0x00,0x00},/*",*/ -{0x80,0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80,0x00},/*"-*/ -{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0C,0x00,0x0C,0x00,0x00,0x00,0x00,0x00,0x00},/*".*/ -{0x00,0x08,0x00,0x0C,0x00,0x06,0x00,0x03,0x80,0x01,0xC0,0x00,0x60,0x00,0x30,0x00},/*"/*/ -{0xF0,0x03,0xF8,0x07,0x0C,0x0C,0xC4,0x08,0xC4,0x08,0x0C,0x0C,0xF8,0x07,0xF0,0x03},/*"0*/ -{0x00,0x00,0x10,0x08,0x18,0x08,0xFC,0x0F,0xFC,0x0F,0x00,0x08,0x00,0x08,0x00,0x00},/*"1*/ -{0x08,0x0E,0x0C,0x0F,0x84,0x09,0xC4,0x08,0x64,0x08,0x3C,0x0C,0x18,0x0C,0x00,0x00},/*"2*/ -{0x08,0x04,0x0C,0x0C,0x04,0x08,0x44,0x08,0x44,0x08,0xFC,0x0F,0xB8,0x07,0x00,0x00},/*"3*/ -{0xC0,0x01,0xE0,0x01,0x30,0x01,0x18,0x09,0xFC,0x0F,0xFC,0x0F,0x00,0x09,0x00,0x00},/*"4*/ -{0x7C,0x04,0x7C,0x0C,0x44,0x08,0x44,0x08,0x44,0x08,0xC4,0x0F,0x84,0x07,0x00,0x00},/*"5*/ -{0xF0,0x07,0xF8,0x0F,0x4C,0x08,0x44,0x08,0x44,0x08,0xC4,0x0F,0x80,0x07,0x00,0x00},/*"6*/ -{0x0C,0x00,0x0C,0x00,0x84,0x0F,0xC4,0x0F,0x64,0x00,0x3C,0x00,0x1C,0x00,0x00,0x00},/*"7*/ -{0xB8,0x07,0xFC,0x0F,0x44,0x08,0x44,0x08,0x44,0x08,0xFC,0x0F,0xB8,0x07,0x00,0x00},/*"8*/ -{0x38,0x00,0x7C,0x08,0x44,0x08,0x44,0x08,0x44,0x0C,0xFC,0x07,0xF8,0x03,0x00,0x00},/*"9*/ -{0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x06,0x30,0x06,0x00,0x00,0x00,0x00,0x00,0x00},/*":*/ -{0x00,0x00,0x00,0x00,0x00,0x10,0x60,0x1C,0x60,0x0C,0x00,0x00,0x00,0x00,0x00,0x00},/*";",27*/ -{0x00,0x00,0x80,0x00,0xC0,0x01,0x60,0x03,0x30,0x06,0x18,0x0C,0x08,0x08,0x00,0x00},/*"<",28*/ -{0x20,0x01,0x20,0x01,0x20,0x01,0x20,0x01,0x20,0x01,0x20,0x01,0x20,0x01,0x00,0x00},/*"=",29*/ -{0x00,0x00,0x00,0x00,0x08,0x08,0x18,0x0C,0x30,0x06,0x60,0x03,0xC0,0x01,0x80,0x00},/*">",30*/ -{0x08,0x00,0x0C,0x00,0x04,0x00,0x84,0x0D,0xC4,0x0D,0x7C,0x00,0x38,0x00,0x00,0x00},/*"?",31*/ -{0xF8,0x07,0xFC,0x0F,0x04,0x08,0x84,0x09,0xC4,0x09,0xFC,0x09,0xF8,0x00,0x00,0x00},/*"@",32*/ -{0xE0,0x0F,0xF0,0x0F,0x98,0x00,0x8C,0x00,0x98,0x00,0xF0,0x0F,0xE0,0x0F,0x00,0x00},/*"A",33*/ -{0x04,0x08,0xFC,0x0F,0xFC,0x0F,0x44,0x08,0x44,0x08,0xFC,0x0F,0xB8,0x07,0x00,0x00},/*"B",34*/ -{0xF0,0x03,0xF8,0x07,0x0C,0x0C,0x04,0x08,0x04,0x08,0x0C,0x0C,0x18,0x06,0x00,0x00},/*"C",35*/ -{0x04,0x08,0xFC,0x0F,0xFC,0x0F,0x04,0x08,0x0C,0x0C,0xF8,0x07,0xF0,0x03,0x00,0x00},/*"D",36*/ -{0x04,0x08,0xFC,0x0F,0xFC,0x0F,0x44,0x08,0xE4,0x08,0x0C,0x0C,0x0C,0x0C,0x00,0x00},/*"E",37*/ -{0x04,0x08,0xFC,0x0F,0xFC,0x0F,0x44,0x08,0xE4,0x00,0x0C,0x00,0x0C,0x00,0x00,0x00},/*"F",38*/ -{0xF0,0x03,0xF8,0x07,0x0C,0x0C,0x04,0x08,0x84,0x08,0x8C,0x07,0x98,0x0F,0x00,0x00},/*"G",39*/ -{0xFC,0x0F,0xFC,0x0F,0x40,0x00,0x40,0x00,0x40,0x00,0xFC,0x0F,0xFC,0x0F,0x00,0x00},/*"H",40*/ -{0x00,0x00,0x04,0x08,0x04,0x08,0xFC,0x0F,0xFC,0x0F,0x04,0x08,0x04,0x08,0x00,0x00},/*"I",41*/ -{0x00,0x06,0x00,0x0E,0x00,0x08,0x04,0x08,0xFC,0x0F,0xFC,0x07,0x04,0x00,0x00,0x00},/*"J",42*/ -{0x04,0x08,0xFC,0x0F,0xFC,0x0F,0xE0,0x00,0xB0,0x01,0x1C,0x0F,0x0C,0x0E,0x00,0x00},/*"K",43*/ -{0x04,0x08,0xFC,0x0F,0xFC,0x0F,0x04,0x08,0x00,0x08,0x00,0x0C,0x00,0x0C,0x00,0x00},/*"L",44*/ -{0xFC,0x0F,0xFC,0x0F,0x30,0x00,0xE0,0x00,0xE0,0x00,0x30,0x00,0xFC,0x0F,0xFC,0x0F},/*"M",45*/ -{0xFC,0x0F,0xFC,0x0F,0x30,0x00,0x60,0x00,0xC0,0x00,0xFC,0x0F,0xFC,0x0F,0x00,0x00},/*"N",46*/ -{0xF8,0x07,0xFC,0x0F,0x04,0x08,0x04,0x08,0x04,0x08,0xFC,0x0F,0xF8,0x07,0x00,0x00},/*"O",47*/ -{0x04,0x08,0xFC,0x0F,0xFC,0x0F,0x84,0x08,0x84,0x00,0xFC,0x00,0x78,0x00,0x00,0x00},/*"P",48*/ -{0xF8,0x07,0xFC,0x0F,0x04,0x08,0x04,0x0C,0x04,0x18,0xFC,0x3F,0xF8,0x27,0x00,0x00},/*"Q",49*/ -{0x04,0x08,0xFC,0x0F,0xFC,0x0F,0x44,0x00,0xC4,0x00,0xFC,0x0F,0x38,0x0F,0x00,0x00},/*"R",50*/ -{0x18,0x04,0x3C,0x0C,0x64,0x08,0x44,0x08,0xC4,0x08,0x8C,0x0F,0x08,0x07,0x00,0x00},/*"S",51*/ -{0x0C,0x00,0x0C,0x00,0x04,0x08,0xFC,0x0F,0xFC,0x0F,0x04,0x08,0x0C,0x00,0x0C,0x00},/*"T",52*/ -{0xFC,0x07,0xFC,0x0F,0x00,0x08,0x00,0x08,0x00,0x08,0xFC,0x0F,0xFC,0x07,0x00,0x00},/*"U",53*/ -{0xFC,0x01,0xFC,0x03,0x00,0x06,0x00,0x0C,0x00,0x0C,0x00,0x06,0xFC,0x03,0xFC,0x01},/*"V",54*/ -{0xFC,0x03,0xFC,0x0F,0x00,0x0E,0x80,0x03,0x80,0x03,0x00,0x0E,0xFC,0x0F,0xFC,0x03},/*"W",55*/ -{0x0C,0x0C,0x1C,0x0E,0x30,0x03,0xE0,0x01,0xE0,0x01,0x30,0x03,0x1C,0x0E,0x0C,0x0C},/*"X",56*/ -{0x1C,0x00,0x3C,0x00,0x60,0x08,0xC0,0x0F,0xC0,0x0F,0x60,0x08,0x3C,0x00,0x1C,0x00},/*"Y",57*/ -{0x0C,0x0E,0x0C,0x0F,0x84,0x09,0xC4,0x08,0x64,0x08,0x34,0x08,0x1C,0x0C,0x0C,0x0C},/*"Z",58*/ -{0x00,0x00,0x00,0x00,0xFC,0x0F,0xFC,0x0F,0x04,0x08,0x04,0x08,0x00,0x00,0x00,0x00},/*"[",59*/ -{0x00,0x08,0x00,0x0C,0x00,0x06,0x00,0x03,0x80,0x01,0xC0,0x00,0x60,0x00,0x30,0x00},/*"/",60*/ -{0x00,0x00,0x00,0x00,0x04,0x08,0x04,0x08,0xFC,0x0F,0xFC,0x0F,0x00,0x00,0x00,0x00},/*"]",61*/ -{0x00,0x00,0x10,0x00,0x18,0x00,0x0C,0x00,0x06,0x00,0x0C,0x00,0x18,0x00,0x10,0x00},/*"^",62*/ -{0x00,0x20,0x00,0x20,0x00,0x20,0x00,0x20,0x00,0x20,0x00,0x20,0x00,0x20,0x00,0x20},/*"_",63*/ -{0x00,0x00,0x00,0x00,0x00,0x00,0x06,0x00,0x0E,0x00,0x08,0x00,0x00,0x00,0x00,0x00},/*"`",64*/ -{0x00,0x07,0xA0,0x0F,0xA0,0x08,0xA0,0x08,0xE0,0x07,0xC0,0x0F,0x00,0x08,0x00,0x00},/*"a",65*/ -{0x04,0x08,0xFC,0x0F,0xFC,0x07,0x20,0x08,0x60,0x08,0xC0,0x0F,0x80,0x07,0x00,0x00},/*"b",66*/ -{0xC0,0x07,0xE0,0x0F,0x20,0x08,0x20,0x08,0x20,0x08,0x60,0x0C,0x40,0x04,0x00,0x00},/*"c",67*/ -{0x80,0x07,0xC0,0x0F,0x60,0x08,0x24,0x08,0xFC,0x07,0xFC,0x0F,0x00,0x08,0x00,0x00},/*"d",68*/ -{0xC0,0x07,0xE0,0x0F,0x20,0x09,0x20,0x09,0x20,0x09,0xE0,0x0D,0xC0,0x05,0x00,0x00},/*"e",69*/ -{0x00,0x00,0x40,0x08,0xF8,0x0F,0xFC,0x0F,0x44,0x08,0x4C,0x00,0x08,0x00,0x00,0x00},/*"f",70*/ -{0xC0,0x27,0xE0,0x6F,0x20,0x48,0x20,0x48,0xC0,0x7F,0xE0,0x3F,0x20,0x00,0x00,0x00},/*"g",71*/ -{0x04,0x08,0xFC,0x0F,0xFC,0x0F,0x40,0x00,0x20,0x00,0xE0,0x0F,0xC0,0x0F,0x00,0x00},/*"h",72*/ -{0x00,0x00,0x00,0x00,0x20,0x08,0xEC,0x0F,0xEC,0x0F,0x00,0x08,0x00,0x00,0x00,0x00},/*"i",73*/ -{0x00,0x00,0x00,0x20,0x00,0x60,0x00,0x40,0x20,0x40,0xEC,0x7F,0xEC,0x3F,0x00,0x00},/*"j",74*/ -{0x04,0x08,0xFC,0x0F,0xFC,0x0F,0x80,0x01,0xC0,0x03,0x60,0x0E,0x20,0x0C,0x00,0x00},/*"k",75*/ -{0x00,0x00,0x00,0x00,0x04,0x08,0xFC,0x0F,0xFC,0x0F,0x00,0x08,0x00,0x00,0x00,0x00},/*"l",76*/ -{0xE0,0x0F,0xE0,0x0F,0x60,0x00,0xC0,0x07,0xC0,0x07,0x60,0x00,0xE0,0x0F,0xC0,0x0F},/*"m",77*/ -{0x20,0x00,0xE0,0x0F,0xC0,0x0F,0x20,0x00,0x20,0x00,0xE0,0x0F,0xC0,0x0F,0x00,0x00},/*"n",78*/ -{0xC0,0x07,0xE0,0x0F,0x20,0x08,0x20,0x08,0x20,0x08,0xE0,0x0F,0xC0,0x07,0x00,0x00},/*"o",79*/ -{0x20,0x40,0xE0,0x7F,0xC0,0x7F,0x20,0x48,0x20,0x08,0xE0,0x0F,0xC0,0x07,0x00,0x00},/*"p",80*/ -{0xC0,0x07,0xE0,0x0F,0x20,0x08,0x20,0x48,0xC0,0x7F,0xE0,0x7F,0x20,0x40,0x00,0x00},/*"q",81*/ -{0x20,0x08,0xE0,0x0F,0xC0,0x0F,0x60,0x08,0x20,0x00,0x60,0x00,0x40,0x00,0x00,0x00},/*"r",82*/ -{0xC0,0x04,0xE0,0x0D,0x20,0x09,0x20,0x09,0x20,0x09,0x60,0x0F,0x40,0x06,0x00,0x00},/*"s",83*/ -{0x20,0x00,0x20,0x00,0xF8,0x07,0xFC,0x0F,0x20,0x08,0x20,0x0C,0x00,0x04,0x00,0x00},/*"t",84*/ -{0xE0,0x07,0xE0,0x0F,0x00,0x08,0x00,0x08,0xE0,0x07,0xE0,0x0F,0x00,0x08,0x00,0x00},/*"u",85*/ -{0xE0,0x01,0xE0,0x03,0x00,0x06,0x00,0x0C,0x00,0x0C,0x00,0x06,0xE0,0x03,0xE0,0x01},/*"v",86*/ -{0xE0,0x07,0xE0,0x0F,0x00,0x0C,0x00,0x07,0x00,0x07,0x00,0x0C,0xE0,0x0F,0xE0,0x07},/*"w",87*/ -{0x20,0x08,0x60,0x0C,0xC0,0x06,0x80,0x03,0x80,0x03,0xC0,0x06,0x60,0x0C,0x20,0x08},/*"x",88*/ -{0xE0,0x47,0xE0,0x4F,0x00,0x48,0x00,0x48,0x00,0x68,0xE0,0x3F,0xE0,0x1F,0x00,0x00},/*"y",89*/ -{0x60,0x0C,0x60,0x0E,0x20,0x0B,0xA0,0x09,0xE0,0x08,0x60,0x0C,0x20,0x0C,0x00,0x00},/*"z",90*/ -{0x00,0x00,0x40,0x00,0x40,0x00,0xF8,0x07,0xBC,0x0F,0x04,0x08,0x04,0x08,0x00,0x00},/*"{",91*/ -{0x00,0x00,0x00,0x00,0x00,0x00,0x7C,0x1F,0x7C,0x1F,0x00,0x00,0x00,0x00,0x00,0x00},/*"|",92*/ -{0x00,0x00,0x04,0x08,0x04,0x08,0xBC,0x0F,0xF8,0x07,0x40,0x00,0x40,0x00,0x00,0x00},/*"}",93*/ -}; - const PROGMEM unsigned char font8x16_terminal[][16] = { {0x00,0x00,0x00,0x00,0x7C,0x00,0xFE,0x1B,0xFE,0x1B,0x7C,0x00,0x00,0x00,0x00,0x00},/*"!",0*/ {0x00,0x00,0x0E,0x00,0x1E,0x00,0x00,0x00,0x00,0x00,0x1E,0x00,0x0E,0x00,0x00,0x00},/*""",1*/ @@ -330,5 +243,457 @@ const PROGMEM unsigned char font8x16_terminal[][16] = { {0x00,0x00,0x00,0x00,0x00,0x00,0x7C,0x3E,0x7C,0x3E,0x00,0x00,0x00,0x00,0x00,0x00},/*"|",92*/ {0x00,0x00,0x02,0x20,0x02,0x20,0x7E,0x3F,0xFC,0x1F,0x80,0x00,0x00,0x00,0x00,0x00},/*"}",93*/ }; +#endif + +void LCD_Common::printInt(unsigned int value, char padding) +{ + unsigned int den = 10000; + for (byte i = 5; i > 0; i--) { + byte v = (byte)(value / den); + value -= v * den; + den /= 10; + if (v == 0 && padding && den) { + if (padding >= i) { + writeDigit((m_flags & FLAG_PAD_ZERO) ? 0 : -1); + } + continue; + } + padding = 0; + writeDigit(v); + } +} + +void LCD_Common::printLong(unsigned long value, char padding) +{ + unsigned long den = 1000000000; + for (byte i = 10; i > 0; i--) { + byte v = (byte)(value / den); + value -= v * den; + den /= 10; + if (v == 0 && padding && den) { + if (padding >= i) { + writeDigit((m_flags & FLAG_PAD_ZERO) ? 0 : -1); + } + continue; + } + padding = 0; + writeDigit(v); + } +} + +void LCD_SSD1306::setCursor(byte column, byte line) +{ + m_col = column; + m_row = line; + 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 +} + +size_t LCD_SSD1306::write(uint8_t c) +{ + if (c == '\n') { + setCursor(0, m_row + ((m_font == FONT_SIZE_SMALL) ? 1 : 2)); + return 1; + } else if (c == '\r') { + m_col = 0; + return 1; + } +#ifndef MEMORY_SAVING + if (m_font == FONT_SIZE_SMALL) { +#endif + Wire.beginTransmission(_i2caddr); + Wire.write(0x40); + if (c > 0x20 && c < 0x7f) { + c -= 0x21; + for (byte i = 0; i < 5; i++) { + byte d = pgm_read_byte_near(&font5x8[c][i]); + Wire.write(d); + if (m_flags & FLAG_PIXEL_DOUBLE_H) Wire.write(d); + } + Wire.write(0); + } else { + for (byte i = (m_flags & FLAG_PIXEL_DOUBLE_H) ? 11 : 6; i > 0; i--) { + Wire.write(0); + } + } + Wire.endTransmission(); + m_col += (m_flags & FLAG_PIXEL_DOUBLE_H) ? 11 : 6; + if (m_col >= 128) { + m_col = 0; + m_row ++; + } +#ifndef MEMORY_SAVING + } else { + if (c > 0x20 && c < 0x7f) { + c -= 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 (byte i = 0; i <= 14; i += 2) { + byte d = pgm_read_byte_near(&font8x16_terminal[c][i]); + Wire.write(d); + if (m_flags & FLAG_PIXEL_DOUBLE_H) Wire.write(d); + } + Wire.endTransmission(); + + ssd1306_command(0xB0 + m_row + 1);//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 = 1; i <= 15; i += 2) { + byte d = pgm_read_byte_near(&font8x16_terminal[c][i]); + Wire.write(d); + if (m_flags & FLAG_PIXEL_DOUBLE_H) Wire.write(d); + } + Wire.endTransmission(); + } else { + 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 = (m_flags & FLAG_PIXEL_DOUBLE_H) ? 16 : 8; i > 0; i--) { + Wire.write(0); + } + Wire.endTransmission(); + + ssd1306_command(0xB0 + m_row + 1);//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) ? 16 : 8; i > 0; i--) { + Wire.write(0); + } + Wire.endTransmission(); + } + m_col += (m_flags & FLAG_PIXEL_DOUBLE_H) ? 17 : 9; + if (m_col >= 128) { + m_col = 0; + m_row += 2; + } + } +#endif + return 1; +} + +void LCD_SSD1306::writeDigit(byte n) +{ + uint8_t twbrbackup = TWBR; + TWBR = 18; // upgrade to 400KHz! + if (m_font == FONT_SIZE_SMALL) { + Wire.beginTransmission(_i2caddr); + Wire.write(0x40); + if (n <= 9) { + n += '0' - 0x21; + for (byte i = 0; i < 5; i++) { + Wire.write(pgm_read_byte_near(&font5x8[n][i])); + } + Wire.write(0); + } else { + for (byte i = 0; i < 6; i++) { + Wire.write(0); + } + } + Wire.endTransmission(); + m_col += 6; + } else if (m_font == FONT_SIZE_MEDIUM) { +#ifndef MEMORY_SAVING + if (n <= 9) { + 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 (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); + } + Wire.endTransmission(); + + ssd1306_command(0xB0 + m_row + 1);//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 = 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); + } + Wire.endTransmission(); + } else { + 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 = (m_flags & FLAG_PIXEL_DOUBLE_H) ? 16 : 8; i > 0; i--) { + Wire.write(0); + } + Wire.endTransmission(); + + ssd1306_command(0xB0 + m_row + 1);//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) ? 16 : 8; 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++) { + Wire.write(0); + } + } + Wire.endTransmission(); + m_col += 8; #endif + } else if (m_font == FONT_SIZE_LARGE) { + if (n <= 9) { + 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 (i = 0; i < 16; i ++) { + byte d = pgm_read_byte_near(&digits16x16[n][i]); + Wire.write(d); + if (m_flags & FLAG_PIXEL_DOUBLE_H) Wire.write(d); + } + Wire.endTransmission(); + + ssd1306_command(0xB0 + m_row + 1);//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 < 32; i ++) { + byte d = pgm_read_byte_near(&digits16x16[n][i]); + Wire.write(d); + if (m_flags & FLAG_PIXEL_DOUBLE_H) Wire.write(d); + } + Wire.endTransmission(); + } else { + 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 = (m_flags & FLAG_PIXEL_DOUBLE_H) ? 32 : 16; i > 0; i--) { + Wire.write(0); + } + Wire.endTransmission(); + + ssd1306_command(0xB0 + m_row + 1);//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(); + } + m_col += (m_flags & FLAG_PIXEL_DOUBLE_H) ? 30 : 16; + } else if (m_font == FONT_SIZE_XLARGE) { + if (n <= 9) { + 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 (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); + } + Wire.endTransmission(); + + ssd1306_command(0xB0 + m_row + 1);//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 + 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); + } + Wire.endTransmission(); + } else { + 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 = (m_flags & FLAG_PIXEL_DOUBLE_H) ? 32 : 16; i > 0; i--) { + Wire.write(0); + } + Wire.endTransmission(); + + ssd1306_command(0xB0 + m_row + 1);//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(); + + 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(); + } + m_col += (m_flags & FLAG_PIXEL_DOUBLE_H) ? 30 : 16; + } + TWBR = twbrbackup; +} + +void LCD_SSD1306::draw(const PROGMEM byte* buffer, byte x, byte y, byte width, byte height) +{ + ssd1306_command(SSD1306_SETLOWCOLUMN | 0x0); // low col = 0 + 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; + y >>= 3; + for (byte i = 0; i < height; i++) { + // send a bunch of data in one xmission + ssd1306_command(0xB0 + i + y);//set page address + ssd1306_command(x & 0xf);//set lower column address + ssd1306_command(0x10 | (x >> 4));//set higher column address + + for(byte j = 0; j < 8; j++){ + Wire.beginTransmission(_i2caddr); + Wire.write(0x40); + for (byte k = 0; k < width; k++, p++) { + Wire.write(pgm_read_byte_near(p)); + } + Wire.endTransmission(); + } + } + TWBR = twbrbackup; +} + +void LCD_SSD1306::clearLine(byte line) +{ + ssd1306_command(SSD1306_SETLOWCOLUMN | 0x0); // low col = 0 + 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! + + // send a bunch of data in one xmission + ssd1306_command(0xB0 + line);//set page address + ssd1306_command(0);//set lower column address + ssd1306_command(0x10);//set higher column address + + for(byte j = 0; j < 8; j++){ + Wire.beginTransmission(_i2caddr); + Wire.write(0x40); + for (byte k = 0; k < 16; k++) { + Wire.write(0); + } + Wire.endTransmission(); + } + + TWBR = twbrbackup; +} + +void LCD_SSD1306::clear(byte x, byte y, byte width, byte height) +{ + ssd1306_command(SSD1306_SETLOWCOLUMN | 0x0); // low col = 0 + 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; + for (byte i = 0; i < height; i++) { + // send a bunch of data in one xmission + ssd1306_command(0xB0 + i + y);//set page address + ssd1306_command(x & 0xf);//set lower column address + ssd1306_command(0x10 | (x >> 4));//set higher column address + + for(byte j = 0; j < 8; j++){ + Wire.beginTransmission(_i2caddr); + Wire.write(0x40); + for (byte k = 0; k < width; k++) { + Wire.write(0); + } + Wire.endTransmission(); + } + } + + setCursor(0, 0); + TWBR = twbrbackup; +} diff --git a/obdlogger/MultiLCD.h b/obdlogger/MicroLCD.h index 1206414..1206414 100644 --- a/obdlogger/MultiLCD.h +++ b/obdlogger/MicroLCD.h diff --git a/obdlogger/MultiLCD.cpp b/obdlogger/MultiLCD.cpp deleted file mode 100644 index 1e675fe..0000000 --- a/obdlogger/MultiLCD.cpp +++ /dev/null @@ -1,463 +0,0 @@ -/************************************************************************* -* Arduino Text Display Library for Multiple LCDs -* Distributed under GPL v2.0 -* Copyright (c) 2013 Stanley Huang <stanleyhuangyc@live.com> -* All rights reserved. -*************************************************************************/ - -#include <Arduino.h> -#include <Wire.h> -#include "MultiLCD.h" - -void LCD_Common::printInt(unsigned int value, char padding) -{ - unsigned int den = 10000; - for (byte i = 5; i > 0; i--) { - byte v = (byte)(value / den); - value -= v * den; - den /= 10; - if (v == 0 && padding && den) { - if (padding >= i) { - writeDigit((m_flags & FLAG_PAD_ZERO) ? 0 : -1); - } - continue; - } - padding = 0; - writeDigit(v); - } -} - -void LCD_Common::printLong(unsigned long value, char padding) -{ - unsigned long den = 1000000000; - for (byte i = 10; i > 0; i--) { - byte v = (byte)(value / den); - value -= v * den; - den /= 10; - if (v == 0 && padding && den) { - if (padding >= i) { - writeDigit((m_flags & FLAG_PAD_ZERO) ? 0 : -1); - } - continue; - } - padding = 0; - writeDigit(v); - } -} - -void LCD_SSD1306::setCursor(byte column, byte line) -{ - m_col = column; - m_row = line; - 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 -} - -size_t LCD_SSD1306::write(uint8_t c) -{ - if (c == '\n') { - setCursor(0, m_row + ((m_font == FONT_SIZE_SMALL) ? 1 : 2)); - return 1; - } else if (c == '\r') { - m_col = 0; - return 1; - } -#ifndef MEMORY_SAVING - if (m_font == FONT_SIZE_SMALL) { -#endif - Wire.beginTransmission(_i2caddr); - Wire.write(0x40); - if (c > 0x20 && c < 0x7f) { - c -= 0x21; - for (byte i = 0; i < 5; i++) { - byte d = pgm_read_byte_near(&font5x8[c][i]); - Wire.write(d); - if (m_flags & FLAG_PIXEL_DOUBLE_H) Wire.write(d); - } - Wire.write(0); - } else { - for (byte i = (m_flags & FLAG_PIXEL_DOUBLE_H) ? 11 : 6; i > 0; i--) { - Wire.write(0); - } - } - Wire.endTransmission(); - m_col += (m_flags & FLAG_PIXEL_DOUBLE_H) ? 11 : 6; - if (m_col >= 128) { - m_col = 0; - m_row ++; - } -#ifndef MEMORY_SAVING - } else { - if (c > 0x20 && c < 0x7f) { - c -= 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 (byte i = 0; i <= 14; i += 2) { - byte d = pgm_read_byte_near(&font8x16_terminal[c][i]); - Wire.write(d); - if (m_flags & FLAG_PIXEL_DOUBLE_H) Wire.write(d); - } - Wire.endTransmission(); - - ssd1306_command(0xB0 + m_row + 1);//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 = 1; i <= 15; i += 2) { - byte d = pgm_read_byte_near(&font8x16_terminal[c][i]); - Wire.write(d); - if (m_flags & FLAG_PIXEL_DOUBLE_H) Wire.write(d); - } - Wire.endTransmission(); - } else { - 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 = (m_flags & FLAG_PIXEL_DOUBLE_H) ? 16 : 8; i > 0; i--) { - Wire.write(0); - } - Wire.endTransmission(); - - ssd1306_command(0xB0 + m_row + 1);//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) ? 16 : 8; i > 0; i--) { - Wire.write(0); - } - Wire.endTransmission(); - } - m_col += (m_flags & FLAG_PIXEL_DOUBLE_H) ? 17 : 9; - if (m_col >= 128) { - m_col = 0; - m_row += 2; - } - } -#endif - return 1; -} - -void LCD_SSD1306::writeDigit(byte n) -{ - uint8_t twbrbackup = TWBR; - TWBR = 18; // upgrade to 400KHz! - if (m_font == FONT_SIZE_SMALL) { - Wire.beginTransmission(_i2caddr); - Wire.write(0x40); - if (n <= 9) { - n += '0' - 0x21; - for (byte i = 0; i < 5; i++) { - Wire.write(pgm_read_byte_near(&font5x8[n][i])); - } - Wire.write(0); - } else { - for (byte i = 0; i < 6; i++) { - Wire.write(0); - } - } - Wire.endTransmission(); - m_col += 6; - } else if (m_font == FONT_SIZE_MEDIUM) { -#ifndef MEMORY_SAVING - if (n <= 9) { - 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 (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); - } - Wire.endTransmission(); - - ssd1306_command(0xB0 + m_row + 1);//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 = 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); - } - Wire.endTransmission(); - } else { - 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 = (m_flags & FLAG_PIXEL_DOUBLE_H) ? 16 : 8; i > 0; i--) { - Wire.write(0); - } - Wire.endTransmission(); - - ssd1306_command(0xB0 + m_row + 1);//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) ? 16 : 8; 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++) { - Wire.write(0); - } - } - Wire.endTransmission(); - m_col += 8; -#endif - } else if (m_font == FONT_SIZE_LARGE) { - if (n <= 9) { - 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 (i = 0; i < 16; i ++) { - byte d = pgm_read_byte_near(&digits16x16[n][i]); - Wire.write(d); - if (m_flags & FLAG_PIXEL_DOUBLE_H) Wire.write(d); - } - Wire.endTransmission(); - - ssd1306_command(0xB0 + m_row + 1);//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 < 32; i ++) { - byte d = pgm_read_byte_near(&digits16x16[n][i]); - Wire.write(d); - if (m_flags & FLAG_PIXEL_DOUBLE_H) Wire.write(d); - } - Wire.endTransmission(); - } else { - 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 = (m_flags & FLAG_PIXEL_DOUBLE_H) ? 32 : 16; i > 0; i--) { - Wire.write(0); - } - Wire.endTransmission(); - - ssd1306_command(0xB0 + m_row + 1);//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(); - } - m_col += (m_flags & FLAG_PIXEL_DOUBLE_H) ? 30 : 16; - } else if (m_font == FONT_SIZE_XLARGE) { - if (n <= 9) { - 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 (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); - } - Wire.endTransmission(); - - ssd1306_command(0xB0 + m_row + 1);//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 + 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); - } - Wire.endTransmission(); - } else { - 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 = (m_flags & FLAG_PIXEL_DOUBLE_H) ? 32 : 16; i > 0; i--) { - Wire.write(0); - } - Wire.endTransmission(); - - ssd1306_command(0xB0 + m_row + 1);//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(); - - 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(); - } - m_col += (m_flags & FLAG_PIXEL_DOUBLE_H) ? 30 : 16; - } - TWBR = twbrbackup; -} - -void LCD_SSD1306::draw(const PROGMEM byte* buffer, byte x, byte y, byte width, byte height) -{ - ssd1306_command(SSD1306_SETLOWCOLUMN | 0x0); // low col = 0 - 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; - y >>= 3; - for (byte i = 0; i < height; i++) { - // send a bunch of data in one xmission - ssd1306_command(0xB0 + i + y);//set page address - ssd1306_command(x & 0xf);//set lower column address - ssd1306_command(0x10 | (x >> 4));//set higher column address - - for(byte j = 0; j < 8; j++){ - Wire.beginTransmission(_i2caddr); - Wire.write(0x40); - for (byte k = 0; k < width; k++, p++) { - Wire.write(pgm_read_byte_near(p)); - } - Wire.endTransmission(); - } - } - TWBR = twbrbackup; -} - -void LCD_SSD1306::clearLine(byte line) -{ - ssd1306_command(SSD1306_SETLOWCOLUMN | 0x0); // low col = 0 - 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! - - // send a bunch of data in one xmission - ssd1306_command(0xB0 + line);//set page address - ssd1306_command(0);//set lower column address - ssd1306_command(0x10);//set higher column address - - for(byte j = 0; j < 8; j++){ - Wire.beginTransmission(_i2caddr); - Wire.write(0x40); - for (byte k = 0; k < 16; k++) { - Wire.write(0); - } - Wire.endTransmission(); - } - - TWBR = twbrbackup; -} - -void LCD_SSD1306::clear(byte x, byte y, byte width, byte height) -{ - ssd1306_command(SSD1306_SETLOWCOLUMN | 0x0); // low col = 0 - 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; - for (byte i = 0; i < height; i++) { - // send a bunch of data in one xmission - ssd1306_command(0xB0 + i + y);//set page address - ssd1306_command(x & 0xf);//set lower column address - ssd1306_command(0x10 | (x >> 4));//set higher column address - - for(byte j = 0; j < 8; j++){ - Wire.beginTransmission(_i2caddr); - Wire.write(0x40); - for (byte k = 0; k < width; k++) { - Wire.write(0); - } - Wire.endTransmission(); - } - } - - setCursor(0, 0); - TWBR = twbrbackup; -} diff --git a/obdlogger/obdlogger.ino b/obdlogger/obdlogger.ino index 12eb7bf..ac16184 100644 --- a/obdlogger/obdlogger.ino +++ b/obdlogger/obdlogger.ino @@ -12,7 +12,7 @@ #include <TinyGPS.h> #include <MPU6050.h> #include <SoftwareSerial.h> -#include "MultiLCD.h" +#include "MicroLCD.h" #include "images.h" #include "datalogger.h" |