diff options
author | Jan Krupička <[email protected]> | 2017-12-12 01:14:16 +0100 |
---|---|---|
committer | Ben V. Brown <[email protected]> | 2017-12-12 11:14:16 +1100 |
commit | 1447b1cad859b3e8e3c303d0674a21804bddf305 (patch) | |
tree | d058cd4bf48ebc6630a1936ae5a93227caba6772 | |
parent | d03443e783fe04323c34c5ac8ae1fb65f2935f1c (diff) | |
download | IronOS-1447b1cad859b3e8e3c303d0674a21804bddf305.tar.gz IronOS-1447b1cad859b3e8e3c303d0674a21804bddf305.zip |
Fix oled draw c2 section (#147)
* format
* compensate for chars excluded from font
fixes #146
* added comment to explain magic 32
consolidate whitespaces in this method (really spaces should be used everywhere instead of tabs (exception for makefile) )
-rw-r--r-- | workspace/TS100/src/OLED.cpp | 75 |
1 files changed, 40 insertions, 35 deletions
diff --git a/workspace/TS100/src/OLED.cpp b/workspace/TS100/src/OLED.cpp index 8945f37a..e81f5286 100644 --- a/workspace/TS100/src/OLED.cpp +++ b/workspace/TS100/src/OLED.cpp @@ -93,43 +93,48 @@ void OLED::refresh() { } +/* + * Prints a char to the screen. + * UTF font handling is done using the two input chars. + * Precursor is the command char that is used to select the table. + */ void OLED::drawChar(char c, char PrecursorCommand) { -//prints a char to the screen - if (c < ' ') - return; - //We are left with - uint8_t* charPointer; - //Fonts are offset to start at the space char. - /* - * UTF font handling is done using the two input chars - * Precursor is the command char that is used to select the table - * - */ - uint16_t index = 0; - if (PrecursorCommand == 0) - index = (c - ' '); - else { - - //This is for extended range - //We decode the precursor command to find the offset - //Latin stats at 96 - c -= 0x80; - if (PrecursorCommand == 0xC3) - index = (128) + (c); - else if (PrecursorCommand == 0xC2) - index = (96) + (c); - else if (PrecursorCommand == 0xD0) - index = (192) + (c); - else if (PrecursorCommand == 0xD1) - index = (256) + (c); - else - return; - } - charPointer = ((uint8_t*) currentFont) + ((fontWidth * (fontHeight / 8)) * index); + if (c < ' ') { + return; + } + + //We are left with + uint8_t* charPointer; + + uint16_t index = 0; + if (PrecursorCommand == 0) { + //Fonts are offset to start at the space char + index = (c - ' '); + } + else { + //This is for extended range + //We decode the precursor command to find the offset + //Latin starts at 96 + c -= 0x80; + + switch (PrecursorCommand) { + + case 0xC2: index = (96 - 32) + (c); break; //-32 compensate for chars excluded from font C2 section + case 0xC3: index = (128) + (c); break; + case 0xD0: index = (192) + (c); break; + case 0xD1: index = (256) + (c); break; + + default: return; + } + } + + charPointer = ((uint8_t*) currentFont) + ((fontWidth * (fontHeight / 8)) * index); + + if (cursor_x >= 0 && cursor_x < 96) { + drawArea(cursor_x, cursor_y, fontWidth, fontHeight, charPointer); + } - if (cursor_x >= 0 && cursor_x < 96) - drawArea(cursor_x, cursor_y, fontWidth, fontHeight, charPointer); - cursor_x += fontWidth; + cursor_x += fontWidth; } void OLED::displayOnOff(bool on) { |