@@ -119,7 +119,40 @@ void SSD1306::setChar(int x, int y, unsigned char data) {
119119 }
120120}
121121
122+ // Code form http://playground.arduino.cc/Main/Utf8ascii
123+ byte SSD1306::utf8ascii (byte ascii) {
124+ if ( ascii<128 ) { // Standard ASCII-set 0..0x7F handling
125+ lastChar=0 ;
126+ return ( ascii );
127+ }
128+
129+ // get previous input
130+ byte last = lastChar; // get last char
131+ lastChar=ascii; // remember actual character
132+
133+ switch (last) // conversion depnding on first UTF8-character
134+ { case 0xC2 : return (ascii); break ;
135+ case 0xC3 : return (ascii | 0xC0 ); break ;
136+ case 0x82 : if (ascii==0xAC ) return (0x80 ); // special case Euro-symbol
137+ }
138+
139+ return (0 ); // otherwise: return zero, if character has to be ignored
140+ }
141+
142+ // Code form http://playground.arduino.cc/Main/Utf8ascii
143+ String SSD1306::utf8ascii (String s) {
144+ String r= " " ;
145+ char c;
146+ for (int i=0 ; i<s.length (); i++)
147+ {
148+ c = utf8ascii (s.charAt (i));
149+ if (c!=0 ) r+=c;
150+ }
151+ return r;
152+ }
153+
122154void SSD1306::drawString (int x, int y, String text) {
155+ text = utf8ascii (text);
123156 unsigned char currentByte;
124157 int charX, charY;
125158 int currentBitCount;
@@ -212,6 +245,7 @@ void SSD1306::drawStringMaxWidth(int x, int y, int maxLineWidth, String text) {
212245}
213246
214247int SSD1306::getStringWidth (String text) {
248+ text = utf8ascii (text);
215249 int stringWidth = 0 ;
216250 char charCode;
217251 for (int j=0 ; j < text.length (); j++) {
@@ -259,7 +293,7 @@ void SSD1306::drawRect(int x, int y, int width, int height) {
259293
260294void SSD1306::fillRect (int x, int y, int width, int height) {
261295 for (int i = x; i < x + width; i++) {
262- for (int j = 0 ; j < y + height; j++) {
296+ for (int j = y ; j < y + height; j++) {
263297 setPixel (i, j);
264298 }
265299 }
@@ -316,4 +350,4 @@ void SSD1306::sendInitCommands(void) {
316350 sendCommand (NORMALDISPLAY);
317351 sendCommand (0x2e ); // stop scroll
318352 sendCommand (DISPLAYON);
319- }
353+ }
0 commit comments