diff --git a/OLEDDisplay.cpp b/OLEDDisplay.cpp index bba1400ddf08fea1d5a8b0efd1efe8c0808bec93..f895dddaee3d33ffe7f5c5b7456871f5bff478ee 100644 --- a/OLEDDisplay.cpp +++ b/OLEDDisplay.cpp @@ -620,12 +620,17 @@ size_t OLEDDisplay::write(uint8_t c) { // Don't waste space on \r\n line endings, dropping \r if (c == 13) return 1; + // convert UTF-8 character to font table index + c = (this->fontTableLookupFunction)(c); + // drop unknown character + if (c == 0) return 1; + bool maxLineNotReached = this->logBufferLine < this->logBufferMaxLines; bool bufferNotFull = this->logBufferFilled < this->logBufferSize; // Can we write to the buffer? if (bufferNotFull && maxLineNotReached) { - this->logBuffer[logBufferFilled] = utf8ascii(c); + this->logBuffer[logBufferFilled] = c; this->logBufferFilled++; // Keep track of lines written if (c == 10) this->logBufferLine++; @@ -781,27 +786,6 @@ void inline OLEDDisplay::drawInternal(int16_t xMove, int16_t yMove, int16_t widt } } -// Code form http://playground.arduino.cc/Main/Utf8ascii -uint8_t OLEDDisplay::utf8ascii(byte ascii) { - static uint8_t LASTCHAR; - - if ( ascii < 128 ) { // Standard ASCII-set 0..0x7F handling - LASTCHAR = 0; - return ascii; - } - - uint8_t last = LASTCHAR; // get last char - LASTCHAR = ascii; - - 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 -} - // You need to free the char! char* OLEDDisplay::utf8ascii(String str) { uint16_t k = 0; @@ -818,7 +802,7 @@ char* OLEDDisplay::utf8ascii(String str) { length--; for (uint16_t i=0; i < length; i++) { - char c = utf8ascii(s[i]); + char c = (this->fontTableLookupFunction)(s[i]); if (c!=0) { s[k++]=c; } @@ -829,3 +813,7 @@ char* OLEDDisplay::utf8ascii(String str) { // This will leak 's' be sure to free it in the calling function. return s; } + +void OLEDDisplay::setFontTableLookupFunction(FontTableLookupFunction function) { + this->fontTableLookupFunction = function; +} \ No newline at end of file diff --git a/OLEDDisplay.h b/OLEDDisplay.h index b16838e242a8f17627e7044a3f998a12f3dd3c43..6e9d0fcef908c2db948fb97ecced0c8e127d7977 100644 --- a/OLEDDisplay.h +++ b/OLEDDisplay.h @@ -101,11 +101,15 @@ enum OLEDDISPLAY_TEXT_ALIGNMENT { TEXT_ALIGN_CENTER_BOTH = 3 }; + enum OLEDDISPLAY_GEOMETRY { GEOMETRY_128_64 = 0, GEOMETRY_128_32 = 1 }; +typedef byte (*FontTableLookupFunction)(const byte ch); + + class OLEDDisplay : public Print { public: @@ -185,6 +189,9 @@ class OLEDDisplay : public Print { // ArialMT_Plain_10, ArialMT_Plain_16, ArialMT_Plain_24 void setFont(const char *fontData); + // Set the function that will convert utf-8 to font table index + void setFontTableLookupFunction(FontTableLookupFunction function); + /* Display functions */ // Turn the display on @@ -206,7 +213,7 @@ class OLEDDisplay : public Print { void flipScreenVertically(); // Write the buffer to the display memory - virtual void display(void); + virtual void display(void) = 0; // Clear the local pixel buffer void clear(void); @@ -265,13 +272,33 @@ class OLEDDisplay : public Print { void sendInitCommands(); // converts utf8 characters to extended ascii - static char* utf8ascii(String s); - static byte utf8ascii(byte ascii); + char* utf8ascii(String s); void inline drawInternal(int16_t xMove, int16_t yMove, int16_t width, int16_t height, const char *data, uint16_t offset, uint16_t bytesInData) __attribute__((always_inline)); void drawStringInternal(int16_t xMove, int16_t yMove, char* text, uint16_t textLength, uint16_t textWidth); + // UTF-8 to font table index converter + // Code form http://playground.arduino.cc/Main/Utf8ascii + FontTableLookupFunction fontTableLookupFunction = [](const byte ch) { + static uint8_t LASTCHAR; + + if (ch < 128) { // Standard ASCII-set 0..0x7F handling + LASTCHAR = 0; + return ch; + } + + uint8_t last = LASTCHAR; // get last char + LASTCHAR = ch; + + switch (last) { // conversion depnding on first UTF8-character + case 0xC2: return (uint8_t) ch; break; + case 0xC3: return (uint8_t) (ch | 0xC0); break; + case 0x82: if (ch == 0xAC) return (uint8_t) 0x80; // special case Euro-symbol + } + + return (uint8_t) 0; // otherwise: return zero, if character has to be ignored + }; }; #endif diff --git a/OLEDDisplayUi.cpp b/OLEDDisplayUi.cpp index 1c306d57cd3606cac13274b4592216270e8b9f99..51e026290174882f0293ee342eca9eb8753e6041 100644 --- a/OLEDDisplayUi.cpp +++ b/OLEDDisplayUi.cpp @@ -116,6 +116,10 @@ void OLEDDisplayUi::setOverlays(OverlayCallback* overlayFunctions, uint8_t overl // -/----- Loading Process -----\- +void OLEDDisplayUi::setLoadingDrawFunction(LoadingDrawFunction loadingDrawFunction) { + this->loadingDrawFunction = loadingDrawFunction; +} + void OLEDDisplayUi::runLoadingProcess(LoadingStage* stages, uint8_t stagesCount) { uint8_t progress = 0; uint8_t increment = 100 / stagesCount; diff --git a/OLEDDisplayUi.h b/OLEDDisplayUi.h index 617346a3a2ede21c9f09a19a279aa89d4cbe8387..35a1e99bcf449c3d2f5f4405f223949005fce497 100644 --- a/OLEDDisplayUi.h +++ b/OLEDDisplayUi.h @@ -72,7 +72,7 @@ const char ANIMATION_inactiveSymbol[] PROGMEM = { // Structure of the UiState struct OLEDDisplayUiState { - u_int64_t lastUpdate = 0; + uint64_t lastUpdate = 0; uint16_t ticksSinceLastStateSwitch = 0; FrameState frameState = FIXED; diff --git a/README.md b/README.md index a63d4ba8927a44ce6c8cefc3c36da7584791e66b..3447d87b9ca5b0f474b6d0cdef9fb4fc9d3a40c7 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,6 @@ -esp8266-oled-ssd1306 [](https://travis-ci.org/squix78/esp8266-oled-ssd1306) -============ +[](https://travis-ci.org/ThingPulse/esp8266-oled-ssd1306) + +# ESP8266 OLED SSD1306 > We just released version 3.0.0. Please have a look at our [upgrade guide](UPGRADE-3.0.md) @@ -19,7 +20,7 @@ The init sequence for the SSD1306 was inspired by Adafruit's library for the sam ## Usage -Check out the examples folder for a few comprehensive demonstrations how to use the library. Also check out the ESP8266 Weather Station library (https://github.com/squix78/esp8266-weather-station) which uses the OLED library to display beautiful weather information. +Check out the examples folder for a few comprehensive demonstrations how to use the library. Also check out the [ESP8266 Weather Station](https://github.com/ThingPulse/esp8266-weather-station) library which uses the OLED library to display beautiful weather information. ## Upgrade @@ -274,14 +275,14 @@ void enableIndicator(); void disableIndicator(); /** - * Enable drawing of indicators + * Enable drawing of all indicators. */ -void enableAllIndicator(); +void enableAllIndicators(); /** - * Disable drawing of indicators. + * Disable drawing of all indicators. */ -void disableAllIndicator(); +void disableAllIndicators(); /** * Set the position of the indicator bar. @@ -322,7 +323,7 @@ void setOverlays(OverlayCallback* overlayFunctions, uint8_t overlayCount); * Set the function that will draw each step * in the loading animation */ -void setLoadingDrawFunction(LoadingDrawFunction stage); +void setLoadingDrawFunction(LoadingDrawFunction loadingDrawFunction); /** * Run the loading process diff --git a/library.json b/library.json index 7001fba8d1666bc8cfc448f85e24c89c7359cc03..862d171673544485dc81d73f36a75bc802faa440 100644 --- a/library.json +++ b/library.json @@ -1,8 +1,8 @@ { "name": "ESP8266_SSD1306", - "version": "3.2.3", + "version": "3.2.7", "keywords": "ssd1306, oled, display, i2c", - "description": "A I2C display driver for SSD1306 oled displays connected to an ESP8266", + "description": "A I2C display driver for SSD1306 oled displays connected to an ESP8266 or ESP32", "repository": { "type": "git", @@ -21,5 +21,8 @@ } ], "frameworks": "arduino", - "platforms": "espressif" + "platforms": [ + "espressif8266", + "espressif32" + ] } diff --git a/library.properties b/library.properties index 81174d5956da5963dce585b6c5239165dc18ab92..4f8de4cf3745d2af820bfc3ab762ac81f30e5114 100644 --- a/library.properties +++ b/library.properties @@ -1,9 +1,9 @@ -name=ESP8266 Oled Driver for SSD1306 display -version=3.2.3 +name=ESP8266 and ESP32 Oled Driver for SSD1306 display +version=3.2.7 author=Daniel Eichhorn, Fabrice Weinberg maintainer=Daniel Eichhorn <squix78@gmail.com> -sentence=A I2C display driver for SSD1306 oled displays connected to an ESP8266 -paragraph=A I2C display driver for SSD1306 oled displays connected to an ESP8266 +sentence=A I2C display driver for SSD1306 oled displays connected to an ESP8266 or ESP32 +paragraph=A I2C display driver for SSD1306 oled displays connected to an ESP8266 or ESP32 category=Display url=https://github.com/squix78/esp8266-oled-ssd1306 -architectures=esp8266 +architectures=esp8266,esp32