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
557581void 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