Skip to content
Snippets Groups Projects
Commit cc47fdcb authored by Fabrice Weinberg's avatar Fabrice Weinberg
Browse files

Merge with update stream

parent 5554319b
No related branches found
No related tags found
No related merge requests found
......@@ -119,7 +119,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;
......@@ -212,6 +245,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++) {
......@@ -259,7 +293,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);
}
}
......@@ -316,4 +350,4 @@ void SSD1306::sendInitCommands(void) {
sendCommand(NORMALDISPLAY);
sendCommand(0x2e); // stop scroll
sendCommand(DISPLAYON);
}
}
\ No newline at end of file
......@@ -79,6 +79,7 @@ private:
uint8_t buffer[128 * 64 / 8];
int myTextAlignment = TEXT_ALIGN_LEFT;
int myColor = WHITE;
byte lastChar;
const char *myFontData = ArialMT_Plain_10;
public:
......@@ -139,6 +140,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);
......@@ -161,4 +170,4 @@ public:
// ArialMT_Plain_10, ArialMT_Plain_16, ArialMT_Plain_24
void setFont(const char *fontData);
};
};
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment