mirror of
https://github.com/lumapu/ahoy.git
synced 2025-05-12 16:36:38 +02:00
more changes on oled-display
This commit is contained in:
parent
a9e4429f9f
commit
cb8320b2f2
2 changed files with 89 additions and 39 deletions
|
@ -105,6 +105,7 @@ lib_deps =
|
||||||
https://github.com/bertmelis/espMqttClient#v1.3.3
|
https://github.com/bertmelis/espMqttClient#v1.3.3
|
||||||
bblanchon/ArduinoJson
|
bblanchon/ArduinoJson
|
||||||
olikraus/U8g2
|
olikraus/U8g2
|
||||||
|
https://github.com/JChristensen/Timezone
|
||||||
|
|
||||||
[env:esp8266-ssd1306]
|
[env:esp8266-ssd1306]
|
||||||
platform = espressif8266
|
platform = espressif8266
|
||||||
|
@ -122,6 +123,7 @@ lib_deps =
|
||||||
https://github.com/bertmelis/espMqttClient#v1.3.3
|
https://github.com/bertmelis/espMqttClient#v1.3.3
|
||||||
bblanchon/ArduinoJson
|
bblanchon/ArduinoJson
|
||||||
https://github.com/ThingPulse/esp8266-oled-ssd1306.git
|
https://github.com/ThingPulse/esp8266-oled-ssd1306.git
|
||||||
|
https://github.com/JChristensen/Timezone
|
||||||
|
|
||||||
[env:esp32-wroom32-release]
|
[env:esp32-wroom32-release]
|
||||||
platform = espressif32
|
platform = espressif32
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
#define DISP_PROGMEM PROGMEM
|
#define DISP_PROGMEM PROGMEM
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <Timezone.h>
|
||||||
|
|
||||||
#include "../../utils/helper.h"
|
#include "../../utils/helper.h"
|
||||||
#include "../../hm/hmSystem.h"
|
#include "../../hm/hmSystem.h"
|
||||||
|
@ -34,7 +35,7 @@ class MonochromeDisplay {
|
||||||
MonochromeDisplay() : mDisplay(0x3c, SDA, SCL) {
|
MonochromeDisplay() : mDisplay(0x3c, SDA, SCL) {
|
||||||
mNewPayload = false;
|
mNewPayload = false;
|
||||||
mExtra = 0;
|
mExtra = 0;
|
||||||
mRx = 50;
|
mRx = 0;
|
||||||
mUp = 1;
|
mUp = 1;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -104,11 +105,17 @@ class MonochromeDisplay {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void DataScreen(void) {
|
void DataScreen(void) {
|
||||||
String timeStr = ah::getDateTimeStr(*mUtcTs).substring(2, 22);
|
TimeChangeRule CEST = {"CEST", Last, Sun, Mar, 2, 120}; // Central European Summer Time
|
||||||
|
TimeChangeRule CET = {"CET ", Last, Sun, Oct, 3, 60}; // Central European Standard Time
|
||||||
|
Timezone CE(CEST, CET);
|
||||||
|
String timeStr = ah::getDateTimeStr(CE.toLocal(*mUtcTs)).substring(2, 22);
|
||||||
IPAddress ip = WiFi.localIP();
|
IPAddress ip = WiFi.localIP();
|
||||||
float totalYield = 0.000, totalYieldToday = 0.000, totalActual = 0.0;
|
float totalYield = 0.000, totalYieldToday = 0.000, totalActual = 0.0;
|
||||||
char fmtText[32];
|
char fmtText[32];
|
||||||
int ucnt=0;
|
int ucnt=0, num_inv=0;
|
||||||
|
unsigned int pow_i[ MAX_NUM_INVERTERS ];
|
||||||
|
|
||||||
|
memset( pow_i, 0, sizeof(unsigned int)* MAX_NUM_INVERTERS );
|
||||||
|
|
||||||
for (uint8_t id = 0; id < mSys->getNumInverters(); id++) {
|
for (uint8_t id = 0; id < mSys->getNumInverters(); id++) {
|
||||||
Inverter<> *iv = mSys->getInverterByPos(id);
|
Inverter<> *iv = mSys->getInverterByPos(id);
|
||||||
|
@ -117,11 +124,11 @@ class MonochromeDisplay {
|
||||||
uint8_t pos;
|
uint8_t pos;
|
||||||
uint8_t list[] = {FLD_PAC, FLD_YT, FLD_YD};
|
uint8_t list[] = {FLD_PAC, FLD_YT, FLD_YD};
|
||||||
|
|
||||||
|
num_inv++;
|
||||||
|
|
||||||
if ( !iv->isProducing(*mUtcTs,rec) )
|
if ( !iv->isProducing(*mUtcTs,rec) )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
ucnt++;
|
|
||||||
|
|
||||||
for (uint8_t fld = 0; fld < 3; fld++) {
|
for (uint8_t fld = 0; fld < 3; fld++) {
|
||||||
pos = iv->getPosByChFld(CH0, list[fld],rec);
|
pos = iv->getPosByChFld(CH0, list[fld],rec);
|
||||||
|
|
||||||
|
@ -130,9 +137,13 @@ class MonochromeDisplay {
|
||||||
if(fld == 2)
|
if(fld == 2)
|
||||||
totalYieldToday += iv->getValue(pos,rec);
|
totalYieldToday += iv->getValue(pos,rec);
|
||||||
if(fld == 0)
|
if(fld == 0)
|
||||||
|
{
|
||||||
|
pow_i[num_inv-1] = iv->getValue(pos,rec);
|
||||||
totalActual += iv->getValue(pos,rec);
|
totalActual += iv->getValue(pos,rec);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
ucnt++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* u8g2_font_open_iconic_embedded_2x_t 'D' + 'G' + 'J' */
|
/* u8g2_font_open_iconic_embedded_2x_t 'D' + 'G' + 'J' */
|
||||||
|
@ -149,21 +160,36 @@ class MonochromeDisplay {
|
||||||
mDisplay.drawHLine(2,20,78);
|
mDisplay.drawHLine(2,20,78);
|
||||||
mDisplay.setFont(u8g2_font_5x8_tr);
|
mDisplay.setFont(u8g2_font_5x8_tr);
|
||||||
mDisplay.setCursor(5,29);
|
mDisplay.setCursor(5,29);
|
||||||
|
if (( num_inv != 2 ) || !(mExtra%2))
|
||||||
|
{
|
||||||
sprintf(fmtText,"%4.0f",totalYieldToday);
|
sprintf(fmtText,"%4.0f",totalYieldToday);
|
||||||
mDisplay.print(F("today ")+String(fmtText)+F(" Wh"));
|
mDisplay.print(F("today ")+String(fmtText)+F(" Wh"));
|
||||||
mDisplay.setCursor(5,37);
|
mDisplay.setCursor(5,37);
|
||||||
sprintf(fmtText,"%.1f",totalYield);
|
sprintf(fmtText,"%.1f",totalYield);
|
||||||
mDisplay.print(F("total ")+String(fmtText)+F(" kWh"));
|
mDisplay.print(F("total ")+String(fmtText)+F(" kWh"));
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if( pow_i[0] )
|
||||||
|
mDisplay.print(F("#1 ")+String(pow_i[0])+F(" W"));
|
||||||
|
else
|
||||||
|
mDisplay.print(F("#1 -----"));
|
||||||
|
mDisplay.setCursor(5,37);
|
||||||
|
if( pow_i[1] )
|
||||||
|
mDisplay.print(F("#2 ")+String(pow_i[1])+F(" W"));
|
||||||
|
else
|
||||||
|
mDisplay.print(F("#2 -----"));
|
||||||
|
}
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
mDisplay.setFont(u8g2_font_logisoso16_tr);
|
mDisplay.setFont(u8g2_font_logisoso16_tr);
|
||||||
mDisplay.setCursor(30,30);
|
mDisplay.setCursor(30,30);
|
||||||
mDisplay.print(F("off"));
|
mDisplay.print(F("off"));
|
||||||
mDisplay.setFont(u8g2_font_5x8_tr);
|
mDisplay.setFont(u8g2_font_5x8_tr);
|
||||||
}
|
}
|
||||||
if ( !(mExtra%20) ) {
|
if ( !(mExtra%10) && ip ) {
|
||||||
mDisplay.setCursor(5,57);
|
mDisplay.setCursor(5,47);
|
||||||
mDisplay.print(ip);
|
mDisplay.print(ip.toString());
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
mDisplay.setCursor(0,47);
|
mDisplay.setCursor(0,47);
|
||||||
|
@ -174,43 +200,65 @@ class MonochromeDisplay {
|
||||||
} while( mDisplay.nextPage() );
|
} while( mDisplay.nextPage() );
|
||||||
mExtra++;
|
mExtra++;
|
||||||
#else // ENA_SSD1306
|
#else // ENA_SSD1306
|
||||||
|
if(mUp) {
|
||||||
|
mRx += 2;
|
||||||
|
if(mRx >= 20)
|
||||||
|
mUp = 0;
|
||||||
|
} else {
|
||||||
|
mRx -= 2;
|
||||||
|
if(mRx <= 0)
|
||||||
|
mUp = 1;
|
||||||
|
}
|
||||||
|
int ex = 2*( mExtra % 5 );
|
||||||
|
|
||||||
if(ucnt) {
|
if(ucnt) {
|
||||||
mDisplay.setBrightness(63);
|
mDisplay.setBrightness(63);
|
||||||
mDisplay.drawXbm(10,5,8,17,bmp_arrow);
|
mDisplay.drawXbm(10+ex,5,8,17,bmp_arrow);
|
||||||
mDisplay.setFont(ArialMT_Plain_24);
|
mDisplay.setFont(ArialMT_Plain_24);
|
||||||
sprintf(fmtText,"%3.0f",totalActual);
|
sprintf(fmtText,"%3.0f",totalActual);
|
||||||
mDisplay.drawString(25,0,String(fmtText)+F(" W"));
|
mDisplay.drawString(25+ex,0,String(fmtText)+F(" W"));
|
||||||
mDisplay.setFont(ArialMT_Plain_16);
|
mDisplay.setFont(ArialMT_Plain_16);
|
||||||
|
|
||||||
|
if (( num_inv != 2 ) || !(mExtra%2))
|
||||||
|
{
|
||||||
sprintf(fmtText,"%4.0f",totalYieldToday);
|
sprintf(fmtText,"%4.0f",totalYieldToday);
|
||||||
mDisplay.drawString(5,22,F("today ")+String(fmtText)+F(" Wh"));
|
mDisplay.drawString(5,22,F("today ")+String(fmtText)+F(" Wh"));
|
||||||
sprintf(fmtText,"%.1f",totalYield);
|
sprintf(fmtText,"%.1f",totalYield);
|
||||||
mDisplay.drawString(5,35,F("total ")+String(fmtText)+F(" kWh"));
|
mDisplay.drawString(5,35,F("total ")+String(fmtText)+F(" kWh"));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if( pow_i[0] )
|
||||||
|
mDisplay.drawString(15,22,F("#1 ")+String(pow_i[0])+F(" W"));
|
||||||
|
else
|
||||||
|
mDisplay.drawString(15,22,F("#1 -----"));
|
||||||
|
if( pow_i[1] )
|
||||||
|
mDisplay.drawString(15,35,F("#2 ")+String(pow_i[1])+F(" W"));
|
||||||
|
else
|
||||||
|
mDisplay.drawString(15,35,F("#2 -----"));
|
||||||
|
}
|
||||||
mDisplay.drawLine(2,23,123,23);
|
mDisplay.drawLine(2,23,123,23);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if(mUp) {
|
|
||||||
mRx += 2;
|
|
||||||
if(mRx >= 70)
|
|
||||||
mUp = 0;
|
|
||||||
} else {
|
|
||||||
mRx -= 2;
|
|
||||||
if(mRx <= 50)
|
|
||||||
mUp = 1;
|
|
||||||
}
|
|
||||||
mDisplay.setBrightness(1);
|
mDisplay.setBrightness(1);
|
||||||
mDisplay.setFont(ArialMT_Plain_24);
|
mDisplay.setFont(ArialMT_Plain_24);
|
||||||
mDisplay.drawString(mRx, 10, F("off"));
|
mDisplay.drawString(mRx+50, 10, F("off"));
|
||||||
mDisplay.setFont(ArialMT_Plain_16);
|
mDisplay.setFont(ArialMT_Plain_16);
|
||||||
}
|
}
|
||||||
if (!(mExtra % 20)) {
|
if ( (!(mExtra%10) && ip )|| (timeStr.length()<16))
|
||||||
|
{
|
||||||
mDisplay.drawString(5,49,ip.toString());
|
mDisplay.drawString(5,49,ip.toString());
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
int w=mDisplay.getStringWidth(timeStr.c_str(),timeStr.length(),0);
|
int w=mDisplay.getStringWidth(timeStr.c_str(),timeStr.length(),0);
|
||||||
if (w > 127) {
|
if ( w>127 )
|
||||||
|
{
|
||||||
String tt=timeStr.substring(9,17);
|
String tt=timeStr.substring(9,17);
|
||||||
w=mDisplay.getStringWidth(tt.c_str(),tt.length(),0);
|
w=mDisplay.getStringWidth(tt.c_str(),tt.length(),0);
|
||||||
mDisplay.drawString(127 - w, 49, tt);
|
mDisplay.drawString(127-w-mRx,49,tt);
|
||||||
} else
|
}
|
||||||
|
else
|
||||||
mDisplay.drawString(0,49,timeStr);
|
mDisplay.drawString(0,49,timeStr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue