Skip to content

Commit

Permalink
New support for the common SSD1306 I2C Displays
Browse files Browse the repository at this point in the history
  • Loading branch information
Manuel-Sensate committed May 18, 2020
1 parent 40d4479 commit 4ab0af1
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 161 deletions.
8 changes: 5 additions & 3 deletions firmware-esp8266.ino
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@
/**************************************************************************/

#include "src/controller/Bridge.h"
#include "src/output/display/DisplaySSD1306.h"
#include "src/output/display/DisplayOLED128.h"
#include "src/communication/WiFiManager.h"
#include "src/controller/OTA.h"
#include "src/communication/RestServer.h"

Display* display = NULL;

int currentVersion = 29;
int currentVersion = 30;
boolean printMemory = false;

String board = "Generic";
Expand Down Expand Up @@ -101,7 +101,9 @@ void setup()
if(displayType!=0)
{
boolean rotateDisplay = (displayRotation == 180);
display = new Display(rotateDisplay, "","",i2cSDAPort,i2cSCLPort);

display = new Display(rotateDisplay, displayType,"",i2cSDAPort,i2cSCLPort);

if(!displayEnabled)
display->clear(true);
}
Expand Down
2 changes: 1 addition & 1 deletion src/communication/RestServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

#include "../controller/StateHelper.h"
#include "../controller/UUID.h"
#include "../output/display/DisplaySSD1306.h"
#include "../output/display/DisplayOLED128.h"
#include "../communication/WiFiManager.h"

void startRestServer();
Expand Down
1 change: 0 additions & 1 deletion src/communication/WiFiManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
/**************************************************************************/

#include "WiFiManager.h"
#include "Hash.h"

extern State state;
extern Display* display;
Expand Down
3 changes: 2 additions & 1 deletion src/communication/WiFiManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>
#include <ArduinoJson.h>
#include "Hash.h"

#ifndef _WiFiManager_h_
#define _WiFiManager_h_

#include "../output/display/DisplaySSD1306.h"
#include "../output/display/DisplayOLED128.h"
#include "../controller/StateHelper.h"
#include "../controller/Bridge.h"

Expand Down
8 changes: 4 additions & 4 deletions src/controller/Bridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -449,11 +449,11 @@ void configureBridge(JsonObject& bridgeConfig) {
displayEnabled = false;
}

if(displayType!=0 && (oldSCL != i2cSCLPort || oldSDA != i2cSDAPort || oldDisplayWidth != displayWidth || oldDisplayHeight != displayHeight))
if(displayType!=0 && (oldSCL != i2cSCLPort || oldSDA != i2cSDAPort || oldDisplayWidth != displayWidth || oldDisplayHeight != displayHeight) || (display!=NULL && display->getType()!=displayType))
{
Serial.println("CREATE TEMP DISPLAY for new I2C Bus!");
boolean rotateDisplay = (displayRotation == 180);
display = new Display(rotateDisplay, "","",i2cSDAPort,i2cSCLPort);
display = new Display(rotateDisplay, displayType,"",i2cSDAPort,i2cSCLPort);
}
else
{
Expand All @@ -465,7 +465,7 @@ void configureBridge(JsonObject& bridgeConfig) {
{
Serial.println("CREATE TEMP DISPLAY!");
boolean rotateDisplay = (displayRotation == 180);
display = new Display(rotateDisplay, "","",i2cSDAPort,i2cSCLPort);
display = new Display(rotateDisplay, displayType,"",i2cSDAPort,i2cSCLPort);
}
else if(updateRotation && display!=NULL)
{
Expand Down Expand Up @@ -980,7 +980,7 @@ boolean postSensorData(Data* data[], int dataCount)
displayEnabled=true;
boolean rotateDisplay = (displayRotation == 180);
if(display==NULL)
display = new Display(rotateDisplay, "","",i2cSDAPort,i2cSCLPort);
display = new Display(rotateDisplay, displayType,"",i2cSDAPort,i2cSCLPort);
storeDisplayAndPowerConfig(false);
}
else if(payload.equals("dd") && displayEnabled==true)
Expand Down
2 changes: 1 addition & 1 deletion src/controller/Bridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
#include "../input/i2c/SensorBH1750.h"
#include "../input/onewire/SensorDHT.h"
#include "../input/onewire/SensorDallas.h"
#include "../output/display/DisplaySSD1306.h"
#include "../output/display/DisplayOLED128.h"

bool registerBridge();
void restoreBridgeConfig();
Expand Down
2 changes: 0 additions & 2 deletions src/controller/OTA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
/**************************************************************************/

#include "OTA.h"
#include "StateHelper.h"
#include "../output/display/DisplaySSD1306.h"

extern State state;
extern Display* display;
Expand Down
2 changes: 2 additions & 0 deletions src/controller/OTA.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
/**************************************************************************/

#include <ESP8266httpUpdate.h>
#include "StateHelper.h"
#include "../output/display/DisplayOLED128.h"

#ifndef _OTA_h_
#define _OTA_h_
Expand Down
2 changes: 1 addition & 1 deletion src/input/SensorCalculation.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#define __SensorCalculation_h_

#include "../communication/Data.h"
#include "../output/display/DisplaySSD1306.h"
#include "../output/display/DisplayOLED128.h"

class SensorCalculation {
protected:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**************************************************************************/
/*!
@file DisplaySSD1306.cpp
@file DisplayOLED128.cpp
@author M. Fegerl (Sensate Digital Technologies GmbH)
@license GPL (see LICENSE file)
The Sensate ESP8266 firmware is used to connect ESP8266 based hardware
Expand All @@ -15,7 +15,7 @@
*/
/**************************************************************************/

#include "DisplaySSD1306.h"
#include "DisplayOLED128.h"

extern bool isResetting;

Expand All @@ -27,7 +27,7 @@ int displayWidth;
int displayRotation;
bool firstSensorData;

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

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

firstSensorData=true;

display = new SH1106Wire(0x3c, PortSDA, PortSCL, g);

type = _type;
if(_type==2)
display = new SSD1306Wire(0x3c, PortSDA, PortSCL, g);
else
display = new SH1106Wire(0x3c, PortSDA, PortSCL, g);

display->init();
if(flip)
display->flipScreenVertically();
Expand Down Expand Up @@ -71,6 +75,11 @@ void Display::flip(int rotation) {
display->resetOrientation();
}

int Display::getType()
{
return type;
}

void Display::drawProductLogo() {

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

}

//void drawLines() {
// for (int16_t i=0; i<display.getWidth(); i+=4) {
// display.drawLine(0, 0, i, display.getHeight()-1);
// display.display();
// delay(10);
// }
// for (int16_t i=0; i<display.getHeight(); i+=4) {
// display.drawLine(0, 0, display.getWidth()-1, i);
// display.display();
// delay(10);
// }
// delay(250);
//
// display.clear();
// for (int16_t i=0; i<display.getWidth(); i+=4) {
// display.drawLine(0, display.getHeight()-1, i, 0);
// display.display();
// delay(10);
// }
// 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);
// 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);
// display.display();
// delay(10);
// }
// delay(250);
// display.clear();
// for (int16_t i=0; i<display.getHeight(); i+=4) {
// display.drawLine(display.getWidth()-1, 0, 0, i);
// display.display();
// delay(10);
// }
// for (int16_t i=0; i<display.getWidth(); i+=4) {
// display.drawLine(display.getWidth()-1, 0, i, display.getHeight()-1);
// display.display();
// delay(10);
// }
// delay(250);
//}
//
//// Adapted from Adafruit_SSD1306
//void drawRect(void) {
// for (int16_t i=0; i<display.getHeight()/2; i+=2) {
// display.drawRect(i, i, display.getWidth()-2*i, display.getHeight()-2*i);
// display.display();
// delay(10);
// }
//}
//
//// Adapted from Adafruit_SSD1306
//void fillRect(void) {
// uint8_t color = 1;
// for (int16_t i=0; i<display.getHeight()/2; i+=3) {
// display.setColor((color % 2 == 0) ? BLACK : WHITE); // alternate colors
// display.fillRect(i, i, display.getWidth() - i*2, display.getHeight() - i*2);
// display.display();
// delay(10);
// color++;
// }
// // Reset back to WHITE
// display.setColor(WHITE);
//}
//
//// Adapted from Adafruit_SSD1306
//void drawCircle(void) {
// for (int16_t i=0; i<display.getHeight(); i+=2) {
// display.drawCircle(display.getWidth()/2, display.getHeight()/2, i);
// display.display();
// delay(10);
// }
// delay(1000);
// display.clear();
//
// // This will draw the part of the circel in quadrant 1
// // Quadrants are numberd like this:
// // 0010 | 0001
// // ------|-----
// // 0100 | 1000
// //
// display.drawCircleQuads(display.getWidth()/2, display.getHeight()/2, display.getHeight()/4, 0b00000001);
// display.display();
// delay(200);
// display.drawCircleQuads(display.getWidth()/2, display.getHeight()/2, display.getHeight()/4, 0b00000011);
// display.display();
// delay(200);
// display.drawCircleQuads(display.getWidth()/2, display.getHeight()/2, display.getHeight()/4, 0b00000111);
// display.display();
// delay(200);
// display.drawCircleQuads(display.getWidth()/2, display.getHeight()/2, display.getHeight()/4, 0b00001111);
// display.display();
//}
//
//void printBuffer(void) {
// // Initialize the log buffer
// // allocate memory to store 8 lines of text and 30 chars per line.
// display.setLogBuffer(5, 30);
//
// // Some test data
// const char* test[] = {
// "Hello",
// "World" ,
// "----",
// "Show off",
// "how",
// "the log buffer",
// "is",
// "working.",
// "Even",
// "scrolling is",
// "working"
// };
//
// for (uint8_t i = 0; i < 11; i++) {
// display.clear();
// // Print to the screen
// display.println(test[i]);
// // Draw it to the internal screen buffer
// display.drawLogBuffer(0, 0);
// // Display it on the screen
// display.display();
// delay(500);
// }
//}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**************************************************************************/
/*!
@file DisplaySSD1306.h
@file DisplayOLED128.h
@author M. Fegerl (Sensate Digital Technologies GmbH)
@license GPL (see LICENSE file)
The Sensate ESP8266 firmware is used to connect ESP8266 based hardware
Expand All @@ -18,8 +18,8 @@
#include "SSD1306Wire.h"
#include "SH1106Wire.h"

#ifndef _DisplaySSD1306_h_
#define _DisplaySSD1306_h_
#ifndef _DisplayOLED128_h_
#define _DisplayOLED128_h_

#define Product_Logo_width 128
#define Product_Logo_height 64
Expand Down Expand Up @@ -113,9 +113,10 @@ const uint8_t Product_Logo[] PROGMEM = {

class Display {
private:
SH1106Wire *display;
OLEDDisplay *display;
int type;
public:
Display (bool, String, String, uint8_t, uint8_t);
Display (bool, int, String, uint8_t, uint8_t);
void drawProductLogo();
void clear(boolean update);
void drawString(int16_t x, int16_t y, String text);
Expand All @@ -127,6 +128,7 @@ class Display {
void drawValue(int position, String name, String shortName, float value, String unit);
void drawValueClassic(int position, String name, String shortName, float value, String uit);
void drawValueQuad(int position, String name, String shortName, float value, String unit);
int getType();
};

#endif

0 comments on commit 4ab0af1

Please sign in to comment.