diff --git a/src/platformio.ini b/src/platformio.ini index d64a8c93a..897cd451b 100644 --- a/src/platformio.ini +++ b/src/platformio.ini @@ -104,8 +104,8 @@ lib_deps = paulstoffregen/Time https://github.com/bertmelis/espMqttClient#v1.3.3 bblanchon/ArduinoJson - olikraus/U8g2 https://github.com/JChristensen/Timezone + olikraus/U8g2 [env:esp8266-ssd1306] platform = espressif8266 @@ -122,8 +122,8 @@ lib_deps = paulstoffregen/Time https://github.com/bertmelis/espMqttClient#v1.3.3 bblanchon/ArduinoJson - https://github.com/ThingPulse/esp8266-oled-ssd1306.git https://github.com/JChristensen/Timezone + olikraus/U8g2 [env:esp8266-sh1106] platform = espressif8266 @@ -140,8 +140,8 @@ lib_deps = paulstoffregen/Time https://github.com/bertmelis/espMqttClient#v1.3.3 bblanchon/ArduinoJson - https://github.com/ThingPulse/esp8266-oled-ssd1306.git https://github.com/JChristensen/Timezone + olikraus/U8g2 [env:esp32-wroom32-release] platform = espressif32 @@ -179,8 +179,8 @@ lib_deps = paulstoffregen/Time https://github.com/bertmelis/espMqttClient#v1.3.3 bblanchon/ArduinoJson - olikraus/U8g2 https://github.com/JChristensen/Timezone + olikraus/U8g2 [env:esp32-wroom32-ssd1306] platform = espressif32 @@ -199,6 +199,7 @@ lib_deps = bblanchon/ArduinoJson https://github.com/ThingPulse/esp8266-oled-ssd1306.git https://github.com/JChristensen/Timezone + olikraus/U8g2 [env:esp32-wroom32-sh1106] platform = espressif32 @@ -216,4 +217,5 @@ lib_deps = https://github.com/bertmelis/espMqttClient#v1.3.3 bblanchon/ArduinoJson https://github.com/ThingPulse/esp8266-oled-ssd1306.git - https://github.com/JChristensen/Timezone \ No newline at end of file + https://github.com/JChristensen/Timezone + olikraus/U8g2 \ No newline at end of file diff --git a/src/plugins/MonochromeDisplay/MonochromeDisplay.h b/src/plugins/MonochromeDisplay/MonochromeDisplay.h index 3bfe94589..51c105db4 100644 --- a/src/plugins/MonochromeDisplay/MonochromeDisplay.h +++ b/src/plugins/MonochromeDisplay/MonochromeDisplay.h @@ -1,19 +1,13 @@ #ifndef __MONOCHROME_DISPLAY__ #define __MONOCHROME_DISPLAY__ +/* esp8266 : SCL = 5, SDA = 4 */ +/* ewsp32 : SCL = 22, SDA = 21 */ #if defined(ENA_NOKIA) || defined(ENA_SSD1306) || defined(ENA_SH1106) +#include #ifdef ENA_NOKIA - #include #define DISP_PROGMEM U8X8_PROGMEM #else // ENA_SSD1306 || ENA_SH1106 - /* esp8266 : SCL = 5, SDA = 4 */ - /* ewsp32 : SCL = 22, SDA = 21 */ - #include - #ifdef ENA_SSD1306 - #include - # else //ENA_SH1106 - #include - #endif #define DISP_PROGMEM PROGMEM #endif @@ -22,6 +16,27 @@ #include "../../utils/helper.h" #include "../../hm/hmSystem.h" + +static uint8_t bmp_logo[] PROGMEM = { + B00000000,B00000000, // ................ + B11101100,B00110111, // ..##.######.##.. + B11101100,B00110111, // ..##.######.##.. + B11100000,B00000111, // .....######..... + B11010000,B00001011, // ....#.####.#.... + B10011000,B00011001, // ...##..##..##... + B10000000,B00000001, // .......##....... + B00000000,B00000000, // ................ + B01111000,B00011110, // ...####..####... + B11111100,B00111111, // ..############.. + B01111100,B00111110, // ..#####..#####.. + B00000000,B00000000, // ................ + B11111100,B00111111, // ..############.. + B11111110,B01111111, // .##############. + B01111110,B01111110, // .######..######. + B00000000,B00000000 // ................ +}; + + static uint8_t bmp_arrow[] DISP_PROGMEM = { B00000000, B00011100, B00011100, B00001110, B00001110, B11111110, B01111111, B01110000, B01110000, B00110000, B00111000, B00011000, B01111111, B00111111, @@ -33,17 +48,15 @@ static TimeChangeRule CET = {"CET ", Last, Sun, Oct, 3, 60}; // Central Eu template class MonochromeDisplay { public: - #if defined(ENA_NOKIA) + #ifdef ENA_NOKIA MonochromeDisplay() : mDisplay(U8G2_R0, 5, 4, 16), mCE(CEST, CET) { mNewPayload = false; mExtra = 0; } #else // ENA_SSD1306 || ENA_SH1106 - MonochromeDisplay() : mDisplay(0x3c, SDA, SCL), mCE(CEST, CET) { + MonochromeDisplay() : mDisplay(U8G2_R0, SCL, SDA, U8X8_PIN_NONE), mCE(CEST, CET) { mNewPayload = false; mExtra = 0; - mRx = 0; - mUp = 1; } #endif @@ -53,23 +66,8 @@ class MonochromeDisplay { memset( mToday, 0, sizeof(float)*MAX_NUM_INVERTERS ); memset( mTotal, 0, sizeof(float)*MAX_NUM_INVERTERS ); mLastHour = 25; - #if defined(ENA_NOKIA) mDisplay.begin(); ShowInfoText("booting..."); - #else - mDisplay.init(); - mDisplay.flipScreenVertically(); - mDisplay.setContrast(63); - mDisplay.setBrightness(63); - - mDisplay.clear(); - mDisplay.setFont(ArialMT_Plain_24); - mDisplay.setTextAlignment(TEXT_ALIGN_CENTER_BOTH); - - mDisplay.drawString(64,22,"Starting..."); - mDisplay.display(); - mDisplay.setTextAlignment(TEXT_ALIGN_LEFT); - #endif } void loop(void) { @@ -92,7 +90,6 @@ class MonochromeDisplay { } private: - #if defined(ENA_NOKIA) void ShowInfoText(const char *txt) { /* u8g2_font_open_iconic_embedded_2x_t 'D' + 'G' + 'J' */ mDisplay.clear(); @@ -116,10 +113,9 @@ class MonochromeDisplay { mDisplay.sendBuffer(); } while( mDisplay.nextPage() ); } - #endif void DataScreen(void) { - String timeStr = ah::getDateTimeStr(mCE.toLocal(*mUtcTs)).substring(2, 22); + String timeStr = ah::getDateTimeStr(mCE.toLocal(*mUtcTs)).substring(2, 16); int hr = timeStr.substring(9,2).toInt(); IPAddress ip = WiFi.localIP(); float totalYield = 0.0, totalYieldToday = 0.0, totalActual = 0.0; @@ -167,139 +163,145 @@ class MonochromeDisplay { } /* u8g2_font_open_iconic_embedded_2x_t 'D' + 'G' + 'J' */ mDisplay.clear(); - #if defined(ENA_NOKIA) mDisplay.firstPage(); do { - if(ucnt) { - mDisplay.drawXBMP(10,1,8,17,bmp_arrow); - mDisplay.setFont(u8g2_font_logisoso16_tr); - mDisplay.setCursor(25,17); - sprintf(fmtText,"%3.0f",totalActual); - mDisplay.print(String(fmtText)+F(" W")); - } - else - { - mDisplay.setFont(u8g2_font_logisoso16_tr ); - mDisplay.setCursor(10,17); - mDisplay.print(String(F("offline"))); - } - mDisplay.drawHLine(2,20,78); - mDisplay.setFont(u8g2_font_5x8_tr); - mDisplay.setCursor(5,29); - if (( num_inv < 2 ) || !(mExtra%2)) - { - sprintf(fmtText,"%4.0f",totalYieldToday); - mDisplay.print(F("today ")+String(fmtText)+F(" Wh")); - mDisplay.setCursor(5,37); - sprintf(fmtText,"%.1f",totalYield); - mDisplay.print(F("total ")+String(fmtText)+F(" kWh")); - } - else - { - int id1=(mExtra/2)%(num_inv-1); - if( pow_i[id1] ) - mDisplay.print(F("#")+String(id1+1)+F(" ")+String(pow_i[id1])+F(" W")); - else - mDisplay.print(F("#")+String(id1+1)+F(" -----")); - mDisplay.setCursor(5,37); - if( pow_i[id1+1] ) - mDisplay.print(F("#")+String(id1+2)+F(" ")+String(pow_i[id1+1])+F(" W")); + #ifdef ENA_NOKIA + if(ucnt) { + //=====> Actual Production + mDisplay.drawXBMP(10,1,8,17,bmp_arrow); + mDisplay.setFont(u8g2_font_logisoso16_tr); + mDisplay.setCursor(25,17); + if (totalActual>999){ + sprintf(fmtText,"%2.1f",(totalActual/1000)); + mDisplay.print(String(fmtText)+F(" kW")); + } else { + sprintf(fmtText,"%3.0f",totalActual); + mDisplay.print(String(fmtText)+F(" W")); + } + //<======================= + } else - mDisplay.print(F("#")+String(id1+2)+F(" -----")); - } - if ( !(mExtra%10) && ip ) { - mDisplay.setCursor(5,47); - mDisplay.print(ip.toString()); - } - else { - mDisplay.setCursor(0,47); - mDisplay.print(timeStr); - } + { + //=====> Offline + mDisplay.setFont(u8g2_font_logisoso16_tr ); + mDisplay.setCursor(10,17); + mDisplay.print(String(F("offline"))); + //<======================= + } + mDisplay.drawHLine(2,20,78); + mDisplay.setFont(u8g2_font_5x8_tr); + mDisplay.setCursor(5,29); + if (( num_inv < 2 ) || !(mExtra%2)) + { + sprintf(fmtText,"%4.0f",totalYieldToday); + mDisplay.print(F("today ")+String(fmtText)+F(" Wh")); + mDisplay.setCursor(5,37); + sprintf(fmtText,"%.1f",totalYield); + mDisplay.print(F("total ")+String(fmtText)+F(" kWh")); + } + else + { + int id1=(mExtra/2)%(num_inv-1); + if( pow_i[id1] ) + mDisplay.print(F("#")+String(id1+1)+F(" ")+String(pow_i[id1])+F(" W")); + else + mDisplay.print(F("#")+String(id1+1)+F(" -----")); + mDisplay.setCursor(5,37); + if( pow_i[id1+1] ) + mDisplay.print(F("#")+String(id1+2)+F(" ")+String(pow_i[id1+1])+F(" W")); + else + mDisplay.print(F("#")+String(id1+2)+F(" -----")); + } + if ( !(mExtra%10) && ip ) { + mDisplay.setCursor(5,47); + mDisplay.print(ip.toString()); + } + else { + mDisplay.setCursor(5,47); + mDisplay.print(timeStr); + } + #else // ENA_SSD1306 + mDisplay.setContrast(60); + // pxZittern in +x (0 - 8 px) + int ex = 2*( mExtra % 5 ); + mDisplay.drawXBM(100+ex,2,16,16,bmp_logo); + mDisplay.setFont(u8g2_font_ncenB08_tr); + if(ucnt) { + //=====> Actual Production + mDisplay.setPowerSave(false); + displaySleep=false; + mDisplay.setFont(u8g2_font_logisoso18_tr); + mDisplay.drawXBM(10+ex,2,8,17,bmp_arrow); + mDisplay.setCursor(25+ex,20); + if (totalActual>999){ + sprintf(fmtText,"%2.1f",(totalActual/1000)); + mDisplay.print(String(fmtText)+F(" kW")); + } else { + sprintf(fmtText,"%3.0f",totalActual); + mDisplay.print(String(fmtText)+F(" W")); + } + //<======================= + } + else + { + //=====> Offline + if(!displaySleep) { + displaySleepTimer = millis(); + displaySleep=true; + } + mDisplay.setFont(u8g2_font_logisoso18_tr); + mDisplay.setCursor(10+ex,20); + mDisplay.print(String(F("offline"))); + if ((millis() - displaySleepTimer) > displaySleepDelay) { + mDisplay.setPowerSave(true); + } + //<======================= + } + mDisplay.drawLine(2+ex, 23, 123, 23); + mDisplay.setFont(u8g2_font_ncenB10_tr); + mDisplay.setCursor(2+ex,36); + if (( num_inv < 2 ) || !(mExtra%2)) + { + //=====> Today & Total Production + sprintf(fmtText,"%5.0f",totalYieldToday); + mDisplay.print(F("today: ")+String(fmtText)+F(" Wh")); + mDisplay.setCursor(2+ex,50); + sprintf(fmtText,"%.1f",totalYield); + mDisplay.print(F("total: ")+String(fmtText)+F(" kWh")); + //<======================= + } else { + int id1=(mExtra/2)%(num_inv-1); + if( pow_i[id1] ) + mDisplay.print(F("#")+String(id1+1)+F(" ")+String(pow_i[id1])+F(" W")); + else + mDisplay.print(F("#")+String(id1+1)+F(" -----")); + mDisplay.setCursor(5+ex,50); + if( pow_i[id1+1] ) + mDisplay.print(F("#")+String(id1+2)+F(" ")+String(pow_i[id1+1])+F(" W")); + else + mDisplay.print(F("#")+String(id1+2)+F(" -----")); + } + mDisplay.setFont(u8g2_font_5x8_tr); + mDisplay.setCursor(5+ex,63); + if ( !(mExtra%10) && ip ) + mDisplay.print(ip.toString()); + else + mDisplay.print(timeStr); + #endif mDisplay.sendBuffer(); } while( mDisplay.nextPage() ); + delay(200); mExtra++; - #else // ENA_SSD1306 || ENA_SH1106 - if(mUp) { - mRx += 2; - if(mRx >= 20) - mUp = 0; - } else { - mRx -= 2; - if(mRx <= 0) - mUp = 1; - } - int ex = 2*( mExtra % 5 ); - - if(ucnt) { - mDisplay.setBrightness(63); - mDisplay.drawXbm(10+ex,5,8,17,bmp_arrow); - mDisplay.setFont(ArialMT_Plain_24); - sprintf(fmtText,"%3.0f",totalActual); - mDisplay.drawString(25+ex,0,String(fmtText)+F(" W")); - } - else - { - mDisplay.setBrightness(1); - mDisplay.setFont(ArialMT_Plain_24); - mDisplay.drawString(25+ex,0,String(F("offline"))); - } - mDisplay.setFont(ArialMT_Plain_16); - - if (( num_inv < 2 ) || !(mExtra%2)) - { - sprintf(fmtText,"%4.0f",totalYieldToday); - mDisplay.drawString(5,22,F("today ")+String(fmtText)+F(" Wh")); - sprintf(fmtText,"%.1f",totalYield); - mDisplay.drawString(5,35,F("total ")+String(fmtText)+F(" kWh")); - } - else - { - int id1=(mExtra/2)%(num_inv-1); - if( pow_i[id1] ) - mDisplay.drawString(15,22,F("#")+String(id1+1)+F(" ")+String(pow_i[id1])+F(" W")); - else - mDisplay.drawString(15,22,F("#")+String(id1+1)+F(" -----")); - if( pow_i[id1+1] ) - mDisplay.drawString(15,35,F("#")+String(id1+2)+F(" ")+String(pow_i[id1+1])+F(" W")); - else - mDisplay.drawString(15,35,F("#")+String(id1+2)+F(" -----")); - } - mDisplay.drawLine(2,23,123,23); - - if ( (!(mExtra%10) && ip )|| (timeStr.length()<16)) - { - mDisplay.drawString(5,49,ip.toString()); - } - else - { - int w=mDisplay.getStringWidth(timeStr.c_str(),timeStr.length(),0); - if ( w>127 ) - { - String tt=timeStr.substring(9,17); - w=mDisplay.getStringWidth(tt.c_str(),tt.length(),0); - mDisplay.drawString(127-w-mRx,49,tt); - } - else - mDisplay.drawString(0,49,timeStr); - } - - mDisplay.display(); - mExtra++; - #endif } // private member variables - #if defined(ENA_NOKIA) + #ifdef ENA_NOKIA U8G2_PCD8544_84X48_1_4W_HW_SPI mDisplay; - #else // ENA_SSD1306 - #ifdef ENA_SSD1306 - SSD1306Wire mDisplay; - # else //ENA_SH1106 - SH1106Wire mDisplay; - #endif - int mRx; - char mUp; + #elif defined(ENA_SSD1306) + U8G2_SSD1306_128X64_NONAME_F_HW_I2C mDisplay; + #elif defined(ENA_SH1106) + U8G2_SH1106_128X64_NONAME_F_HW_I2C mDisplay; #endif int mExtra; bool mNewPayload; @@ -309,6 +311,9 @@ class MonochromeDisplay { int mLastHour; HMSYSTEM *mSys; Timezone mCE; + bool displaySleep; + uint32_t displaySleepTimer; + const uint32_t displaySleepDelay= 60000; }; #endif