diff --git a/library.properties b/library.properties index defc41ec7c6bee89c3d9809d05eae87f68778dd9..6ffce0178c05c2aafd63b29980eb7e7bd410bac6 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=ESP8266 Oled Driver for SSD1306 display -version=1.0.1 +version=1.0.2 author=Daniel Eichhorn maintainer=Daniel Eichhorn <squix78@gmail.com> sentence=A display driver for SSD1306 oled displays connected to an ESP8266 diff --git a/ssd1306_i2c.cpp b/ssd1306_i2c.cpp index 77f4866790d2d9a0cbff3c1d0f67ab55eee1ce61..37c628cb33d9d85f2107c42b1e0d31225f48227f 100644 --- a/ssd1306_i2c.cpp +++ b/ssd1306_i2c.cpp @@ -88,6 +88,7 @@ void SSD1306::display(void) { sendCommand(0x0); sendCommand(0x7); + for (uint16_t i=0; i<(128*64/8); i++) { // send a bunch of data in one xmission //Wire.begin(mySda, mySdc); @@ -101,6 +102,7 @@ void SSD1306::display(void) { yield(); Wire.endTransmission(); } + } @@ -124,7 +126,40 @@ void SSD1306::setChar(int x, int y, unsigned char data) { } } +// Code form http://playground.arduino.cc/Main/Utf8ascii +byte SSD1306::utf8ascii(byte ascii) { + if ( ascii<128 ) // Standard ASCII-set 0..0x7F handling + { lastChar=0; + return( ascii ); + } + + // get previous input + byte last = lastChar; // get last char + lastChar=ascii; // remember actual character + + switch (last) // conversion depnding on first UTF8-character + { case 0xC2: return (ascii); break; + case 0xC3: return (ascii | 0xC0); break; + case 0x82: if(ascii==0xAC) return(0x80); // special case Euro-symbol + } + + return (0); // otherwise: return zero, if character has to be ignored +} + +// Code form http://playground.arduino.cc/Main/Utf8ascii +String SSD1306::utf8ascii(String s) { + String r= ""; + char c; + for (int i=0; i<s.length(); i++) + { + c = utf8ascii(s.charAt(i)); + if (c!=0) r+=c; + } + return r; +} + void SSD1306::drawString(int x, int y, String text) { + text = utf8ascii(text); unsigned char currentByte; int charX, charY; int currentBitCount; @@ -219,6 +254,7 @@ void SSD1306::drawStringMaxWidth(int x, int y, int maxLineWidth, String text) { } int SSD1306::getStringWidth(String text) { + text = utf8ascii(text); int stringWidth = 0; char charCode; for (int j=0; j < text.length(); j++) { @@ -266,7 +302,7 @@ void SSD1306::drawRect(int x, int y, int width, int height) { void SSD1306::fillRect(int x, int y, int width, int height) { for (int i = x; i < x + width; i++) { - for (int j = 0; j < y + height; j++) { + for (int j = y; j < y + height; j++) { setPixel(i, j); } } diff --git a/ssd1306_i2c.h b/ssd1306_i2c.h index 59cbb74598a2baf2ae74c300c87474694544da5b..078868cbd3ea2c68b5e4a04dde042e8c7e965de2 100644 --- a/ssd1306_i2c.h +++ b/ssd1306_i2c.h @@ -96,6 +96,7 @@ private: int myFrameTransitionTicks = 25; int myTextAlignment = TEXT_ALIGN_LEFT; int myColor = WHITE; + byte lastChar; const char *myFontData = ArialMT_Plain_10; void (**myFrameCallbacks)(int x, int y); @@ -159,6 +160,14 @@ public: // Sets the color of all pixel operations void setColor(int color); + // converts utf8 characters to extended ascii + // taken from http://playground.arduino.cc/Main/Utf8ascii + byte utf8ascii(byte ascii); + + // converts utf8 string to extended ascii + // taken from http://playground.arduino.cc/Main/Utf8ascii + String utf8ascii(String s); + // Draws a string at the given location void drawString(int x, int y, String text);