Skip to content

Commit 4ab0af1

Browse files
New support for the common SSD1306 I2C Displays
1 parent 40d4479 commit 4ab0af1

File tree

11 files changed

+38
-161
lines changed

11 files changed

+38
-161
lines changed

firmware-esp8266.ino

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@
1616
/**************************************************************************/
1717

1818
#include "src/controller/Bridge.h"
19-
#include "src/output/display/DisplaySSD1306.h"
19+
#include "src/output/display/DisplayOLED128.h"
2020
#include "src/communication/WiFiManager.h"
2121
#include "src/controller/OTA.h"
2222
#include "src/communication/RestServer.h"
2323

2424
Display* display = NULL;
2525

26-
int currentVersion = 29;
26+
int currentVersion = 30;
2727
boolean printMemory = false;
2828

2929
String board = "Generic";
@@ -101,7 +101,9 @@ void setup()
101101
if(displayType!=0)
102102
{
103103
boolean rotateDisplay = (displayRotation == 180);
104-
display = new Display(rotateDisplay, "","",i2cSDAPort,i2cSCLPort);
104+
105+
display = new Display(rotateDisplay, displayType,"",i2cSDAPort,i2cSCLPort);
106+
105107
if(!displayEnabled)
106108
display->clear(true);
107109
}

src/communication/RestServer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
#include "../controller/StateHelper.h"
2626
#include "../controller/UUID.h"
27-
#include "../output/display/DisplaySSD1306.h"
27+
#include "../output/display/DisplayOLED128.h"
2828
#include "../communication/WiFiManager.h"
2929

3030
void startRestServer();

src/communication/WiFiManager.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
/**************************************************************************/
1717

1818
#include "WiFiManager.h"
19-
#include "Hash.h"
2019

2120
extern State state;
2221
extern Display* display;

src/communication/WiFiManager.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,12 @@
2222
#include <ESP8266WebServer.h>
2323
#include <ESP8266mDNS.h>
2424
#include <ArduinoJson.h>
25+
#include "Hash.h"
2526

2627
#ifndef _WiFiManager_h_
2728
#define _WiFiManager_h_
2829

29-
#include "../output/display/DisplaySSD1306.h"
30+
#include "../output/display/DisplayOLED128.h"
3031
#include "../controller/StateHelper.h"
3132
#include "../controller/Bridge.h"
3233

src/controller/Bridge.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -449,11 +449,11 @@ void configureBridge(JsonObject& bridgeConfig) {
449449
displayEnabled = false;
450450
}
451451

452-
if(displayType!=0 && (oldSCL != i2cSCLPort || oldSDA != i2cSDAPort || oldDisplayWidth != displayWidth || oldDisplayHeight != displayHeight))
452+
if(displayType!=0 && (oldSCL != i2cSCLPort || oldSDA != i2cSDAPort || oldDisplayWidth != displayWidth || oldDisplayHeight != displayHeight) || (display!=NULL && display->getType()!=displayType))
453453
{
454454
Serial.println("CREATE TEMP DISPLAY for new I2C Bus!");
455455
boolean rotateDisplay = (displayRotation == 180);
456-
display = new Display(rotateDisplay, "","",i2cSDAPort,i2cSCLPort);
456+
display = new Display(rotateDisplay, displayType,"",i2cSDAPort,i2cSCLPort);
457457
}
458458
else
459459
{
@@ -465,7 +465,7 @@ void configureBridge(JsonObject& bridgeConfig) {
465465
{
466466
Serial.println("CREATE TEMP DISPLAY!");
467467
boolean rotateDisplay = (displayRotation == 180);
468-
display = new Display(rotateDisplay, "","",i2cSDAPort,i2cSCLPort);
468+
display = new Display(rotateDisplay, displayType,"",i2cSDAPort,i2cSCLPort);
469469
}
470470
else if(updateRotation && display!=NULL)
471471
{
@@ -980,7 +980,7 @@ boolean postSensorData(Data* data[], int dataCount)
980980
displayEnabled=true;
981981
boolean rotateDisplay = (displayRotation == 180);
982982
if(display==NULL)
983-
display = new Display(rotateDisplay, "","",i2cSDAPort,i2cSCLPort);
983+
display = new Display(rotateDisplay, displayType,"",i2cSDAPort,i2cSCLPort);
984984
storeDisplayAndPowerConfig(false);
985985
}
986986
else if(payload.equals("dd") && displayEnabled==true)

src/controller/Bridge.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
#include "../input/i2c/SensorBH1750.h"
3434
#include "../input/onewire/SensorDHT.h"
3535
#include "../input/onewire/SensorDallas.h"
36-
#include "../output/display/DisplaySSD1306.h"
36+
#include "../output/display/DisplayOLED128.h"
3737

3838
bool registerBridge();
3939
void restoreBridgeConfig();

src/controller/OTA.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
/**************************************************************************/
1717

1818
#include "OTA.h"
19-
#include "StateHelper.h"
20-
#include "../output/display/DisplaySSD1306.h"
2119

2220
extern State state;
2321
extern Display* display;

src/controller/OTA.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
/**************************************************************************/
1717

1818
#include <ESP8266httpUpdate.h>
19+
#include "StateHelper.h"
20+
#include "../output/display/DisplayOLED128.h"
1921

2022
#ifndef _OTA_h_
2123
#define _OTA_h_

src/input/SensorCalculation.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#define __SensorCalculation_h_
2323

2424
#include "../communication/Data.h"
25-
#include "../output/display/DisplaySSD1306.h"
25+
#include "../output/display/DisplayOLED128.h"
2626

2727
class SensorCalculation {
2828
protected:

src/output/display/DisplaySSD1306.cpp renamed to src/output/display/DisplayOLED128.cpp

Lines changed: 15 additions & 142 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**************************************************************************/
22
/*!
3-
@file DisplaySSD1306.cpp
3+
@file DisplayOLED128.cpp
44
@author M. Fegerl (Sensate Digital Technologies GmbH)
55
@license GPL (see LICENSE file)
66
The Sensate ESP8266 firmware is used to connect ESP8266 based hardware
@@ -15,7 +15,7 @@
1515
*/
1616
/**************************************************************************/
1717

18-
#include "DisplaySSD1306.h"
18+
#include "DisplayOLED128.h"
1919

2020
extern bool isResetting;
2121

@@ -27,7 +27,7 @@ int displayWidth;
2727
int displayRotation;
2828
bool firstSensorData;
2929

30-
Display::Display(bool flip, String type, String address, uint8_t PortSDA, uint8_t PortSCL) {
30+
Display::Display(bool flip, int _type, String address, uint8_t PortSDA, uint8_t PortSCL) {
3131

3232
if(!isResetting)
3333
{
@@ -40,8 +40,12 @@ Display::Display(bool flip, String type, String address, uint8_t PortSDA, uint8_
4040

4141
firstSensorData=true;
4242

43-
display = new SH1106Wire(0x3c, PortSDA, PortSCL, g);
44-
43+
type = _type;
44+
if(_type==2)
45+
display = new SSD1306Wire(0x3c, PortSDA, PortSCL, g);
46+
else
47+
display = new SH1106Wire(0x3c, PortSDA, PortSCL, g);
48+
4549
display->init();
4650
if(flip)
4751
display->flipScreenVertically();
@@ -71,6 +75,11 @@ void Display::flip(int rotation) {
7175
display->resetOrientation();
7276
}
7377

78+
int Display::getType()
79+
{
80+
return type;
81+
}
82+
7483
void Display::drawProductLogo() {
7584

7685
// see http://blog.squix.org/2015/05/esp8266-nodemcu-how-to-create-xbm.html
@@ -247,140 +256,4 @@ void Display::drawValueQuad(int position, String name, String shortName, float v
247256
display->display();
248257
}
249258

250-
}
251-
252-
//void drawLines() {
253-
// for (int16_t i=0; i<display.getWidth(); i+=4) {
254-
// display.drawLine(0, 0, i, display.getHeight()-1);
255-
// display.display();
256-
// delay(10);
257-
// }
258-
// for (int16_t i=0; i<display.getHeight(); i+=4) {
259-
// display.drawLine(0, 0, display.getWidth()-1, i);
260-
// display.display();
261-
// delay(10);
262-
// }
263-
// delay(250);
264-
//
265-
// display.clear();
266-
// for (int16_t i=0; i<display.getWidth(); i+=4) {
267-
// display.drawLine(0, display.getHeight()-1, i, 0);
268-
// display.display();
269-
// delay(10);
270-
// }
271-
// for (int16_t i=display.getHeight()-1; i>=0; i-=4) {
272-
// display.drawLine(0, display.getHeight()-1, display.getWidth()-1, i);
273-
// display.display();
274-
// delay(10);
275-
// }
276-
// delay(250);
277-
//
278-
// display.clear();
279-
// for (int16_t i=display.getWidth()-1; i>=0; i-=4) {
280-
// display.drawLine(display.getWidth()-1, display.getHeight()-1, i, 0);
281-
// display.display();
282-
// delay(10);
283-
// }
284-
// for (int16_t i=display.getHeight()-1; i>=0; i-=4) {
285-
// display.drawLine(display.getWidth()-1, display.getHeight()-1, 0, i);
286-
// display.display();
287-
// delay(10);
288-
// }
289-
// delay(250);
290-
// display.clear();
291-
// for (int16_t i=0; i<display.getHeight(); i+=4) {
292-
// display.drawLine(display.getWidth()-1, 0, 0, i);
293-
// display.display();
294-
// delay(10);
295-
// }
296-
// for (int16_t i=0; i<display.getWidth(); i+=4) {
297-
// display.drawLine(display.getWidth()-1, 0, i, display.getHeight()-1);
298-
// display.display();
299-
// delay(10);
300-
// }
301-
// delay(250);
302-
//}
303-
//
304-
//// Adapted from Adafruit_SSD1306
305-
//void drawRect(void) {
306-
// for (int16_t i=0; i<display.getHeight()/2; i+=2) {
307-
// display.drawRect(i, i, display.getWidth()-2*i, display.getHeight()-2*i);
308-
// display.display();
309-
// delay(10);
310-
// }
311-
//}
312-
//
313-
//// Adapted from Adafruit_SSD1306
314-
//void fillRect(void) {
315-
// uint8_t color = 1;
316-
// for (int16_t i=0; i<display.getHeight()/2; i+=3) {
317-
// display.setColor((color % 2 == 0) ? BLACK : WHITE); // alternate colors
318-
// display.fillRect(i, i, display.getWidth() - i*2, display.getHeight() - i*2);
319-
// display.display();
320-
// delay(10);
321-
// color++;
322-
// }
323-
// // Reset back to WHITE
324-
// display.setColor(WHITE);
325-
//}
326-
//
327-
//// Adapted from Adafruit_SSD1306
328-
//void drawCircle(void) {
329-
// for (int16_t i=0; i<display.getHeight(); i+=2) {
330-
// display.drawCircle(display.getWidth()/2, display.getHeight()/2, i);
331-
// display.display();
332-
// delay(10);
333-
// }
334-
// delay(1000);
335-
// display.clear();
336-
//
337-
// // This will draw the part of the circel in quadrant 1
338-
// // Quadrants are numberd like this:
339-
// // 0010 | 0001
340-
// // ------|-----
341-
// // 0100 | 1000
342-
// //
343-
// display.drawCircleQuads(display.getWidth()/2, display.getHeight()/2, display.getHeight()/4, 0b00000001);
344-
// display.display();
345-
// delay(200);
346-
// display.drawCircleQuads(display.getWidth()/2, display.getHeight()/2, display.getHeight()/4, 0b00000011);
347-
// display.display();
348-
// delay(200);
349-
// display.drawCircleQuads(display.getWidth()/2, display.getHeight()/2, display.getHeight()/4, 0b00000111);
350-
// display.display();
351-
// delay(200);
352-
// display.drawCircleQuads(display.getWidth()/2, display.getHeight()/2, display.getHeight()/4, 0b00001111);
353-
// display.display();
354-
//}
355-
//
356-
//void printBuffer(void) {
357-
// // Initialize the log buffer
358-
// // allocate memory to store 8 lines of text and 30 chars per line.
359-
// display.setLogBuffer(5, 30);
360-
//
361-
// // Some test data
362-
// const char* test[] = {
363-
// "Hello",
364-
// "World" ,
365-
// "----",
366-
// "Show off",
367-
// "how",
368-
// "the log buffer",
369-
// "is",
370-
// "working.",
371-
// "Even",
372-
// "scrolling is",
373-
// "working"
374-
// };
375-
//
376-
// for (uint8_t i = 0; i < 11; i++) {
377-
// display.clear();
378-
// // Print to the screen
379-
// display.println(test[i]);
380-
// // Draw it to the internal screen buffer
381-
// display.drawLogBuffer(0, 0);
382-
// // Display it on the screen
383-
// display.display();
384-
// delay(500);
385-
// }
386-
//}
259+
}

src/output/display/DisplaySSD1306.h renamed to src/output/display/DisplayOLED128.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**************************************************************************/
22
/*!
3-
@file DisplaySSD1306.h
3+
@file DisplayOLED128.h
44
@author M. Fegerl (Sensate Digital Technologies GmbH)
55
@license GPL (see LICENSE file)
66
The Sensate ESP8266 firmware is used to connect ESP8266 based hardware
@@ -18,8 +18,8 @@
1818
#include "SSD1306Wire.h"
1919
#include "SH1106Wire.h"
2020

21-
#ifndef _DisplaySSD1306_h_
22-
#define _DisplaySSD1306_h_
21+
#ifndef _DisplayOLED128_h_
22+
#define _DisplayOLED128_h_
2323

2424
#define Product_Logo_width 128
2525
#define Product_Logo_height 64
@@ -113,9 +113,10 @@ const uint8_t Product_Logo[] PROGMEM = {
113113

114114
class Display {
115115
private:
116-
SH1106Wire *display;
116+
OLEDDisplay *display;
117+
int type;
117118
public:
118-
Display (bool, String, String, uint8_t, uint8_t);
119+
Display (bool, int, String, uint8_t, uint8_t);
119120
void drawProductLogo();
120121
void clear(boolean update);
121122
void drawString(int16_t x, int16_t y, String text);
@@ -127,6 +128,7 @@ class Display {
127128
void drawValue(int position, String name, String shortName, float value, String unit);
128129
void drawValueClassic(int position, String name, String shortName, float value, String uit);
129130
void drawValueQuad(int position, String name, String shortName, float value, String unit);
131+
int getType();
130132
};
131133

132134
#endif

0 commit comments

Comments
 (0)