ThingPulse OLED SSD1306

Dependents:   Turtle_RadioShuttle mbed-os5-F303-18650-Manager-tp4056 Kretanje_kroz_izbornike_OLED128x64_4tipke

Files at this revision

API Documentation at this revision

Comitter:
Helmut Tschemernjak
Date:
Wed May 29 11:17:58 2019 +0200
Parent:
1:9270c15c6aea
Child:
3:99a409809366
Commit message:
Updated with github changes

Changed in this revision

OLEDDisplay.cpp Show annotated file Show diff for this revision Revisions of this file
OLEDDisplay.h Show annotated file Show diff for this revision Revisions of this file
--- 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;
--- a/OLEDDisplay.h	Sun Apr 14 18:00:54 2019 +0200
+++ b/OLEDDisplay.h	Wed May 29 11:17:58 2019 +0200
@@ -137,11 +137,12 @@
 
 enum OLEDDISPLAY_GEOMETRY {
   GEOMETRY_128_64   = 0,
-  GEOMETRY_128_32   = 1
+  GEOMETRY_128_32,
+  GEOMETRY_RAWMODE,
 };
 
-typedef char (*FontTableLookupFunction)(const char ch);
-char DefaultFontTableLookup(const char ch);
+typedef char (*FontTableLookupFunction)(const uint8_t ch);
+char DefaultFontTableLookup(const uint8_t ch);
 
 
 #ifdef ARDUINO
@@ -318,7 +319,7 @@
     uint16_t  displayBufferSize;
 
     // Set the correct height, width and buffer for the geometry
-    void setGeometry(OLEDDISPLAY_GEOMETRY g);
+    void setGeometry(OLEDDISPLAY_GEOMETRY g, uint16_t width = 0, uint16_t height = 0);
 
     OLEDDISPLAY_TEXT_ALIGNMENT   textAlignment;
     OLEDDISPLAY_COLOR            color;