ThingPulse OLED SSD1306
Dependents: Turtle_RadioShuttle mbed-os5-F303-18650-Manager-tp4056 Kretanje_kroz_izbornike_OLED128x64_4tipke
Diff: OLEDDisplay.cpp
- Revision:
- 2:4ed55dfe5be7
- Parent:
- 1:9270c15c6aea
- Child:
- 3:99a409809366
--- a/OLEDDisplay.cpp Sun Apr 14 18:00:54 2019 +0200 +++ b/OLEDDisplay.cpp Wed May 29 11:17:58 2019 +0200 @@ -42,7 +42,7 @@ displayWidth = 128; displayHeight = 64; - displayBufferSize = 1024; + displayBufferSize = displayWidth * displayHeight / 8; color = WHITE; geometry = GEOMETRY_128_64; textAlignment = TEXT_ALIGN_LEFT; @@ -427,8 +427,8 @@ uint8_t firstChar = pgm_read_byte(fontData + FIRST_CHAR_POS); uint16_t sizeOfJumpTable = pgm_read_byte(fontData + CHAR_NUM_POS) * JUMPTABLE_BYTES; - uint8_t cursorX = 0; - uint8_t cursorY = 0; + uint16_t cursorX = 0; + uint16_t cursorY = 0; switch (textAlignment) { case TEXT_ALIGN_CENTER_BOTH: @@ -789,19 +789,28 @@ #endif // Private functions -void OLEDDisplay::setGeometry(OLEDDISPLAY_GEOMETRY g) { +void OLEDDisplay::setGeometry(OLEDDISPLAY_GEOMETRY g, uint16_t width, uint16_t height) { this->geometry = g; - if (g == GEOMETRY_128_64) { - this->displayWidth = 128; - this->displayHeight = 64; - } else if (g == GEOMETRY_128_32) { - this->displayWidth = 128; - this->displayHeight = 32; + switch (g) { + case GEOMETRY_128_64: + this->displayWidth = 128; + this->displayHeight = 64; + break; + case GEOMETRY_128_32: + this->displayWidth = 128; + this->displayHeight = 32; + break; + case GEOMETRY_RAWMODE: + this->displayWidth = width > 0 ? width : 128; + this->displayHeight = height > 0 ? height : 64; + break; } - this->displayBufferSize = displayWidth*displayHeight/8; + this->displayBufferSize = displayWidth * displayHeight /8; } void OLEDDisplay::sendInitCommands(void) { + if (geometry == GEOMETRY_RAWMODE) + return; sendCommand(DISPLAYOFF); sendCommand(SETDISPLAYCLOCKDIV); sendCommand(0xF0); // Increase speed of the display max ~96Hz @@ -945,7 +954,7 @@ } -char DefaultFontTableLookup(const char ch) { +char DefaultFontTableLookup(const uint8_t ch) { // UTF-8 to font table index converter // Code form http://playground.arduino.cc/Main/Utf8ascii static uint8_t LASTCHAR;