Skip to content

Commit 439a834

Browse files
Added Support for ST7735 Displays, and added new Display Mode (Right Alligned Classic Mode)
1 parent c24ec49 commit 439a834

17 files changed

+756
-255
lines changed

Sensatio_FW_ESP32.cpp

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
SOURCE: https://github.com/sensate-io/firmware-esp32.git
1212
1313
@section HISTORY
14-
v41 - Changed IDE, Sensatio
14+
v41 - Changed IDE, Sensatio, Renamed Display Class to support more types
1515
v40 - New Display Structure to enable Display Rotation, different Styles etc.
1616
v39 - Changed automatic Update to only if required Update (skipping versions to be on par with ESP8266)
1717
v35 - Added Support for VEML6075 and SI1145 UVI Sensors
@@ -24,20 +24,20 @@
2424
VisualisationHelper* vHelper;
2525
Display* display = NULL;
2626

27-
int currentVersion = 40;
27+
int currentVersion = 41;
2828
boolean printMemory = false;
2929

30-
String board = "Generic";
31-
char firmwareType[] = "ESP32";
30+
//String board = "Generic";
31+
//char firmwareType[] = "ESP32";
3232

3333
// String board = "DevKitC";
3434
// char firmwareType[] = "ESP32-DevKitC";
3535

3636
// String board = "ESP32S";
3737
// char firmwareType[] = "ESP32-S";
3838

39-
// String board = "ESP-WROOM-32";
40-
// char firmwareType[] = "ESP32-WROOM";
39+
String board = "ESP-WROOM-32";
40+
char firmwareType[] = "ESP32-WROOM";
4141

4242
// String board = "M5StickC";
4343
// char firmwareType[] = "ESP32-M5StickC";
@@ -61,12 +61,15 @@ unsigned long previousTickerMillis = 0;
6161
unsigned long currentMillis;
6262
State state = Boot;
6363

64-
esp_sleep_wakeup_cause_t resetInfo;
64+
int displayMode;
65+
boolean displayEnabled;
66+
int displayType;
67+
int displayHeight;
68+
int displayWidth;
69+
int displayRotation;
70+
bool firstSensorData;
6571

66-
extern int displayType;
67-
extern boolean displayEnabled;
68-
extern int displayRotation;
69-
extern int displayMode;
72+
esp_sleep_wakeup_cause_t resetInfo;
7073

7174
extern uint8_t i2cSDAPort;
7275
extern uint8_t i2cSCLPort;
@@ -108,7 +111,15 @@ void setup()
108111
{
109112
boolean rotateDisplay = (displayRotation == 180);
110113

111-
display = new Display(rotateDisplay, displayType,"",i2cSDAPort,i2cSCLPort);
114+
switch(displayType)
115+
{
116+
case 3:
117+
display = new DisplayST7735(rotateDisplay, displayType);
118+
break;
119+
default: // Fallback to OLED init
120+
display = new DisplayOLED128(displayWidth, displayHeight, rotateDisplay, displayType,"",i2cSDAPort,i2cSCLPort);
121+
break;
122+
}
112123

113124
if(!displayEnabled)
114125
display->clear(true);

Sensatio_FW_ESP32.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
SOURCE: https://github.com/sensate-io/firmware-esp32.git
1212
1313
@section HISTORY
14-
v41 - Changed IDE, Sensatio
14+
v41 - Changed IDE, Sensatio, Renamed Display Class to support more types
1515
*/
1616
/**************************************************************************/
1717

@@ -27,7 +27,7 @@
2727

2828
//add your includes for the project Sensatio_FW_ESP32 here
2929
#include "src/controller/Bridge.h"
30-
#include "src/output/display/DisplayOLED128.h"
30+
#include "src/output/display/Display.h"
3131
#include "src/communication/WiFiManager.h"
3232
#include "src/controller/OTA.h"
3333
#include "src/communication/RestServer.h"

src/communication/RestServer.cpp

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
@file RestServer.cpp
44
@author M. Fegerl (Sensate Digital Solutions GmbH)
55
@license GPL (see LICENSE file)
6-
The Sensate ESP32 firmware is used to connect ESP32 based hardware
7-
with the Sensate Cloud and the Sensate apps.
6+
The Sensatio ESP32 firmware is used to connect ESP32 based hardware
7+
with the Sensatio Cloud and the Sensatio apps.
88
9-
----> https://www.sensate.io
9+
----> https://www.sensatio.io
1010
1111
SOURCE: https://github.com/sensate-io/firmware-esp8266.git
1212
@@ -21,11 +21,8 @@ WebServer http_rest_server(80);
2121

2222
extern State state;
2323
extern IPAddress apIP;
24-
extern IPAddress netMsk;
25-
extern const byte DNS_PORT;
2624
extern const char *myHostname;
2725
extern Display* display;
28-
extern String bridgeURL;
2926
extern MQTT* mqtt;
3027
extern boolean enableMQTT;
3128

@@ -339,9 +336,9 @@ void returnNetworkList() {
339336
for (int i = 0; i < numberOfNetworks; i++) {
340337

341338
JsonObject& network = jsonBuffer.createObject();
342-
network["name"] = WiFi.SSID(i);
339+
network["name"] = WiFi.SSID(i); // @suppress("Invalid arguments")
343340
network["enc"] = (WiFi.encryptionType(i) == WIFI_AUTH_OPEN) ? false : true;
344-
network["rssi"] = WiFi.RSSI(i);
341+
network["rssi"] = WiFi.RSSI(i); // @suppress("Invalid arguments")
345342

346343
root.add(network);
347344
}
@@ -365,15 +362,15 @@ void presentWiFiSetupScreen() {
365362

366363
for (int i = 0; i < numberOfNetworks; i++) {
367364

368-
networks[i] = WiFi.SSID(i) + " (" + WiFi.RSSI(i) + "ddBm)";
365+
networks[i] = WiFi.SSID(i) + " (" + WiFi.RSSI(i) + "ddBm)"; // @suppress("Invalid arguments")
369366
// Serial.println("Network: " + networks[i]);
370367

371368
}
372369

373370
restoreBridgeConfig();
374371
String wifiResponse = "<html><body style='width:600;margin-left:auto;margin-right:auto;font-family:verdana'><br/><br/><h1>Welcome to your Sensate Bridge</h1><br/><br/><form action='/manualsetup' method='post'><table width='100%'><tr><td colspan='2'><h2>Wireless LAN Configuration</h2></td></tr><tr><td align='right'><b>SSID/Name</b></td><td><select name='ssid'>";
375372
for (int i = 0; i < numberOfNetworks; i++) {
376-
wifiResponse = wifiResponse + "<option value='" + WiFi.SSID(i) + "'>" + WiFi.SSID(i) + " (" + WiFi.RSSI(i) + "ddBm)</option>";
373+
wifiResponse = wifiResponse + "<option value='" + WiFi.SSID(i) + "'>" + WiFi.SSID(i) + " (" + WiFi.RSSI(i) + "ddBm)</option>"; // @suppress("Invalid arguments")
377374
}
378375

379376
wifiResponse = wifiResponse + "</select></td></tr><tr><td align='right'><b>Password</b></td><td><input type='password' name='password' value='' maxlength='63' placeholder='leave empty if unencrypted' size='30'/></td></tr><tr><td colspan='2'>&nbsp;</td></tr><tr><td colspan='2'><h2>Service Configuration</h2></td></tr><tr><td align='right'><b>SensorHub Location</b></td><td><input type='text' name='url' value='https://hub.sensate.cloud' maxlength='100' placeholder='Service Backend URL' size='40'/></td></tr><tr><td align='right'><b>Device Name</b></td><td><input type='text' name='identifier' value='Bridge' maxlength='100' placeholder='Bridge Name' size='40'/></td></tr><tr><td colspan='2'>&nbsp;</td></tr><tr><td colspan='2'>&nbsp;</td></tr><tr><td colspan='2' align='center'><input type='submit' value='Save and restart' style='height: 25px; width: 100px;'/></td></tr></table></form></body></html>";
@@ -426,4 +423,4 @@ bool isIp(String str) {
426423
}
427424
}
428425
return true;
429-
}
426+
}

src/communication/RestServer.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
@file RestServer.h
44
@author M. Fegerl (Sensate Digital Solutions GmbH)
55
@license GPL (see LICENSE file)
6-
The Sensate ESP32 firmware is used to connect ESP32 based hardware
7-
with the Sensate Cloud and the Sensate apps.
6+
The Sensatio ESP32 firmware is used to connect ESP32 based hardware
7+
with the Sensatio Cloud and the Sensatio apps.
88
9-
----> https://www.sensate.io
9+
----> https://www.sensatio.io
1010
1111
SOURCE: https://github.com/sensate-io/firmware-esp8266.git
1212
@@ -24,7 +24,7 @@
2424

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

@@ -48,4 +48,4 @@ void initMqtt();
4848
String toStringIp(IPAddress ip);
4949
bool isIp(String str);
5050

51-
#endif
51+
#endif

src/communication/WiFiManager.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33
@file WiFiManager.cpp
44
@author M. Fegerl (Sensate Digital Solutions GmbH)
55
@license GPL (see LICENSE file)
6-
The Sensate ESP32 firmware is used to connect ESP32 based hardware
7-
with the Sensate Cloud and the Sensate apps.
6+
The Sensatio ESP32 firmware is used to connect ESP32 based hardware
7+
with the Sensatio Cloud and the Sensatio apps.
88
9-
----> https://www.sensate.io
9+
----> https://www.sensatio.io
1010
1111
SOURCE: https://github.com/sensate-io/firmware-esp8266.git
1212
1313
@section HISTORY
14+
v41 - Renamed Display Class to support more types
1415
v34 - First Public Release (Feature parity with ESP8266 Release v34)
1516
*/
1617
/**************************************************************************/
@@ -427,4 +428,4 @@ void loopDNS() {
427428

428429
dnsServer.processNextRequest();
429430

430-
}
431+
}

src/communication/WiFiManager.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
#ifndef _WiFiManager_h_
2727
#define _WiFiManager_h_
2828

29-
#include "../output/display/DisplayOLED128.h"
29+
#include "../output/display/Display.h"
3030
#include "../controller/StateHelper.h"
3131
#include "../controller/Bridge.h"
3232

@@ -41,4 +41,4 @@ void startDNS();
4141
void loopDNS();
4242
void checkWiFiStatus();
4343

44-
#endif
44+
#endif

src/controller/Bridge.cpp

Lines changed: 49 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33
@file Bridge.cpp
44
@author M. Fegerl (Sensate Digital Solutions GmbH)
55
@license GPL (see LICENSE file)
6-
The Sensate ESP32 firmware is used to connect ESP32 based hardware
7-
with the Sensate Cloud and the Sensate apps.
6+
The Sensatio ESP32 firmware is used to connect ESP32 based hardware
7+
with the Sensatio Cloud and the Sensatio apps.
88
9-
----> https://www.sensate.io
9+
----> https://www.sensatio.io
1010
1111
SOURCE: https://github.com/sensate-io/firmware-esp8266.git
1212
1313
@section HISTORY
14+
v41 - Renamed Display Class to support more types
1415
v40 - New Display Structure to enable Display Rotation, different Styles etc.
1516
v35 - Added Support for VEML6075 and SI1145 UVI Sensors
1617
v34 - First Public Release (Feature parity with ESP8266 Release v34)
@@ -517,11 +518,23 @@ void configureBridge(JsonObject& bridgeConfig) {
517518
displayEnabled = false;
518519
}
519520

520-
if((displayType!=0) && (((oldSCL != i2cSCLPort) || (oldSDA != i2cSDAPort) || (oldDisplayWidth != displayWidth) || (oldDisplayHeight != displayHeight)) || ((display!=NULL) && (display->getType()!=displayType))))
521+
boolean requireInitI2C = true;
522+
523+
if(((displayType==1 || displayType==2)) && (((oldSCL != i2cSCLPort) || (oldSDA != i2cSDAPort) || (oldDisplayWidth != displayWidth) || (oldDisplayHeight != displayHeight)) || ((display!=NULL) && (display->getType()!=displayType))))
521524
{
522-
Serial.println("CREATE TEMP DISPLAY for new I2C Bus!");
525+
Serial.println("CREATE TEMP DISPLAY FOR NEW CONFIG");
523526
boolean rotateDisplay = (displayRotation == 180);
524-
display = new Display(rotateDisplay, displayType,"",i2cSDAPort,i2cSCLPort);
527+
528+
switch(displayType)
529+
{
530+
case 3:
531+
display = new DisplayST7735(rotateDisplay, displayType);
532+
break;
533+
default: // Fallback to OLED init
534+
display = new DisplayOLED128(displayWidth, displayHeight, rotateDisplay, displayType,"",i2cSDAPort,i2cSCLPort);
535+
requireInitI2C=false;
536+
break;
537+
}
525538
}
526539
else
527540
{
@@ -531,21 +544,32 @@ void configureBridge(JsonObject& bridgeConfig) {
531544
}
532545
else if(display==NULL && displayType!=0)
533546
{
534-
Serial.println("CREATE TEMP DISPLAY!");
535-
boolean rotateDisplay = (displayRotation == 180);
536-
display = new Display(rotateDisplay, displayType,"",i2cSDAPort,i2cSCLPort);
547+
Serial.println("CREATE TEMP DISPLAY!");
548+
boolean rotateDisplay = (displayRotation == 180);
549+
switch(displayType)
550+
{
551+
case 3:
552+
display = new DisplayST7735(rotateDisplay, displayType);
553+
break;
554+
default: // Fallback to OLED init
555+
display = new DisplayOLED128(displayWidth, displayHeight, rotateDisplay, displayType,"",i2cSDAPort,i2cSCLPort);
556+
requireInitI2C=false;
557+
break;
558+
}
537559
}
538560
else if(updateRotation && display!=NULL)
539561
{
540562
Serial.println("FLIP!");
541563
display->flip(displayRotation);
542564
}
543-
else if(displayType==0)
565+
}
566+
567+
if(requireInitI2C)
544568
{
545-
Serial.println("Init I2C Bus: SDA-"+String(i2cSDAPort)+", SCL-"+String(i2cSCLPort));
546-
Wire.begin(i2cSDAPort, i2cSCLPort);
569+
Serial.println("Init I2C Bus: SDA-"+String(i2cSDAPort)+", SCL-"+String(i2cSCLPort));
570+
Wire.begin(i2cSDAPort, i2cSCLPort);
547571
}
548-
}
572+
549573

550574
tryInitMQTT();
551575

@@ -556,13 +580,6 @@ void configureBridge(JsonObject& bridgeConfig) {
556580

557581
void initVisualisationHelper(JsonObject& bridgeConfig) {
558582

559-
int simultanValueCount;
560-
561-
if(displayHeight==64)
562-
simultanValueCount = 4;
563-
else if(displayHeight==32)
564-
simultanValueCount = 2;
565-
566583
unsigned long displayCycleInterval = bridgeConfig["di"];
567584

568585
if(displayCycleInterval==0)
@@ -571,7 +588,7 @@ void initVisualisationHelper(JsonObject& bridgeConfig) {
571588
}
572589
else
573590
{
574-
vHelper->enableDisplayCycle(millis(), simultanValueCount, displayCycleInterval);
591+
vHelper->enableDisplayCycle(millis(), display->getSimultanValueCount(), displayCycleInterval);
575592
}
576593

577594

@@ -1242,7 +1259,17 @@ boolean postSensorData(Data* data[], int dataCount)
12421259
displayEnabled=true;
12431260
boolean rotateDisplay = (displayRotation == 180);
12441261
if(display==NULL)
1245-
display = new Display(rotateDisplay, displayType,"",i2cSDAPort,i2cSCLPort);
1262+
{
1263+
switch(displayType)
1264+
{
1265+
case 3:
1266+
display = new DisplayST7735(rotateDisplay, displayType);
1267+
break;
1268+
default: // Fallback to OLED init
1269+
display = new DisplayOLED128(displayWidth, displayHeight, rotateDisplay, displayType,"",i2cSDAPort,i2cSCLPort);
1270+
break;
1271+
}
1272+
}
12461273
storeDisplayAndPowerConfig(false);
12471274
}
12481275
else if(payload.equals("dd") && displayEnabled==true)

0 commit comments

Comments
 (0)