@@ -88,6 +88,7 @@ void SSD1306::display(void) {
8888 sendCommand (0x0 );
8989 sendCommand (0x7 );
9090
91+
9192 for (uint16_t i=0 ; i<(128 *64 /8 ); i++) {
9293 // send a bunch of data in one xmission
9394 // Wire.begin(mySda, mySdc);
@@ -101,6 +102,7 @@ void SSD1306::display(void) {
101102 yield ();
102103 Wire.endTransmission ();
103104 }
105+
104106
105107
106108}
@@ -124,7 +126,40 @@ void SSD1306::setChar(int x, int y, unsigned char data) {
124126 }
125127}
126128
129+ // Code form http://playground.arduino.cc/Main/Utf8ascii
130+ byte SSD1306::utf8ascii (byte ascii) {
131+ if ( ascii<128 ) // Standard ASCII-set 0..0x7F handling
132+ { lastChar=0 ;
133+ return ( ascii );
134+ }
135+
136+ // get previous input
137+ byte last = lastChar; // get last char
138+ lastChar=ascii; // remember actual character
139+
140+ switch (last) // conversion depnding on first UTF8-character
141+ { case 0xC2 : return (ascii); break ;
142+ case 0xC3 : return (ascii | 0xC0 ); break ;
143+ case 0x82 : if (ascii==0xAC ) return (0x80 ); // special case Euro-symbol
144+ }
145+
146+ return (0 ); // otherwise: return zero, if character has to be ignored
147+ }
148+
149+ // Code form http://playground.arduino.cc/Main/Utf8ascii
150+ String SSD1306::utf8ascii (String s) {
151+ String r= " " ;
152+ char c;
153+ for (int i=0 ; i<s.length (); i++)
154+ {
155+ c = utf8ascii (s.charAt (i));
156+ if (c!=0 ) r+=c;
157+ }
158+ return r;
159+ }
160+
127161void SSD1306::drawString (int x, int y, String text) {
162+ text = utf8ascii (text);
128163 unsigned char currentByte;
129164 int charX, charY;
130165 int currentBitCount;
@@ -219,6 +254,7 @@ void SSD1306::drawStringMaxWidth(int x, int y, int maxLineWidth, String text) {
219254}
220255
221256int SSD1306::getStringWidth (String text) {
257+ text = utf8ascii (text);
222258 int stringWidth = 0 ;
223259 char charCode;
224260 for (int j=0 ; j < text.length (); j++) {
@@ -266,7 +302,7 @@ void SSD1306::drawRect(int x, int y, int width, int height) {
266302
267303void SSD1306::fillRect (int x, int y, int width, int height) {
268304 for (int i = x; i < x + width; i++) {
269- for (int j = 0 ; j < y + height; j++) {
305+ for (int j = y ; j < y + height; j++) {
270306 setPixel (i, j);
271307 }
272308 }
0 commit comments