From 2f8989d5ac80100d0a87386f5087f90108d49cef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20St=C3=B6r?= Date: Sun, 17 Jan 2021 21:21:34 +0100 Subject: [PATCH 01/23] Add classic kit reference --- README.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index ff3a6ca..ed2d8b1 100644 --- a/README.md +++ b/README.md @@ -2,14 +2,16 @@ # ThingPulse OLED SSD1306 (ESP8266/ESP32/Mbed-OS) -> We just released version 4.0.0. Please have a look at our [upgrade guide](UPGRADE-4.0.md) - This is a driver for SSD1306 128x64, 128x32, 64x48 and 64x32 OLED displays running on the Arduino/ESP8266 & ESP32 and mbed-os platforms. Can be used with either the I2C or SPI version of the display. +This library drives the OLED display included in the [ThingPulse IoT starter kit](https://thingpulse.com/product/esp8266-iot-electronics-starter-kit-weatherstation-planespotter-worldclock/) aka classic kit aka weather station kit. + +[![ThingPulse ESP8266 WeatherStation Classic Kit](https://github.com/ThingPulse/esp8266-weather-station/blob/master/resources/ThingPulse-ESP8266-Weather-Station.jpeg?raw=true)](https://thingpulse.com/product/esp8266-iot-electronics-starter-kit-weatherstation-planespotter-worldclock/) + You can either download this library as a zip file and unpack it to your Arduino/libraries folder or find it in the Arduino library manager under "ESP8266 and ESP32 Oled Driver for SSD1306 display". For mbed-os a copy of the files are available as an mbed-os library. -It is also available as a platformio library. Just execute the following command: +It is also available as a [PlatformIO library](https://platformio.org/lib/show/562/ESP8266%20and%20ESP32%20OLED%20driver%20for%20SSD1306%20displays/examples). Just execute the following command: ``` platformio lib install 562 ``` From 5187aef63bfa1001b9090f0903bba6e1339b94d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20St=C3=B6r?= Date: Sun, 17 Jan 2021 21:29:42 +0100 Subject: [PATCH 02/23] Add license properties --- library.json | 1 + library.properties | 1 + 2 files changed, 2 insertions(+) diff --git a/library.json b/library.json index 016a589..acd11ce 100644 --- a/library.json +++ b/library.json @@ -3,6 +3,7 @@ "version": "4.2.0", "keywords": "ssd1306, oled, display, i2c", "description": "I2C display driver for SSD1306 OLED displays connected to ESP8266, ESP32, Mbed-OS", + "license": "MIT", "repository": { "type": "git", diff --git a/library.properties b/library.properties index edc770c..e931a3f 100644 --- a/library.properties +++ b/library.properties @@ -7,3 +7,4 @@ paragraph=The following geometries are currently supported: 128x64, 128x32, 64x4 category=Display url=https://github.com/ThingPulse/esp8266-oled-ssd1306 architectures=esp8266,esp32 +license=MIT From 7b73fdec98d0a5ea5b17d80d91d10a92f56e28a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20St=C3=B6r?= Date: Mon, 8 Feb 2021 08:34:31 +0100 Subject: [PATCH 03/23] Add issue templates --- .github/ISSUE_TEMPLATE/bug_report.md | 37 +++++++++++++++++++++++ .github/ISSUE_TEMPLATE/support-request.md | 10 ++++++ 2 files changed, 47 insertions(+) create mode 100644 .github/ISSUE_TEMPLATE/bug_report.md create mode 100644 .github/ISSUE_TEMPLATE/support-request.md diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 0000000..e01d29c --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,37 @@ +--- +name: Bug report +about: Create a report to help us improve +title: '' +labels: '' +assignees: '' + +--- + +**Describe the bug** +A clear and concise description of what the bug is. + +**To Reproduce** +Steps to reproduce the behavior: +1. Go to '...' +2. Do this '....' +3. Do that '....' +4. See error + +**Sample code** +Provide a [MCVE](https://stackoverflow.com/help/minimal-reproducible-example) below. +```c +# your code goes here +``` + +**Expected behavior** +A clear and concise description of what you expected to happen. + +**Screenshots** +If applicable, add screenshots to help explain your problem. + +**Versions (please complete the following information):** + - Library: [e.g. 4.2] + - Platform [e.g. ESP266 Arduino Core 2.5.x] + +**Additional context** +Add any other context about the problem here. diff --git a/.github/ISSUE_TEMPLATE/support-request.md b/.github/ISSUE_TEMPLATE/support-request.md new file mode 100644 index 0000000..3af6a49 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/support-request.md @@ -0,0 +1,10 @@ +--- +name: Support request +about: Describe this issue template's purpose here. +title: '' +labels: '' +assignees: '' + +--- + +We offer support to our customers at https://support.thingpulse.com/. Send us an email if you don't have an account yet. From fe63fb152b256a407b1c056febf2d50a3697ef79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20St=C3=B6r?= Date: Mon, 22 Mar 2021 21:29:45 +0100 Subject: [PATCH 04/23] Adjust PlatformIO id --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index ed2d8b1..4ef080b 100644 --- a/README.md +++ b/README.md @@ -11,9 +11,9 @@ This library drives the OLED display included in the [ThingPulse IoT starter kit You can either download this library as a zip file and unpack it to your Arduino/libraries folder or find it in the Arduino library manager under "ESP8266 and ESP32 Oled Driver for SSD1306 display". For mbed-os a copy of the files are available as an mbed-os library. -It is also available as a [PlatformIO library](https://platformio.org/lib/show/562/ESP8266%20and%20ESP32%20OLED%20driver%20for%20SSD1306%20displays/examples). Just execute the following command: +It is also available as a [PlatformIO library](https://platformio.org/lib/show/2978/ESP8266%20and%20ESP32%20OLED%20driver%20for%20SSD1306%20displays/examples). Just execute the following command: ``` -platformio lib install 562 +platformio lib install 2978 ``` ## Service level promise From d4b8234ef5b191b164dbbd65735962ca7635ba7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20St=C3=B6r?= Date: Mon, 22 Mar 2021 22:51:39 +0100 Subject: [PATCH 05/23] Support triangles Code provided by @mtsem. Fixes #329 --- README.md | 14 +++++--- src/OLEDDisplay.cpp | 88 +++++++++++++++++++++++++++++++++++++++++++-- src/OLEDDisplay.h | 12 +++++-- 3 files changed, 105 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 4ef080b..8440078 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -[![Build Status](https://travis-ci.org/ThingPulse/esp8266-oled-ssd1306.svg?branch=master)](https://travis-ci.org/ThingPulse/esp8266-oled-ssd1306) +[![Build Status](https://travis-ci.com/ThingPulse/esp8266-oled-ssd1306.svg?branch=master)](https://travis-ci.com/ThingPulse/esp8266-oled-ssd1306) # ThingPulse OLED SSD1306 (ESP8266/ESP32/Mbed-OS) @@ -9,7 +9,7 @@ This library drives the OLED display included in the [ThingPulse IoT starter kit [![ThingPulse ESP8266 WeatherStation Classic Kit](https://github.com/ThingPulse/esp8266-weather-station/blob/master/resources/ThingPulse-ESP8266-Weather-Station.jpeg?raw=true)](https://thingpulse.com/product/esp8266-iot-electronics-starter-kit-weatherstation-planespotter-worldclock/) -You can either download this library as a zip file and unpack it to your Arduino/libraries folder or find it in the Arduino library manager under "ESP8266 and ESP32 Oled Driver for SSD1306 display". For mbed-os a copy of the files are available as an mbed-os library. +You can either download this library as a zip file and unpack it to your Arduino/libraries folder or find it in the Arduino library manager under "ESP8266 and ESP32 Oled Driver for SSD1306 display". For mbed-os a copy of the files are available as an mbed-os library. It is also available as a [PlatformIO library](https://platformio.org/lib/show/2978/ESP8266%20and%20ESP32%20OLED%20driver%20for%20SSD1306%20displays/examples). Just execute the following command: ``` @@ -71,7 +71,7 @@ The library supports different protocols to access the OLED display. Currently t ### I2C with Wire.h ```C++ -#include +#include #include "SSD1306Wire.h" // for 128x64 displays: @@ -87,7 +87,7 @@ SSD1306Wire display(0x3c, SDA, SCL); // ADDRESS, SDA, SCL for a SH1106: ```C++ -#include +#include #include "SH1106Wire.h" SH1106Wire display(0x3c, SDA, SCL); // ADDRESS, SDA, SCL @@ -205,6 +205,12 @@ void drawCircle(int16_t x, int16_t y, int16_t radius); // Fill circle void fillCircle(int16_t x, int16_t y, int16_t radius); +// Draw an empty triangle i.e. only the outline +void drawTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2); + +// Draw a solid triangle i.e. filled +void fillTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2); + // Draw a line horizontally void drawHorizontalLine(int16_t x, int16_t y, int16_t length); diff --git a/src/OLEDDisplay.cpp b/src/OLEDDisplay.cpp index 89a8010..ddfa30d 100644 --- a/src/OLEDDisplay.cpp +++ b/src/OLEDDisplay.cpp @@ -99,7 +99,7 @@ bool OLEDDisplay::allocateBuffer() { bool OLEDDisplay::init() { BufferOffset = getBufferOffset(); - + if(!allocateBuffer()) { return false; } @@ -304,6 +304,90 @@ void OLEDDisplay::fillCircle(int16_t x0, int16_t y0, int16_t radius) { } +void OLEDDisplay::drawTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, + int16_t x2, int16_t y2) { + drawLine(x0, y0, x1, y1); + drawLine(x1, y1, x2, y2); + drawLine(x2, y2, x0, y0); +} + +void OLEDDisplay::fillTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, + int16_t x2, int16_t y2) { + int16_t a, b, y, last; + + if (y0 > y1) { + _swap_int16_t(y0, y1); + _swap_int16_t(x0, x1); + } + if (y1 > y2) { + _swap_int16_t(y2, y1); + _swap_int16_t(x2, x1); + } + if (y0 > y1) { + _swap_int16_t(y0, y1); + _swap_int16_t(x0, x1); + } + + if (y0 == y2) { + a = b = x0; + if (x1 < a) { + a = x1; + } else if (x1 > b) { + b = x1; + } + if (x2 < a) { + a = x2; + } else if (x2 > b) { + b = x2; + } + drawHorizontalLine(a, y0, b - a + 1); + return; + } + + int16_t + dx01 = x1 - x0, + dy01 = y1 - y0, + dx02 = x2 - x0, + dy02 = y2 - y0, + dx12 = x2 - x1, + dy12 = y2 - y1; + int32_t + sa = 0, + sb = 0; + + if (y1 == y2) { + last = y1; // Include y1 scanline + } else { + last = y1 - 1; // Skip it + } + + for (y = y0; y <= last; y++) { + a = x0 + sa / dy01; + b = x0 + sb / dy02; + sa += dx01; + sb += dx02; + + if (a > b) { + _swap_int16_t(a, b); + } + drawHorizontalLine(a, y, b - a + 1); + } + + sa = dx12 * (y - y1); + sb = dx02 * (y - y0); + for (; y <= y2; y++) { + a = x1 + sa / dy12; + b = x0 + sb / dy02; + sa += dx12; + sb += dx02; + + if (a > b) { + _swap_int16_t(a, b); + } + drawHorizontalLine(a, y, b - a + 1); + } +} + void OLEDDisplay::drawHorizontalLine(int16_t x, int16_t y, int16_t length) { if (y < 0 || y >= this->height()) { return; } @@ -884,7 +968,7 @@ void OLEDDisplay::sendInitCommands(void) { sendCommand(SETDISPLAYOFFSET); sendCommand(0x00); if(geometry == GEOMETRY_64_32) - sendCommand(0x00); + sendCommand(0x00); else sendCommand(SETSTARTLINE); sendCommand(CHARGEPUMP); diff --git a/src/OLEDDisplay.h b/src/OLEDDisplay.h index d43ee16..76329e8 100644 --- a/src/OLEDDisplay.h +++ b/src/OLEDDisplay.h @@ -215,6 +215,12 @@ class OLEDDisplay : public Stream { // Fill circle void fillCircle(int16_t x, int16_t y, int16_t radius); + // Draw an empty triangle i.e. only the outline + void drawTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2); + + // Draw a solid triangle i.e. filled + void fillTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2); + // Draw a line horizontally void drawHorizontalLine(int16_t x, int16_t y, int16_t length); @@ -320,7 +326,7 @@ class OLEDDisplay : public Stream { // Implement needed function to be compatible with Print class size_t write(uint8_t c); size_t write(const char* s); - + // Implement needed function to be compatible with Stream class #ifdef __MBED__ int _putc(int c); @@ -361,7 +367,7 @@ class OLEDDisplay : public Stream { // the header size of the buffer used, e.g. for the SPI command header int BufferOffset; virtual int getBufferOffset(void) = 0; - + // Send a command to the display (low level function) virtual void sendCommand(uint8_t com) {(void)com;}; @@ -377,7 +383,7 @@ class OLEDDisplay : public Stream { void inline drawInternal(int16_t xMove, int16_t yMove, int16_t width, int16_t height, const uint8_t *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); - + FontTableLookupFunction fontTableLookupFunction; }; From f242f1a3a5b54631665ba892a6314075ad8858d3 Mon Sep 17 00:00:00 2001 From: Rotzbua Date: Thu, 1 Apr 2021 15:47:44 +0200 Subject: [PATCH 06/23] Fix type: unsigned char -> uint8_t (#334) --- examples/SSD1306ClockDemo/images.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/SSD1306ClockDemo/images.h b/examples/SSD1306ClockDemo/images.h index 1889188..0943f57 100644 --- a/examples/SSD1306ClockDemo/images.h +++ b/examples/SSD1306ClockDemo/images.h @@ -1,4 +1,4 @@ -const unsigned char activeSymbol[] PROGMEM = { +const uint8_t activeSymbol[] PROGMEM = { B00000000, B00000000, B00011000, @@ -9,7 +9,7 @@ const unsigned char activeSymbol[] PROGMEM = { B00011000 }; -const unsigned char inactiveSymbol[] PROGMEM = { +const uint8_t inactiveSymbol[] PROGMEM = { B00000000, B00000000, B00000000, From 8969d73c3acb010e89b5582b25f5b60501949fdf Mon Sep 17 00:00:00 2001 From: Rotzbua Date: Thu, 1 Apr 2021 15:54:14 +0200 Subject: [PATCH 07/23] Fix type: char -> uint8_t (#335) --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 8440078..e9e8277 100644 --- a/README.md +++ b/README.md @@ -338,12 +338,12 @@ void setIndicatorDirection(IndicatorDirection dir); /** * Set the symbol to indicate an active frame in the indicator bar. */ -void setActiveSymbol(const char* symbol); +void setActiveSymbol(const uint8_t* symbol); /** * Set the symbol to indicate an inactive frame in the indicator bar. */ -void setInactiveSymbol(const char* symbol); +void setInactiveSymbol(const uint8_t* symbol); /** * Configure what animation is used to transition from one frame to another From 86bba3ed30169137bebdd2e556e09aaf2bd2d80f Mon Sep 17 00:00:00 2001 From: Rotzbua Date: Sun, 4 Apr 2021 21:26:59 +0200 Subject: [PATCH 08/23] Fix type: char -> uint8_t (#336) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e9e8277..2d0351e 100644 --- a/README.md +++ b/README.md @@ -225,7 +225,7 @@ void drawProgressBar(uint16_t x, uint16_t y, uint16_t width, uint16_t height, ui void drawFastImage(int16_t x, int16_t y, int16_t width, int16_t height, const uint8_t *image); // Draw a XBM -void drawXbm(int16_t x, int16_t y, int16_t width, int16_t height, const char* xbm); +void drawXbm(int16_t x, int16_t y, int16_t width, int16_t height, const uint8_t *xbm); ``` ## Text operations From 259a899ee8e49e9a188eee491b31322418a51b71 Mon Sep 17 00:00:00 2001 From: Rotzbua Date: Sun, 4 Apr 2021 21:27:15 +0200 Subject: [PATCH 09/23] Fix type: char -> uint8_t (#337) --- src/OLEDDisplay.cpp | 2 +- src/OLEDDisplay.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/OLEDDisplay.cpp b/src/OLEDDisplay.cpp index ddfa30d..b5471d1 100644 --- a/src/OLEDDisplay.cpp +++ b/src/OLEDDisplay.cpp @@ -537,7 +537,7 @@ void OLEDDisplay::drawXbm(int16_t xMove, int16_t yMove, int16_t width, int16_t h } } -void OLEDDisplay::drawIco16x16(int16_t xMove, int16_t yMove, const char *ico, bool inverse) { +void OLEDDisplay::drawIco16x16(int16_t xMove, int16_t yMove, const uint8_t *ico, bool inverse) { uint16_t data; for(int16_t y = 0; y < 16; y++) { diff --git a/src/OLEDDisplay.h b/src/OLEDDisplay.h index 76329e8..2781517 100644 --- a/src/OLEDDisplay.h +++ b/src/OLEDDisplay.h @@ -238,7 +238,7 @@ class OLEDDisplay : public Stream { void drawXbm(int16_t x, int16_t y, int16_t width, int16_t height, const uint8_t *xbm); // Draw icon 16x16 xbm format - void drawIco16x16(int16_t x, int16_t y, const char *ico, bool inverse = false); + void drawIco16x16(int16_t x, int16_t y, const uint8_t *ico, bool inverse = false); /* Text functions */ From 946f351bf9452e31806d0f38de9f229862ff8eaf Mon Sep 17 00:00:00 2001 From: Edduaardo <41928360+Edduaardo@users.noreply.github.com> Date: Fri, 9 Apr 2021 09:03:37 -0300 Subject: [PATCH 10/23] Small fixes to some examples (#340) Fixes #338 --- examples/SSD1306ClockDemo/SSD1306ClockDemo.ino | 2 +- examples/SSD1306DrawingDemo/SSD1306DrawingDemo.ino | 2 +- examples/SSD1306OTADemo/SSD1306OTADemo.ino | 2 +- examples/SSD1306SimpleDemo/SSD1306SimpleDemo.ino | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/SSD1306ClockDemo/SSD1306ClockDemo.ino b/examples/SSD1306ClockDemo/SSD1306ClockDemo.ino index 63102cf..71b7d92 100644 --- a/examples/SSD1306ClockDemo/SSD1306ClockDemo.ino +++ b/examples/SSD1306ClockDemo/SSD1306ClockDemo.ino @@ -70,7 +70,7 @@ // Initialize the OLED display using Wire library SSD1306Wire display(0x3c, D3, D5); -// SH1106 display(0x3c, D3, D5); +// SH1106Wire display(0x3c, D3, D5); OLEDDisplayUi ui ( &display ); diff --git a/examples/SSD1306DrawingDemo/SSD1306DrawingDemo.ino b/examples/SSD1306DrawingDemo/SSD1306DrawingDemo.ino index 43bd974..3e326cf 100644 --- a/examples/SSD1306DrawingDemo/SSD1306DrawingDemo.ino +++ b/examples/SSD1306DrawingDemo/SSD1306DrawingDemo.ino @@ -63,7 +63,7 @@ // Initialize the OLED display using Wire library SSD1306Wire display(0x3c, D3, D5); - // SH1106 display(0x3c, D3, D5); + // SH1106Wire display(0x3c, D3, D5); // Adapted from Adafruit_SSD1306 void drawLines() { diff --git a/examples/SSD1306OTADemo/SSD1306OTADemo.ino b/examples/SSD1306OTADemo/SSD1306OTADemo.ino index e207d4a..1dc6687 100644 --- a/examples/SSD1306OTADemo/SSD1306OTADemo.ino +++ b/examples/SSD1306OTADemo/SSD1306OTADemo.ino @@ -74,7 +74,7 @@ // Initialize the OLED display using Wire library SSD1306Wire display(0x3c, D3, D5); -// SH1106 display(0x3c, D3, D5); +// SH1106Wire display(0x3c, D3, D5); void setup() { diff --git a/examples/SSD1306SimpleDemo/SSD1306SimpleDemo.ino b/examples/SSD1306SimpleDemo/SSD1306SimpleDemo.ino index 8d715e4..3428a9f 100644 --- a/examples/SSD1306SimpleDemo/SSD1306SimpleDemo.ino +++ b/examples/SSD1306SimpleDemo/SSD1306SimpleDemo.ino @@ -54,7 +54,7 @@ SSD1306Wire display(0x3c, SDA, SCL); // ADDRESS, SDA, SCL - SDA and SCL usually populate automatically based on your board's pins_arduino.h // SSD1306Wire display(0x3c, D3, D5); // ADDRESS, SDA, SCL - If not, they can be specified manually. // SSD1306Wire display(0x3c, SDA, SCL, GEOMETRY_128_32); // ADDRESS, SDA, SCL, OLEDDISPLAY_GEOMETRY - Extra param required for 128x32 displays. -// SH1106 display(0x3c, SDA, SCL); // ADDRESS, SDA, SCL +// SH1106Wire display(0x3c, SDA, SCL); // ADDRESS, SDA, SCL // Initialize the OLED display using brzo_i2c: // SSD1306Brzo display(0x3c, D3, D5); // ADDRESS, SDA, SCL From 5930c1c907e62e9fd30f4d984606a26127812d29 Mon Sep 17 00:00:00 2001 From: Rotzbua Date: Sat, 24 Apr 2021 20:02:06 +0200 Subject: [PATCH 11/23] Pass String arguments by reference (#342) --- README.md | 6 +++--- src/OLEDDisplay.cpp | 8 ++++---- src/OLEDDisplay.h | 8 ++++---- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 2d0351e..70e92a4 100644 --- a/README.md +++ b/README.md @@ -231,19 +231,19 @@ void drawXbm(int16_t x, int16_t y, int16_t width, int16_t height, const uint8_t ## Text operations ``` C++ -void drawString(int16_t x, int16_t y, String text); +void drawString(int16_t x, int16_t y, const String &text); // Draws a String with a maximum width at the given location. // If the given String is wider than the specified width // The text will be wrapped to the next line at a space or dash -void drawStringMaxWidth(int16_t x, int16_t y, int16_t maxLineWidth, String text); +void drawStringMaxWidth(int16_t x, int16_t y, int16_t maxLineWidth, const String &text); // Returns the width of the const char* with the current // font settings uint16_t getStringWidth(const char* text, uint16_t length); // Convencience method for the const char version -uint16_t getStringWidth(String text); +uint16_t getStringWidth(const String &text); // Specifies relative to which anchor point // the text is rendered. Available constants: diff --git a/src/OLEDDisplay.cpp b/src/OLEDDisplay.cpp index b5471d1..469e2dc 100644 --- a/src/OLEDDisplay.cpp +++ b/src/OLEDDisplay.cpp @@ -606,7 +606,7 @@ void OLEDDisplay::drawStringInternal(int16_t xMove, int16_t yMove, char* text, u } -void OLEDDisplay::drawString(int16_t xMove, int16_t yMove, String strUser) { +void OLEDDisplay::drawString(int16_t xMove, int16_t yMove, const String &strUser) { uint16_t lineHeight = pgm_read_byte(fontData + HEIGHT_POS); // char* text must be freed! @@ -644,7 +644,7 @@ void OLEDDisplay::drawStringf( int16_t x, int16_t y, char* buffer, String format drawString( x, y, buffer ); } -void OLEDDisplay::drawStringMaxWidth(int16_t xMove, int16_t yMove, uint16_t maxLineWidth, String strUser) { +void OLEDDisplay::drawStringMaxWidth(int16_t xMove, int16_t yMove, uint16_t maxLineWidth, const String &strUser) { uint16_t firstChar = pgm_read_byte(fontData + FIRST_CHAR_POS); uint16_t lineHeight = pgm_read_byte(fontData + HEIGHT_POS); @@ -707,7 +707,7 @@ uint16_t OLEDDisplay::getStringWidth(const char* text, uint16_t length) { return max(maxWidth, stringWidth); } -uint16_t OLEDDisplay::getStringWidth(String strUser) { +uint16_t OLEDDisplay::getStringWidth(const String &strUser) { char* text = utf8ascii(strUser); uint16_t length = strlen(text); uint16_t width = getStringWidth(text, length); @@ -1074,7 +1074,7 @@ void inline OLEDDisplay::drawInternal(int16_t xMove, int16_t yMove, int16_t widt } // You need to free the char! -char* OLEDDisplay::utf8ascii(String str) { +char* OLEDDisplay::utf8ascii(const String &str) { uint16_t k = 0; uint16_t length = str.length() + 1; diff --git a/src/OLEDDisplay.h b/src/OLEDDisplay.h index 2781517..982b794 100644 --- a/src/OLEDDisplay.h +++ b/src/OLEDDisplay.h @@ -243,7 +243,7 @@ class OLEDDisplay : public Stream { /* Text functions */ // Draws a string at the given location - void drawString(int16_t x, int16_t y, String text); + void drawString(int16_t x, int16_t y, const String &text); // Draws a formatted string (like printf) at the given location void drawStringf(int16_t x, int16_t y, char* buffer, String format, ... ); @@ -251,14 +251,14 @@ class OLEDDisplay : public Stream { // Draws a String with a maximum width at the given location. // If the given String is wider than the specified width // The text will be wrapped to the next line at a space or dash - void drawStringMaxWidth(int16_t x, int16_t y, uint16_t maxLineWidth, String text); + void drawStringMaxWidth(int16_t x, int16_t y, uint16_t maxLineWidth, const String &text); // Returns the width of the const char* with the current // font settings uint16_t getStringWidth(const char* text, uint16_t length); // Convencience method for the const char version - uint16_t getStringWidth(String text); + uint16_t getStringWidth(const String &text); // Specifies relative to which anchor point // the text is rendered. Available constants: @@ -378,7 +378,7 @@ class OLEDDisplay : public Stream { void sendInitCommands(); // converts utf8 characters to extended ascii - char* utf8ascii(String s); + char* utf8ascii(const String &s); void inline drawInternal(int16_t xMove, int16_t yMove, int16_t width, int16_t height, const uint8_t *data, uint16_t offset, uint16_t bytesInData) __attribute__((always_inline)); From 9ff5460f864d73ccc610fa30e73874baca6ee037 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20St=C3=B6r?= Date: Mon, 24 May 2021 21:34:24 +0200 Subject: [PATCH 12/23] Harmonize examples - format - use SDA, SCL pins by default with explanation - fix rendering millis() in SimpleDemo --- .../SSD1306ClockDemo/SSD1306ClockDemo.ino | 92 ++++---- .../SSD1306DrawingDemo/SSD1306DrawingDemo.ino | 204 +++++++++--------- examples/SSD1306OTADemo/SSD1306OTADemo.ino | 78 +++---- .../SSD1306SimpleDemo/SSD1306SimpleDemo.ino | 127 +++++------ .../SSD1306TwoScreenDemo.ino | 54 ++--- examples/SSD1306UiDemo/SSD1306UiDemo.ino | 96 ++++----- 6 files changed, 325 insertions(+), 326 deletions(-) diff --git a/examples/SSD1306ClockDemo/SSD1306ClockDemo.ino b/examples/SSD1306ClockDemo/SSD1306ClockDemo.ino index 71b7d92..b5eb3dc 100644 --- a/examples/SSD1306ClockDemo/SSD1306ClockDemo.ino +++ b/examples/SSD1306ClockDemo/SSD1306ClockDemo.ino @@ -1,32 +1,33 @@ /** - * The MIT License (MIT) - * - * Copyright (c) 2018 by ThingPulse, Daniel Eichhorn - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - * ThingPulse invests considerable time and money to develop these open source libraries. - * Please support us by buying our products (and not the clones) from - * https://thingpulse.com - * - */ + The MIT License (MIT) + Copyright (c) 2018 by ThingPulse, Daniel Eichhorn + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. + + ThingPulse invests considerable time and money to develop these open source libraries. + Please support us by buying our products (and not the clones) from + https://thingpulse.com + +*/ + +// Install https://github.com/PaulStoffregen/Time #include // Include the correct display library @@ -69,21 +70,21 @@ // SH1106Brzo display(0x3c, D3, D5); // Initialize the OLED display using Wire library -SSD1306Wire display(0x3c, D3, D5); -// SH1106Wire display(0x3c, D3, D5); +SSD1306Wire display(0x3c, SDA, SCL); // ADDRESS, SDA, SCL - SDA and SCL usually populate automatically based on your board's pins_arduino.h e.g. https://github.com/esp8266/Arduino/blob/master/variants/nodemcu/pins_arduino.h +// SH1106Wire display(0x3c, SDA, SCL); OLEDDisplayUi ui ( &display ); int screenW = 128; int screenH = 64; -int clockCenterX = screenW/2; -int clockCenterY = ((screenH-16)/2)+16; // top yellow part is 16 px height +int clockCenterX = screenW / 2; +int clockCenterY = ((screenH - 16) / 2) + 16; // top yellow part is 16 px height int clockRadius = 23; // utility function for digital clock display: prints leading 0 -String twoDigits(int digits){ - if(digits < 10) { - String i = '0'+String(digits); +String twoDigits(int digits) { + if (digits < 10) { + String i = '0' + String(digits); return i; } else { @@ -96,15 +97,15 @@ void clockOverlay(OLEDDisplay *display, OLEDDisplayUiState* state) { } void analogClockFrame(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int16_t y) { -// ui.disableIndicator(); + // ui.disableIndicator(); // Draw the clock face -// display->drawCircle(clockCenterX + x, clockCenterY + y, clockRadius); + // display->drawCircle(clockCenterX + x, clockCenterY + y, clockRadius); display->drawCircle(clockCenterX + x, clockCenterY + y, 2); // //hour ticks - for( int z=0; z < 360;z= z + 30 ){ - //Begin at 0° and stop at 360° + for ( int z = 0; z < 360; z = z + 30 ) { + //Begin at 0° and stop at 360° float angle = z ; angle = ( angle / 57.29577951 ) ; //Convert degrees to radians int x2 = ( clockCenterX + ( sin(angle) * clockRadius ) ); @@ -137,7 +138,7 @@ void analogClockFrame(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x } void digitalClockFrame(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int16_t y) { - String timenow = String(hour())+":"+twoDigits(minute())+":"+twoDigits(second()); + String timenow = String(hour()) + ":" + twoDigits(minute()) + ":" + twoDigits(second()); display->setTextAlignment(TEXT_ALIGN_CENTER); display->setFont(ArialMT_Plain_24); display->drawString(clockCenterX + x , clockCenterY + y, timenow ); @@ -155,15 +156,15 @@ OverlayCallback overlays[] = { clockOverlay }; int overlaysCount = 1; void setup() { - Serial.begin(9600); + Serial.begin(115200); Serial.println(); - // The ESP is capable of rendering 60fps in 80Mhz mode - // but that won't give you much time for anything else - // run it in 160Mhz mode or just set it to 30 fps + // The ESP is capable of rendering 60fps in 80Mhz mode + // but that won't give you much time for anything else + // run it in 160Mhz mode or just set it to 30 fps ui.setTargetFPS(60); - // Customize the active and inactive symbol + // Customize the active and inactive symbol ui.setActiveSymbol(activeSymbol); ui.setInactiveSymbol(inactiveSymbol); @@ -207,8 +208,5 @@ void loop() { // Don't do stuff if you are below your // time budget. delay(remainingTimeBudget); - } - - } diff --git a/examples/SSD1306DrawingDemo/SSD1306DrawingDemo.ino b/examples/SSD1306DrawingDemo/SSD1306DrawingDemo.ino index 3e326cf..d684e7d 100644 --- a/examples/SSD1306DrawingDemo/SSD1306DrawingDemo.ino +++ b/examples/SSD1306DrawingDemo/SSD1306DrawingDemo.ino @@ -1,117 +1,117 @@ - /** - * The MIT License (MIT) - * - * Copyright (c) 2018 by ThingPulse, Daniel Eichhorn - * Copyright (c) 2018 by Fabrice Weinberg - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - * ThingPulse invests considerable time and money to develop these open source libraries. - * Please support us by buying our products (and not the clones) from - * https://thingpulse.com - * - */ - - // Include the correct display library - // For a connection via I2C using Wire include - #include // Only needed for Arduino 1.6.5 and earlier +/** + The MIT License (MIT) + + Copyright (c) 2018 by ThingPulse, Daniel Eichhorn + Copyright (c) 2018 by Fabrice Weinberg + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. + + ThingPulse invests considerable time and money to develop these open source libraries. + Please support us by buying our products (and not the clones) from + https://thingpulse.com + +*/ + +// Include the correct display library +// For a connection via I2C using Wire include +#include // Only needed for Arduino 1.6.5 and earlier #include "SSD1306Wire.h" // legacy include: `#include "SSD1306.h"` - // or #include "SH1106Wire.h", legacy include: `#include "SH1106.h"` - // For a connection via I2C using brzo_i2c (must be installed) include - // #include // Only needed for Arduino 1.6.5 and earlier - // #include "SSD1306Brzo.h" - // #include "SH1106Brzo.h" - // For a connection via SPI include - // #include // Only needed for Arduino 1.6.5 and earlier - // #include "SSD1306Spi.h" - // #include "SH1106SPi.h" - - // Use the corresponding display class: - - // Initialize the OLED display using SPI - // D5 -> CLK - // D7 -> MOSI (DOUT) - // D0 -> RES - // D2 -> DC - // D8 -> CS - // SSD1306Spi display(D0, D2, D8); - // or - // SH1106Spi display(D0, D2); - - // Initialize the OLED display using brzo_i2c - // D3 -> SDA - // D5 -> SCL - // SSD1306Brzo display(0x3c, D3, D5); - // or - // SH1106Brzo display(0x3c, D3, D5); - - // Initialize the OLED display using Wire library - SSD1306Wire display(0x3c, D3, D5); - // SH1106Wire display(0x3c, D3, D5); +// or #include "SH1106Wire.h", legacy include: `#include "SH1106.h"` +// For a connection via I2C using brzo_i2c (must be installed) include +// #include // Only needed for Arduino 1.6.5 and earlier +// #include "SSD1306Brzo.h" +// #include "SH1106Brzo.h" +// For a connection via SPI include +// #include // Only needed for Arduino 1.6.5 and earlier +// #include "SSD1306Spi.h" +// #include "SH1106SPi.h" + +// Use the corresponding display class: + +// Initialize the OLED display using SPI +// D5 -> CLK +// D7 -> MOSI (DOUT) +// D0 -> RES +// D2 -> DC +// D8 -> CS +// SSD1306Spi display(D0, D2, D8); +// or +// SH1106Spi display(D0, D2); + +// Initialize the OLED display using brzo_i2c +// D3 -> SDA +// D5 -> SCL +// SSD1306Brzo display(0x3c, D3, D5); +// or +// SH1106Brzo display(0x3c, D3, D5); + +// Initialize the OLED display using Wire library +SSD1306Wire display(0x3c, SDA, SCL); // ADDRESS, SDA, SCL - SDA and SCL usually populate automatically based on your board's pins_arduino.h e.g. https://github.com/esp8266/Arduino/blob/master/variants/nodemcu/pins_arduino.h +// SH1106Wire display(0x3c, SDA, SCL); // Adapted from Adafruit_SSD1306 void drawLines() { - for (int16_t i=0; i=0; i-=4) { - display.drawLine(0, display.getHeight()-1, display.getWidth()-1, i); + for (int16_t i = display.getHeight() - 1; i >= 0; i -= 4) { + display.drawLine(0, display.getHeight() - 1, display.getWidth() - 1, i); display.display(); delay(10); } delay(250); display.clear(); - for (int16_t i=display.getWidth()-1; i>=0; i-=4) { - display.drawLine(display.getWidth()-1, display.getHeight()-1, i, 0); + for (int16_t i = display.getWidth() - 1; i >= 0; i -= 4) { + display.drawLine(display.getWidth() - 1, display.getHeight() - 1, i, 0); display.display(); delay(10); } - for (int16_t i=display.getHeight()-1; i>=0; i-=4) { - display.drawLine(display.getWidth()-1, display.getHeight()-1, 0, i); + for (int16_t i = display.getHeight() - 1; i >= 0; i -= 4) { + display.drawLine(display.getWidth() - 1, display.getHeight() - 1, 0, i); display.display(); delay(10); } delay(250); display.clear(); - for (int16_t i=0; i +#include - // OTA Includes - #include - #include +// OTA Includes +#include +#include - const char *ssid = "[Your SSID]"; - const char *password = "[Your Password]"; +const char *ssid = "[Your SSID]"; +const char *password = "[Your Password]"; // Include the correct display library @@ -73,8 +73,8 @@ // SH1106Brzo display(0x3c, D3, D5); // Initialize the OLED display using Wire library -SSD1306Wire display(0x3c, D3, D5); -// SH1106Wire display(0x3c, D3, D5); +SSD1306Wire display(0x3c, SDA, SCL); // ADDRESS, SDA, SCL - SDA and SCL usually populate automatically based on your board's pins_arduino.h e.g. https://github.com/esp8266/Arduino/blob/master/variants/nodemcu/pins_arduino.h +// SH1106Wire display(0x3c, SDA, SCL); void setup() { @@ -94,7 +94,7 @@ void setup() { display.clear(); display.setFont(ArialMT_Plain_10); display.setTextAlignment(TEXT_ALIGN_CENTER_BOTH); - display.drawString(display.getWidth()/2, display.getHeight()/2 - 10, "OTA Update"); + display.drawString(display.getWidth() / 2, display.getHeight() / 2 - 10, "OTA Update"); display.display(); }); @@ -107,14 +107,14 @@ void setup() { display.clear(); display.setFont(ArialMT_Plain_10); display.setTextAlignment(TEXT_ALIGN_CENTER_BOTH); - display.drawString(display.getWidth()/2, display.getHeight()/2, "Restart"); + display.drawString(display.getWidth() / 2, display.getHeight() / 2, "Restart"); display.display(); }); // Align text vertical/horizontal center display.setTextAlignment(TEXT_ALIGN_CENTER_BOTH); display.setFont(ArialMT_Plain_10); - display.drawString(display.getWidth()/2, display.getHeight()/2, "Ready for OTA:\n" + WiFi.localIP().toString()); + display.drawString(display.getWidth() / 2, display.getHeight() / 2, "Ready for OTA:\n" + WiFi.localIP().toString()); display.display(); } diff --git a/examples/SSD1306SimpleDemo/SSD1306SimpleDemo.ino b/examples/SSD1306SimpleDemo/SSD1306SimpleDemo.ino index 3428a9f..e871362 100644 --- a/examples/SSD1306SimpleDemo/SSD1306SimpleDemo.ino +++ b/examples/SSD1306SimpleDemo/SSD1306SimpleDemo.ino @@ -1,33 +1,33 @@ /** - * The MIT License (MIT) - * - * Copyright (c) 2018 by ThingPulse, Daniel Eichhorn - * Copyright (c) 2018 by Fabrice Weinberg - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - * ThingPulse invests considerable time and money to develop these open source libraries. - * Please support us by buying our products (and not the clones) from - * https://thingpulse.com - * - */ - + The MIT License (MIT) + + Copyright (c) 2018 by ThingPulse, Daniel Eichhorn + Copyright (c) 2018 by Fabrice Weinberg + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. + + ThingPulse invests considerable time and money to develop these open source libraries. + Please support us by buying our products (and not the clones) from + https://thingpulse.com + +*/ + // Include the correct display library // For a connection via I2C using the Arduino Wire include: @@ -51,7 +51,7 @@ // Initialize the OLED display using Arduino Wire: -SSD1306Wire display(0x3c, SDA, SCL); // ADDRESS, SDA, SCL - SDA and SCL usually populate automatically based on your board's pins_arduino.h +SSD1306Wire display(0x3c, SDA, SCL); // ADDRESS, SDA, SCL - SDA and SCL usually populate automatically based on your board's pins_arduino.h e.g. https://github.com/esp8266/Arduino/blob/master/variants/nodemcu/pins_arduino.h // SSD1306Wire display(0x3c, D3, D5); // ADDRESS, SDA, SCL - If not, they can be specified manually. // SSD1306Wire display(0x3c, SDA, SCL, GEOMETRY_128_32); // ADDRESS, SDA, SCL, OLEDDISPLAY_GEOMETRY - Extra param required for 128x32 displays. // SH1106Wire display(0x3c, SDA, SCL); // ADDRESS, SDA, SCL @@ -93,26 +93,26 @@ void setup() { } void drawFontFaceDemo() { - // Font Demo1 - // create more fonts at http://oleddisplay.squix.ch/ - display.setTextAlignment(TEXT_ALIGN_LEFT); - display.setFont(ArialMT_Plain_10); - display.drawString(0, 0, "Hello world"); - display.setFont(ArialMT_Plain_16); - display.drawString(0, 10, "Hello world"); - display.setFont(ArialMT_Plain_24); - display.drawString(0, 26, "Hello world"); + // Font Demo1 + // create more fonts at http://oleddisplay.squix.ch/ + display.setTextAlignment(TEXT_ALIGN_LEFT); + display.setFont(ArialMT_Plain_10); + display.drawString(0, 0, "Hello world"); + display.setFont(ArialMT_Plain_16); + display.drawString(0, 10, "Hello world"); + display.setFont(ArialMT_Plain_24); + display.drawString(0, 26, "Hello world"); } void drawTextFlowDemo() { - display.setFont(ArialMT_Plain_10); - display.setTextAlignment(TEXT_ALIGN_LEFT); - display.drawStringMaxWidth(0, 0, 128, - "Lorem ipsum\n dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore." ); + display.setFont(ArialMT_Plain_10); + display.setTextAlignment(TEXT_ALIGN_LEFT); + display.drawStringMaxWidth(0, 0, 128, + "Lorem ipsum\n dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore." ); } void drawTextAlignmentDemo() { - // Text alignment demo + // Text alignment demo display.setFont(ArialMT_Plain_10); // The coordinates define the left starting point of the text @@ -129,31 +129,31 @@ void drawTextAlignmentDemo() { } void drawRectDemo() { - // Draw a pixel at given position - for (int i = 0; i < 10; i++) { - display.setPixel(i, i); - display.setPixel(10 - i, i); - } - display.drawRect(12, 12, 20, 20); + // Draw a pixel at given position + for (int i = 0; i < 10; i++) { + display.setPixel(i, i); + display.setPixel(10 - i, i); + } + display.drawRect(12, 12, 20, 20); - // Fill the rectangle - display.fillRect(14, 14, 17, 17); + // Fill the rectangle + display.fillRect(14, 14, 17, 17); - // Draw a line horizontally - display.drawHorizontalLine(0, 40, 20); + // Draw a line horizontally + display.drawHorizontalLine(0, 40, 20); - // Draw a line horizontally - display.drawVerticalLine(40, 0, 20); + // Draw a line horizontally + display.drawVerticalLine(40, 0, 20); } void drawCircleDemo() { - for (int i=1; i < 8; i++) { + for (int i = 1; i < 8; i++) { display.setColor(WHITE); - display.drawCircle(32, 32, i*3); + display.drawCircle(32, 32, i * 3); if (i % 2 == 0) { display.setColor(BLACK); } - display.fillCircle(96, 32, 32 - i* 3); + display.fillCircle(96, 32, 32 - i * 3); } } @@ -168,9 +168,9 @@ void drawProgressBarDemo() { } void drawImageDemo() { - // see http://blog.squix.org/2015/05/esp8266-nodemcu-how-to-create-xbm.html - // on how to create xbm files - display.drawXbm(34, 14, WiFi_Logo_width, WiFi_Logo_height, WiFi_Logo_bits); + // see http://blog.squix.org/2015/05/esp8266-nodemcu-how-to-create-xbm.html + // on how to create xbm files + display.drawXbm(34, 14, WiFi_Logo_width, WiFi_Logo_height, WiFi_Logo_bits); } Demo demos[] = {drawFontFaceDemo, drawTextFlowDemo, drawTextAlignmentDemo, drawRectDemo, drawCircleDemo, drawProgressBarDemo, drawImageDemo}; @@ -183,8 +183,9 @@ void loop() { // draw the current demo method demos[demoMode](); + display.setFont(ArialMT_Plain_10); display.setTextAlignment(TEXT_ALIGN_RIGHT); - display.drawString(10, 128, String(millis())); + display.drawString(128, 54, String(millis())); // write the buffer to the display display.display(); diff --git a/examples/SSD1306TwoScreenDemo/SSD1306TwoScreenDemo.ino b/examples/SSD1306TwoScreenDemo/SSD1306TwoScreenDemo.ino index b9595d8..aa00989 100644 --- a/examples/SSD1306TwoScreenDemo/SSD1306TwoScreenDemo.ino +++ b/examples/SSD1306TwoScreenDemo/SSD1306TwoScreenDemo.ino @@ -1,31 +1,31 @@ /** - * The MIT License (MIT) - * - * Copyright (c) 2018 by ThingPulse, Daniel Eichhorn - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - * ThingPulse invests considerable time and money to develop these open source libraries. - * Please support us by buying our products (and not the clones) from - * https://thingpulse.com - * - */ + The MIT License (MIT) + + Copyright (c) 2018 by ThingPulse, Daniel Eichhorn + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. + + ThingPulse invests considerable time and money to develop these open source libraries. + Please support us by buying our products (and not the clones) from + https://thingpulse.com + +*/ // Include the correct display library // For a connection via I2C using Wire include diff --git a/examples/SSD1306UiDemo/SSD1306UiDemo.ino b/examples/SSD1306UiDemo/SSD1306UiDemo.ino index 72c836b..a7bd6cd 100644 --- a/examples/SSD1306UiDemo/SSD1306UiDemo.ino +++ b/examples/SSD1306UiDemo/SSD1306UiDemo.ino @@ -1,46 +1,46 @@ /** - * The MIT License (MIT) - * - * Copyright (c) 2018 by ThingPulse, Daniel Eichhorn - * Copyright (c) 2018 by Fabrice Weinberg - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - * ThingPulse invests considerable time and money to develop these open source libraries. - * Please support us by buying our products (and not the clones) from - * https://thingpulse.com - * - */ - - // Include the correct display library - // For a connection via I2C using Wire include - #include // Only needed for Arduino 1.6.5 and earlier - #include "SSD1306Wire.h" // legacy include: `#include "SSD1306.h"` - // or #include "SH1106Wire.h", legacy include: `#include "SH1106.h"` - // For a connection via I2C using brzo_i2c (must be installed) include - // #include // Only needed for Arduino 1.6.5 and earlier - // #include "SSD1306Brzo.h" - // #include "SH1106Brzo.h" - // For a connection via SPI include - // #include // Only needed for Arduino 1.6.5 and earlier - // #include "SSD1306Spi.h" - // #include "SH1106SPi.h" + The MIT License (MIT) + + Copyright (c) 2018 by ThingPulse, Daniel Eichhorn + Copyright (c) 2018 by Fabrice Weinberg + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. + + ThingPulse invests considerable time and money to develop these open source libraries. + Please support us by buying our products (and not the clones) from + https://thingpulse.com + +*/ + +// Include the correct display library +// For a connection via I2C using Wire include +#include // Only needed for Arduino 1.6.5 and earlier +#include "SSD1306Wire.h" // legacy include: `#include "SSD1306.h"` +// or #include "SH1106Wire.h", legacy include: `#include "SH1106.h"` +// For a connection via I2C using brzo_i2c (must be installed) include +// #include // Only needed for Arduino 1.6.5 and earlier +// #include "SSD1306Brzo.h" +// #include "SH1106Brzo.h" +// For a connection via SPI include +// #include // Only needed for Arduino 1.6.5 and earlier +// #include "SSD1306Spi.h" +// #include "SH1106SPi.h" // Include the UI lib #include "OLEDDisplayUi.h" @@ -69,8 +69,8 @@ // SH1106Brzo display(0x3c, D3, D5); // Initialize the OLED display using Wire library -SSD1306Wire display(0x3c, D3, D5); -// SH1106Wire display(0x3c, D3, D5); +SSD1306Wire display(0x3c, SDA, SCL); // ADDRESS, SDA, SCL - SDA and SCL usually populate automatically based on your board's pins_arduino.h e.g. https://github.com/esp8266/Arduino/blob/master/variants/nodemcu/pins_arduino.h +// SH1106Wire display(0x3c, SDA, SCL); OLEDDisplayUi ui ( &display ); @@ -148,12 +148,12 @@ void setup() { Serial.println(); Serial.println(); - // The ESP is capable of rendering 60fps in 80Mhz mode - // but that won't give you much time for anything else - // run it in 160Mhz mode or just set it to 30 fps + // The ESP is capable of rendering 60fps in 80Mhz mode + // but that won't give you much time for anything else + // run it in 160Mhz mode or just set it to 30 fps ui.setTargetFPS(60); - // Customize the active and inactive symbol + // Customize the active and inactive symbol ui.setActiveSymbol(activeSymbol); ui.setInactiveSymbol(inactiveSymbol); From 435ded3c222f17e64d102def76c30f411b890ad6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20St=C3=B6r?= Date: Tue, 1 Jun 2021 22:01:16 +0200 Subject: [PATCH 13/23] Move from Travis-CI to GitHub Actions --- .github/workflows/main.yml | 39 ++++++++++++++++++++++++++++++++++++++ .travis.yml | 29 ---------------------------- 2 files changed, 39 insertions(+), 29 deletions(-) create mode 100644 .github/workflows/main.yml delete mode 100644 .travis.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..6523979 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,39 @@ +# documentation at https://docs.platformio.org/en/latest/integration/ci/github-actions.html + +name: PlatformIO CI + +on: [push] + +jobs: + build: + + runs-on: ubuntu-latest + strategy: + matrix: + example: [examples/SSD1306UiDemo, examples/SSD1306SimpleDemo, examples/SSD1306DrawingDemo, examples/SSD1306OTADemo, examples/SSD1306ClockDemo, examples/SSD1306TwoScreenDemo] + + steps: + - uses: actions/checkout@v2 + - name: Cache pip + uses: actions/cache@v2 + with: + path: ~/.cache/pip + key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }} + restore-keys: ${{ runner.os }}-pip- + - name: Cache PlatformIO + uses: actions/cache@v2 + with: + path: ~/.platformio + key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }} + - name: Set up Python + uses: actions/setup-python@v2 + - name: Install PlatformIO + run: | + python -m pip install --upgrade pip + pip install --upgrade platformio + - name: Install library dependencies + run: pio lib -g install "paulstoffregen/Time@^1.6" + - name: Run PlatformIO + run: pio ci --lib="." --board=nodemcuv2 + env: + PLATFORMIO_CI_SRC: ${{ matrix.example }} diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 49ea5b6..0000000 --- a/.travis.yml +++ /dev/null @@ -1,29 +0,0 @@ -# documentation at https://docs.platformio.org/en/latest/integration/ci/travis.html - -language: python -python: - - "3.7" - -# Cache PlatformIO packages using Travis CI container-based infrastructure -sudo: false -cache: - directories: - - "~/.platformio" - - $HOME/.cache/pip - -env: - - PLATFORMIO_CI_SRC=examples/SSD1306UiDemo - - PLATFORMIO_CI_SRC=examples/SSD1306SimpleDemo - - PLATFORMIO_CI_SRC=examples/SSD1306DrawingDemo - - PLATFORMIO_CI_SRC=examples/SSD1306OTADemo - - PLATFORMIO_CI_SRC=examples/SSD1306ClockDemo - - PLATFORMIO_CI_SRC=examples/SSD1306TwoScreenDemo - - -install: - - pip install -U platformio - - pio update - - platformio lib -g install "paulstoffregen/Time@^1.6" - -script: - - platformio ci --lib="." --board=nodemcuv2 From 815fb1df270501836e257f5b2437399733c87000 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20St=C3=B6r?= Date: Tue, 1 Jun 2021 22:14:03 +0200 Subject: [PATCH 14/23] Add D1 mini --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 6523979..c22a1e3 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -34,6 +34,6 @@ jobs: - name: Install library dependencies run: pio lib -g install "paulstoffregen/Time@^1.6" - name: Run PlatformIO - run: pio ci --lib="." --board=nodemcuv2 + run: pio ci --lib="." --board=nodemcuv2 --board=d1_mini env: PLATFORMIO_CI_SRC: ${{ matrix.example }} From 675ce920a304560538a52b8c0af30dcb92586025 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20St=C3=B6r?= Date: Tue, 1 Jun 2021 22:19:09 +0200 Subject: [PATCH 15/23] Change CI status badge --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 70e92a4..08c7d22 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -[![Build Status](https://travis-ci.com/ThingPulse/esp8266-oled-ssd1306.svg?branch=master)](https://travis-ci.com/ThingPulse/esp8266-oled-ssd1306) +[![Build Status](https://github.com/ThingPulse/esp8266-oled-ssd1306/actions/workflows/main.yml/badge.svg)](https://github.com/ThingPulse/esp8266-oled-ssd1306/actions) # ThingPulse OLED SSD1306 (ESP8266/ESP32/Mbed-OS) From 6ebcd5478282617c387b44c6fb62f8fcde9f4d82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20St=C3=B6r?= Date: Tue, 1 Jun 2021 22:20:36 +0200 Subject: [PATCH 16/23] Add ESP32 ESP-WROVER-KIT --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index c22a1e3..580a7c4 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -34,6 +34,6 @@ jobs: - name: Install library dependencies run: pio lib -g install "paulstoffregen/Time@^1.6" - name: Run PlatformIO - run: pio ci --lib="." --board=nodemcuv2 --board=d1_mini + run: pio ci --lib="." --board=nodemcuv2 --board=d1_mini --board=esp-wrover-kit env: PLATFORMIO_CI_SRC: ${{ matrix.example }} From ad3a109f28461d9a83ebfa6a4a7263984b1794f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20St=C3=B6r?= Date: Tue, 1 Jun 2021 22:29:34 +0200 Subject: [PATCH 17/23] Remove dependency on NodeMCU/WeMos boards --- examples/SSD1306TwoScreenDemo/SSD1306TwoScreenDemo.ino | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/SSD1306TwoScreenDemo/SSD1306TwoScreenDemo.ino b/examples/SSD1306TwoScreenDemo/SSD1306TwoScreenDemo.ino index aa00989..27265e6 100644 --- a/examples/SSD1306TwoScreenDemo/SSD1306TwoScreenDemo.ino +++ b/examples/SSD1306TwoScreenDemo/SSD1306TwoScreenDemo.ino @@ -34,8 +34,8 @@ #include "images.h" // Initialize the OLED display using Wire library -SSD1306Wire display(0x3c, D3, D5); -SSD1306Wire display2(0x3c, D1, D2); +SSD1306Wire display(0x3c, 0, 14); +SSD1306Wire display2(0x3c, 5, 4); void setup() { Serial.begin(115200); From 0992e0e7a9db5e676308b60f535b097f298a6b7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20St=C3=B6r?= Date: Tue, 1 Jun 2021 22:42:03 +0200 Subject: [PATCH 18/23] Make OTA demo ESP32-compatible --- examples/SSD1306OTADemo/SSD1306OTADemo.ino | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/examples/SSD1306OTADemo/SSD1306OTADemo.ino b/examples/SSD1306OTADemo/SSD1306OTADemo.ino index 1ffbe8c..2f51f2e 100644 --- a/examples/SSD1306OTADemo/SSD1306OTADemo.ino +++ b/examples/SSD1306OTADemo/SSD1306OTADemo.ino @@ -28,11 +28,15 @@ */ -// WiFi includes +#if defined(ESP8266) #include - -// OTA Includes #include +#elif defined(ESP32) +#include +#include +#include +#endif + #include const char *ssid = "[Your SSID]"; From 00dc3ff9039b7b4b2bfb08a22e9ce259d55b20e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20St=C3=B6r?= Date: Tue, 1 Jun 2021 22:45:05 +0200 Subject: [PATCH 19/23] Add another ESP32 board --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 580a7c4..7808791 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -34,6 +34,6 @@ jobs: - name: Install library dependencies run: pio lib -g install "paulstoffregen/Time@^1.6" - name: Run PlatformIO - run: pio ci --lib="." --board=nodemcuv2 --board=d1_mini --board=esp-wrover-kit + run: pio ci --lib="." --board=nodemcuv2 --board=d1_mini --board=esp-wrover-kit --board=esp32doit-devkit-v1 env: PLATFORMIO_CI_SRC: ${{ matrix.example }} From f3b1b3232d8e513d6d9ccffbababc36b6a7a4f73 Mon Sep 17 00:00:00 2001 From: Meng Guang Date: Wed, 30 Jun 2021 05:49:28 +0800 Subject: [PATCH 20/23] Change SDA/SCL from uint8_t to int (#348) This allows to assign `-1` to skip the call to `begin()`. --- src/SH1106Wire.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/SH1106Wire.h b/src/SH1106Wire.h index adb7b62..1917712 100644 --- a/src/SH1106Wire.h +++ b/src/SH1106Wire.h @@ -43,8 +43,8 @@ class SH1106Wire : public OLEDDisplay { private: uint8_t _address; - uint8_t _sda; - uint8_t _scl; + int _sda; + int _scl; bool _doI2cAutoInit = false; TwoWire* _wire = NULL; int _frequency; @@ -65,7 +65,7 @@ class SH1106Wire : public OLEDDisplay { * @param _i2cBus on ESP32 with 2 I2C HW buses, I2C_ONE for 1st Bus, I2C_TWO fot 2nd bus, default I2C_ONE * @param _frequency for Frequency by default Let's use ~700khz if ESP8266 is in 160Mhz mode, this will be limited to ~400khz if the ESP8266 in 80Mhz mode */ - SH1106Wire(uint8_t _address, uint8_t _sda, uint8_t _scl, OLEDDISPLAY_GEOMETRY g = GEOMETRY_128_64, HW_I2C _i2cBus = I2C_ONE, int _frequency = 700000) { + SH1106Wire(uint8_t _address, int _sda = -1, int _scl = -1, OLEDDISPLAY_GEOMETRY g = GEOMETRY_128_64, HW_I2C _i2cBus = I2C_ONE, int _frequency = 700000) { setGeometry(g); this->_address = _address; From 87dbeee3e3158018da29b3e296c93954b399b9e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20St=C3=B6r?= Date: Tue, 29 Jun 2021 23:53:35 +0200 Subject: [PATCH 21/23] Also trigger workflow for PRs --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 7808791..c0e1360 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -2,7 +2,7 @@ name: PlatformIO CI -on: [push] +on: [push, pull_request] jobs: build: From e36e76bcd1a163a2903342366e7980f8dd36e26c Mon Sep 17 00:00:00 2001 From: Thijs Triemstra Date: Sat, 24 Jul 2021 21:26:36 +0200 Subject: [PATCH 22/23] Fix typos (#350) --- README.md | 15 +++++++------ src/OLEDDisplayUi.cpp | 52 +++++++++++++++++++++---------------------- src/OLEDDisplayUi.h | 14 ++++++------ 3 files changed, 41 insertions(+), 40 deletions(-) diff --git a/README.md b/README.md index 08c7d22..a2db816 100644 --- a/README.md +++ b/README.md @@ -258,9 +258,10 @@ void setFont(const uint8_t* fontData); ## Ui Library (OLEDDisplayUi) -The Ui Library is used to provide a basic set of Ui elements called, `Frames` and `Overlays`. A `Frame` is used to provide -information the default behaviour is to display a `Frame` for a defined time and than move to the next. The library also provides an `Indicator` that will be updated accordingly. An `Overlay` on the other hand is a pieces of information (e.g. a clock) that is displayed always at the same position. - +The Ui Library is used to provide a basic set of user interface elements called `Frames` and `Overlays`. A `Frame` is used to provide +information to the user. The default behaviour is to display a `Frame` for a defined time and than move to the next `Frame`. The library also +provides an `Indicator` element that will be updated accordingly. An `Overlay` on the other hand is a piece of information (e.g. a clock) that +is always displayed at the same position. ```C++ /** @@ -371,7 +372,7 @@ void setLoadingDrawFunction(LoadingDrawFunction loadingDrawFunction); */ void runLoadingProcess(LoadingStage* stages, uint8_t stagesCount); -// Manuell Controll +// Manual control void nextFrame(); void previousFrame(); @@ -381,7 +382,7 @@ void previousFrame(); void switchToFrame(uint8_t frame); /** - * Transition to frame `frame`, when the `frame` number is bigger than the current + * Transition to frame `frame`. When the `frame` number is bigger than the current * frame the forward animation will be used, otherwise the backwards animation is used. */ void transitionToFrame(uint8_t frame); @@ -401,8 +402,8 @@ int8_t update(); ![DemoFrame1](https://github.com/squix78/esp8266-oled-ssd1306/raw/master/resources/DemoFrame1.jpg) This frame shows three things: - * How to draw an xbm image - * How to draw a static text which is not moved by the frame transition + * How to draw an XMB image + * How to draw static text which is not moved by the frame transition * The active/inactive frame indicators ### Frame 2 diff --git a/src/OLEDDisplayUi.cpp b/src/OLEDDisplayUi.cpp index 778a2e7..3ade99f 100644 --- a/src/OLEDDisplayUi.cpp +++ b/src/OLEDDisplayUi.cpp @@ -59,8 +59,8 @@ OLEDDisplayUi::OLEDDisplayUi(OLEDDisplay *display) { state.frameState = FIXED; state.currentFrame = 0; state.frameTransitionDirection = 1; - state.isIndicatorDrawen = true; - state.manuelControll = false; + state.isIndicatorDrawn = true; + state.manualControl = false; state.userData = NULL; shouldDrawIndicators = true; autoTransition = true; @@ -106,11 +106,11 @@ void OLEDDisplayUi::setTimePerTransition(uint16_t time){ // -/------ Customize indicator position and style -------\- void OLEDDisplayUi::enableIndicator(){ - this->state.isIndicatorDrawen = true; + this->state.isIndicatorDrawn = true; } void OLEDDisplayUi::disableIndicator(){ - this->state.isIndicatorDrawen = false; + this->state.isIndicatorDrawn = false; } void OLEDDisplayUi::enableAllIndicators(){ @@ -179,10 +179,10 @@ void OLEDDisplayUi::runLoadingProcess(LoadingStage* stages, uint8_t stagesCount) delay(150); } -// -/----- Manuel control -----\- +// -/----- Manual control -----\- void OLEDDisplayUi::nextFrame() { if (this->state.frameState != IN_TRANSITION) { - this->state.manuelControll = true; + this->state.manualControl = true; this->state.frameState = IN_TRANSITION; this->state.ticksSinceLastStateSwitch = 0; this->lastTransitionDirection = this->state.frameTransitionDirection; @@ -191,7 +191,7 @@ void OLEDDisplayUi::nextFrame() { } void OLEDDisplayUi::previousFrame() { if (this->state.frameState != IN_TRANSITION) { - this->state.manuelControll = true; + this->state.manualControl = true; this->state.frameState = IN_TRANSITION; this->state.ticksSinceLastStateSwitch = 0; this->lastTransitionDirection = this->state.frameTransitionDirection; @@ -205,7 +205,7 @@ void OLEDDisplayUi::switchToFrame(uint8_t frame) { if (frame == this->state.currentFrame) return; this->state.frameState = FIXED; this->state.currentFrame = frame; - this->state.isIndicatorDrawen = true; + this->state.isIndicatorDrawn = true; } void OLEDDisplayUi::transitionToFrame(uint8_t frame) { @@ -214,7 +214,7 @@ void OLEDDisplayUi::transitionToFrame(uint8_t frame) { if (frame == this->state.currentFrame) return; this->nextFrameNumber = frame; this->lastTransitionDirection = this->state.frameTransitionDirection; - this->state.manuelControll = true; + this->state.manualControl = true; this->state.frameState = IN_TRANSITION; this->state.frameTransitionDirection = frame < this->state.currentFrame ? -1 : 1; } @@ -237,7 +237,7 @@ int16_t OLEDDisplayUi::update(){ #endif int32_t timeBudget = this->updateInterval - (frameStart - this->state.lastUpdate); if ( timeBudget <= 0) { - // Implement frame skipping to ensure time budget is keept + // Implement frame skipping to ensure time budget is kept if (this->autoTransition && this->state.lastUpdate != 0) this->state.ticksSinceLastStateSwitch += ceil((double)-timeBudget / (double)this->updateInterval); this->state.lastUpdate = frameStart; @@ -266,10 +266,10 @@ void OLEDDisplayUi::tick() { } break; case FIXED: - // Revert manuelControll - if (this->state.manuelControll) { + // Revert manualControl + if (this->state.manualControl) { this->state.frameTransitionDirection = this->lastTransitionDirection; - this->state.manuelControll = false; + this->state.manualControl = false; } if (this->state.ticksSinceLastStateSwitch >= this->ticksPerFrame){ if (this->autoTransition){ @@ -294,7 +294,7 @@ void OLEDDisplayUi::resetState() { this->state.ticksSinceLastStateSwitch = 0; this->state.frameState = FIXED; this->state.currentFrame = 0; - this->state.isIndicatorDrawen = true; + this->state.isIndicatorDrawn = true; } void OLEDDisplayUi::drawFrame(){ @@ -337,32 +337,32 @@ void OLEDDisplayUi::drawFrame(){ int8_t dir = this->state.frameTransitionDirection >= 0 ? 1 : -1; x *= dir; y *= dir; x1 *= dir; y1 *= dir; - bool drawenCurrentFrame; + bool drawnCurrentFrame; - // Prope each frameFunction for the indicator Drawen state + // Probe each frameFunction for the indicator drawn state this->enableIndicator(); (this->frameFunctions[this->state.currentFrame])(this->display, &this->state, x, y); - drawenCurrentFrame = this->state.isIndicatorDrawen; + drawnCurrentFrame = this->state.isIndicatorDrawn; this->enableIndicator(); (this->frameFunctions[this->getNextFrameNumber()])(this->display, &this->state, x1, y1); // Build up the indicatorDrawState - if (drawenCurrentFrame && !this->state.isIndicatorDrawen) { - // Drawen now but not next + if (drawnCurrentFrame && !this->state.isIndicatorDrawn) { + // Drawn now but not next this->indicatorDrawState = 2; - } else if (!drawenCurrentFrame && this->state.isIndicatorDrawen) { - // Not drawen now but next + } else if (!drawnCurrentFrame && this->state.isIndicatorDrawn) { + // Not drawn now but next this->indicatorDrawState = 1; - } else if (!drawenCurrentFrame && !this->state.isIndicatorDrawen) { - // Not drawen in both frames + } else if (!drawnCurrentFrame && !this->state.isIndicatorDrawn) { + // Not drawn in both frames this->indicatorDrawState = 3; } // If the indicator isn't draw in the current frame - // reflect it in state.isIndicatorDrawen - if (!drawenCurrentFrame) this->state.isIndicatorDrawen = false; + // reflect it in state.isIndicatorDrawn + if (!drawnCurrentFrame) this->state.isIndicatorDrawn = false; break; } @@ -381,7 +381,7 @@ void OLEDDisplayUi::drawIndicator() { // Only draw if the indicator is invisible // for both frames or // the indiactor is shown and we are IN_TRANSITION - if (this->indicatorDrawState == 3 || (!this->state.isIndicatorDrawen && this->state.frameState != IN_TRANSITION)) { + if (this->indicatorDrawState == 3 || (!this->state.isIndicatorDrawn && this->state.frameState != IN_TRANSITION)) { return; } diff --git a/src/OLEDDisplayUi.h b/src/OLEDDisplayUi.h index 9aa3f32..27a83e8 100644 --- a/src/OLEDDisplayUi.h +++ b/src/OLEDDisplayUi.h @@ -90,12 +90,12 @@ struct OLEDDisplayUiState { FrameState frameState; uint8_t currentFrame; - bool isIndicatorDrawen; + bool isIndicatorDrawn; // Normal = 1, Inverse = -1; int8_t frameTransitionDirection; - bool manuelControll; + bool manualControl; // Custom data that can be used by the user void* userData; @@ -143,10 +143,10 @@ class OLEDDisplayUi { OverlayCallback* overlayFunctions; uint8_t overlayCount; - // Will the Indicator be drawen + // Will the Indicator be drawn // 3 Not drawn in both frames // 2 Drawn this frame but not next - // 1 Not drown this frame but next + // 1 Not drawn this frame but next // 0 Not known yet uint8_t indicatorDrawState; @@ -183,7 +183,7 @@ class OLEDDisplayUi { */ void setTargetFPS(uint8_t fps); - // Automatic Controll + // Automatic Control /** * Enable automatic transition to next frame after the some time can be configured with `setTimePerFrame` and `setTimePerTransition`. */ @@ -201,12 +201,12 @@ class OLEDDisplayUi { void setAutoTransitionBackwards(); /** - * Set the approx. time a frame is displayed + * Set the approximate time a frame is displayed */ void setTimePerFrame(uint16_t time); /** - * Set the approx. time a transition will take + * Set the approximate time a transition will take */ void setTimePerTransition(uint16_t time); From 5030845b9b2ff9ca8941d8f5a30e85ad4fbb4b4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20St=C3=B6r?= Date: Sun, 25 Jul 2021 07:46:48 +0200 Subject: [PATCH 23/23] Bump version --- library.json | 2 +- library.properties | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/library.json b/library.json index acd11ce..c5691b6 100644 --- a/library.json +++ b/library.json @@ -1,6 +1,6 @@ { "name": "ESP8266 and ESP32 OLED driver for SSD1306 displays", - "version": "4.2.0", + "version": "4.2.1", "keywords": "ssd1306, oled, display, i2c", "description": "I2C display driver for SSD1306 OLED displays connected to ESP8266, ESP32, Mbed-OS", "license": "MIT", diff --git a/library.properties b/library.properties index e931a3f..90f5318 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=ESP8266 and ESP32 OLED driver for SSD1306 displays -version=4.2.0 +version=4.2.1 author=ThingPulse, Fabrice Weinberg maintainer=ThingPulse sentence=I2C display driver for SSD1306 OLED displays connected to ESP8266, ESP32, Mbed-OS