mirror of https://github.com/lumapu/ahoy.git
33 changed files with 1331 additions and 659 deletions
@ -1,20 +1,25 @@ |
|||||
# Development Changes |
# Development Changes |
||||
|
|
||||
## 0.6.4 - 2023-04-06 |
## 0.6.15 - 2023-05-25 |
||||
* merge PR #846, improved NRF24 communication and MI, thx @beegee3 & @rejoe2 |
* improved Prometheus Endpoint PR #958 |
||||
* merge PR #859, fix burger menu height, thx @ThomasPohl |
* fix turn off ePaper only if setting was set #956 |
||||
|
* improved reset values and update MqTT #957 |
||||
|
|
||||
## 0.6.3 - 2023-04-04 |
## 0.6.14 - 2023-05-21 |
||||
* fix login, password length was not checked #852 |
* merge PR #902 Mono-Display |
||||
* merge PR #854 optimize browser caching, thx @tastendruecker123 #828 |
|
||||
* fix WiFi reconnect not working #851 |
|
||||
* updated issue templates #822 |
|
||||
|
|
||||
## 0.6.2 - 2023-04-04 |
## 0.6.13 - 2023-05-16 |
||||
* fix login from multiple clients #819 |
* merge PR #934 (fix JSON API) and #944 (update manual) |
||||
* fix login screen on small displays |
|
||||
|
|
||||
## 0.6.1 - 2023-04-01 |
## 0.6.12 - 2023-04-28 |
||||
* merge LED fix - LED1 shows MqTT state, LED configureable active high/low #839 |
* improved MqTT |
||||
* only publish new inverter data #826 |
* fix menu active item |
||||
* potential fix of WiFi hostname during boot up #752 |
|
||||
|
## 0.6.11 - 2023-04-27 |
||||
|
* added MqTT class for publishing all values in Arduino `loop` |
||||
|
|
||||
|
## 0.6.10 - HMS |
||||
|
* Version available in `HMS` branch |
||||
|
|
||||
|
## 0.6.9 |
||||
|
* last Relaese |
||||
|
@ -1,157 +0,0 @@ |
|||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
||||
#include "Display_Mono.h" |
|
||||
|
|
||||
#ifdef ESP8266 |
|
||||
#include <ESP8266WiFi.h> |
|
||||
#elif defined(ESP32) |
|
||||
#include <WiFi.h> |
|
||||
#endif |
|
||||
#include "../../utils/helper.h" |
|
||||
|
|
||||
//#ifdef U8X8_HAVE_HW_SPI
|
|
||||
//#include <SPI.h>
|
|
||||
//#endif
|
|
||||
//#ifdef U8X8_HAVE_HW_I2C
|
|
||||
//#include <Wire.h>
|
|
||||
//#endif
|
|
||||
|
|
||||
DisplayMono::DisplayMono() { |
|
||||
mEnPowerSafe = true; |
|
||||
mEnScreenSaver = true; |
|
||||
mLuminance = 60; |
|
||||
_dispY = 0; |
|
||||
mTimeout = DISP_DEFAULT_TIMEOUT; // interval at which to power save (milliseconds)
|
|
||||
mUtcTs = NULL; |
|
||||
mType = 0; |
|
||||
} |
|
||||
|
|
||||
|
|
||||
|
|
||||
void DisplayMono::init(uint8_t type, uint8_t rotation, uint8_t cs, uint8_t dc, uint8_t reset, uint8_t clock, uint8_t data, uint32_t *utcTs, const char* version) { |
|
||||
if ((0 < type) && (type < 4)) { |
|
||||
u8g2_cb_t *rot = (u8g2_cb_t *)((rotation != 0x00) ? U8G2_R2 : U8G2_R0); |
|
||||
mType = type; |
|
||||
switch(type) { |
|
||||
case 1: |
|
||||
mDisplay = new U8G2_SSD1306_128X64_NONAME_F_HW_I2C(rot, reset, clock, data); |
|
||||
break; |
|
||||
default: |
|
||||
case 2: |
|
||||
mDisplay = new U8G2_SH1106_128X64_NONAME_F_HW_I2C(rot, reset, clock, data); |
|
||||
break; |
|
||||
case 3: |
|
||||
mDisplay = new U8G2_PCD8544_84X48_F_4W_SW_SPI(rot, clock, data, cs, dc, reset); |
|
||||
break; |
|
||||
} |
|
||||
|
|
||||
mUtcTs = utcTs; |
|
||||
|
|
||||
mDisplay->begin(); |
|
||||
|
|
||||
mIsLarge = (mDisplay->getWidth() > 120); |
|
||||
calcLineHeights(); |
|
||||
|
|
||||
mDisplay->clearBuffer(); |
|
||||
if (3 != mType) |
|
||||
mDisplay->setContrast(mLuminance); |
|
||||
printText("AHOY!", 0, 35); |
|
||||
printText("ahoydtu.de", 2, 20); |
|
||||
printText(version, 3, 46); |
|
||||
mDisplay->sendBuffer(); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
void DisplayMono::config(bool enPowerSafe, bool enScreenSaver, uint8_t lum) { |
|
||||
mEnPowerSafe = enPowerSafe; |
|
||||
mEnScreenSaver = enScreenSaver; |
|
||||
mLuminance = lum; |
|
||||
} |
|
||||
|
|
||||
void DisplayMono::loop(void) { |
|
||||
if (mEnPowerSafe) |
|
||||
if(mTimeout != 0) |
|
||||
mTimeout--; |
|
||||
} |
|
||||
|
|
||||
void DisplayMono::disp(float totalPower, float totalYieldDay, float totalYieldTotal, uint8_t isprod) { |
|
||||
|
|
||||
|
|
||||
mDisplay->clearBuffer(); |
|
||||
|
|
||||
// set Contrast of the Display to raise the lifetime
|
|
||||
if (3 != mType) |
|
||||
mDisplay->setContrast(mLuminance); |
|
||||
|
|
||||
if ((totalPower > 0) && (isprod > 0)) { |
|
||||
mTimeout = DISP_DEFAULT_TIMEOUT; |
|
||||
mDisplay->setPowerSave(false); |
|
||||
if (totalPower > 999) { |
|
||||
snprintf(_fmtText, DISP_FMT_TEXT_LEN, "%2.2f kW", (totalPower / 1000)); |
|
||||
} else { |
|
||||
snprintf(_fmtText, DISP_FMT_TEXT_LEN, "%3.0f W", totalPower); |
|
||||
} |
|
||||
printText(_fmtText, 0); |
|
||||
} else { |
|
||||
printText("offline", 0, 25); |
|
||||
// check if it's time to enter power saving mode
|
|
||||
if (mTimeout == 0) |
|
||||
mDisplay->setPowerSave(mEnPowerSafe); |
|
||||
} |
|
||||
|
|
||||
snprintf(_fmtText, DISP_FMT_TEXT_LEN, "today: %4.0f Wh", totalYieldDay); |
|
||||
printText(_fmtText, 1); |
|
||||
|
|
||||
snprintf(_fmtText, DISP_FMT_TEXT_LEN, "total: %.1f kWh", totalYieldTotal); |
|
||||
printText(_fmtText, 2); |
|
||||
|
|
||||
IPAddress ip = WiFi.localIP(); |
|
||||
if (!(_mExtra % 10) && (ip)) { |
|
||||
printText(ip.toString().c_str(), 3); |
|
||||
} else if (!(_mExtra % 5)) { |
|
||||
snprintf(_fmtText, DISP_FMT_TEXT_LEN, "%d Inverter on", isprod); |
|
||||
printText(_fmtText, 3); |
|
||||
} else { |
|
||||
if(mIsLarge && (NULL != mUtcTs)) |
|
||||
printText(ah::getDateTimeStr(gTimezone.toLocal(*mUtcTs)).c_str(), 3); |
|
||||
else |
|
||||
printText(ah::getTimeStr(gTimezone.toLocal(*mUtcTs)).c_str(), 3); |
|
||||
} |
|
||||
|
|
||||
mDisplay->sendBuffer(); |
|
||||
|
|
||||
_dispY = 0; |
|
||||
_mExtra++; |
|
||||
} |
|
||||
|
|
||||
void DisplayMono::calcLineHeights() { |
|
||||
uint8_t yOff = 0; |
|
||||
for (uint8_t i = 0; i < 4; i++) { |
|
||||
setFont(i); |
|
||||
yOff += (mDisplay->getMaxCharHeight()); |
|
||||
mLineOffsets[i] = yOff; |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
inline void DisplayMono::setFont(uint8_t line) { |
|
||||
switch (line) { |
|
||||
case 0: |
|
||||
mDisplay->setFont((mIsLarge) ? u8g2_font_ncenB14_tr : u8g2_font_logisoso16_tr); |
|
||||
break; |
|
||||
case 3: |
|
||||
mDisplay->setFont(u8g2_font_5x8_tr); |
|
||||
break; |
|
||||
default: |
|
||||
mDisplay->setFont((mIsLarge) ? u8g2_font_ncenB10_tr : u8g2_font_5x8_tr); |
|
||||
break; |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
void DisplayMono::printText(const char* text, uint8_t line, uint8_t dispX) { |
|
||||
if (!mIsLarge) { |
|
||||
dispX = (line == 0) ? 10 : 5; |
|
||||
} |
|
||||
setFont(line); |
|
||||
|
|
||||
dispX += (mEnScreenSaver) ? (_mExtra % 7) : 0; |
|
||||
mDisplay->drawStr(dispX, mLineOffsets[line], text); |
|
||||
} |
|
@ -1,38 +1,45 @@ |
|||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
//-----------------------------------------------------------------------------
|
||||
#pragma once |
// 2023 Ahoy, https://ahoydtu.de
|
||||
|
// Creative Commons - https://creativecommons.org/licenses/by-nc-sa/4.0/deed
|
||||
|
//-----------------------------------------------------------------------------
|
||||
|
|
||||
|
#pragma once |
||||
#include <U8g2lib.h> |
#include <U8g2lib.h> |
||||
#define DISP_DEFAULT_TIMEOUT 60 // in seconds
|
#define DISP_DEFAULT_TIMEOUT 60 // in seconds
|
||||
#define DISP_FMT_TEXT_LEN 32 |
#define DISP_FMT_TEXT_LEN 32 |
||||
|
#define BOTTOM_MARGIN 5 |
||||
|
|
||||
|
|
||||
|
#ifdef ESP8266 |
||||
|
#include <ESP8266WiFi.h> |
||||
|
#elif defined(ESP32) |
||||
|
#include <WiFi.h> |
||||
|
#endif |
||||
|
#include "../../utils/helper.h" |
||||
|
|
||||
class DisplayMono { |
class DisplayMono { |
||||
public: |
public: |
||||
DisplayMono(); |
DisplayMono() {}; |
||||
|
|
||||
void init(uint8_t type, uint8_t rot, uint8_t cs, uint8_t dc, uint8_t reset, uint8_t clock, uint8_t data, uint32_t *utcTs, const char* version); |
|
||||
void config(bool enPowerSafe, bool enScreenSaver, uint8_t lum); |
|
||||
void loop(void); |
|
||||
void disp(float totalPower, float totalYieldDay, float totalYieldTotal, uint8_t isprod); |
|
||||
|
|
||||
private: |
virtual void init(uint8_t type, uint8_t rot, uint8_t cs, uint8_t dc, uint8_t reset, uint8_t clock, uint8_t data, uint32_t* utcTs, const char* version) = 0; |
||||
void calcLineHeights(); |
virtual void config(bool enPowerSafe, bool enScreenSaver, uint8_t lum) = 0; |
||||
void setFont(uint8_t line); |
virtual void loop(void) = 0; |
||||
void printText(const char* text, uint8_t line, uint8_t dispX = 5); |
virtual void disp(float totalPower, float totalYieldDay, float totalYieldTotal, uint8_t isprod) = 0; |
||||
|
|
||||
|
protected: |
||||
U8G2* mDisplay; |
U8G2* mDisplay; |
||||
|
|
||||
uint8_t mType; |
uint8_t mType; |
||||
bool mEnPowerSafe, mEnScreenSaver; |
bool mEnPowerSafe, mEnScreenSaver; |
||||
uint8_t mLuminance; |
uint8_t mLuminance; |
||||
|
|
||||
bool mIsLarge = false; |
|
||||
uint8_t mLoopCnt; |
uint8_t mLoopCnt; |
||||
uint32_t* mUtcTs; |
uint32_t* mUtcTs; |
||||
uint8_t mLineOffsets[5]; |
uint8_t mLineXOffsets[5]; |
||||
|
uint8_t mLineYOffsets[5]; |
||||
|
|
||||
uint16_t _dispY; |
uint16_t mDispY; |
||||
|
|
||||
uint8_t _mExtra; |
uint8_t mExtra; |
||||
uint16_t mTimeout; |
uint16_t mTimeout; |
||||
char _fmtText[DISP_FMT_TEXT_LEN]; |
char mFmtText[DISP_FMT_TEXT_LEN];}; |
||||
}; |
|
||||
|
@ -0,0 +1,155 @@ |
|||||
|
//-----------------------------------------------------------------------------
|
||||
|
// 2023 Ahoy, https://ahoydtu.de
|
||||
|
// Creative Commons - https://creativecommons.org/licenses/by-nc-sa/4.0/deed
|
||||
|
//-----------------------------------------------------------------------------
|
||||
|
|
||||
|
#pragma once |
||||
|
#include "Display_Mono.h" |
||||
|
|
||||
|
class DisplayMono128X32 : public DisplayMono { |
||||
|
public: |
||||
|
DisplayMono128X32() : DisplayMono() { |
||||
|
mEnPowerSafe = true; |
||||
|
mEnScreenSaver = true; |
||||
|
mLuminance = 60; |
||||
|
mExtra = 0; |
||||
|
mDispY = 0; |
||||
|
mTimeout = DISP_DEFAULT_TIMEOUT; // interval at which to power save (milliseconds)
|
||||
|
mUtcTs = NULL; |
||||
|
mType = 0; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
void init(uint8_t type, uint8_t rotation, uint8_t cs, uint8_t dc, uint8_t reset, uint8_t clock, uint8_t data, uint32_t *utcTs, const char *version) { |
||||
|
if((0 == type) || (type > 4)) |
||||
|
return; |
||||
|
|
||||
|
u8g2_cb_t *rot = (u8g2_cb_t *)((rotation != 0x00) ? U8G2_R2 : U8G2_R0); |
||||
|
mType = type; |
||||
|
mDisplay = new U8G2_SSD1306_128X32_UNIVISION_F_HW_I2C(rot, reset, clock, data); |
||||
|
|
||||
|
mUtcTs = utcTs; |
||||
|
|
||||
|
mDisplay->begin(); |
||||
|
|
||||
|
calcLinePositions(); |
||||
|
|
||||
|
mDisplay->clearBuffer(); |
||||
|
mDisplay->setContrast(mLuminance); |
||||
|
printText("AHOY!", 0); |
||||
|
printText("ahoydtu.de", 2); |
||||
|
printText(version, 3); |
||||
|
mDisplay->sendBuffer(); |
||||
|
} |
||||
|
|
||||
|
void config(bool enPowerSafe, bool enScreenSaver, uint8_t lum) { |
||||
|
mEnPowerSafe = enPowerSafe; |
||||
|
mEnScreenSaver = enScreenSaver; |
||||
|
mLuminance = lum; |
||||
|
} |
||||
|
|
||||
|
void loop(void) { |
||||
|
if (mEnPowerSafe) { |
||||
|
if (mTimeout != 0) |
||||
|
mTimeout--; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
void disp(float totalPower, float totalYieldDay, float totalYieldTotal, uint8_t isprod) { |
||||
|
mDisplay->clearBuffer(); |
||||
|
|
||||
|
// set Contrast of the Display to raise the lifetime
|
||||
|
if (3 != mType) |
||||
|
mDisplay->setContrast(mLuminance); |
||||
|
|
||||
|
if ((totalPower > 0) && (isprod > 0)) { |
||||
|
mTimeout = DISP_DEFAULT_TIMEOUT; |
||||
|
mDisplay->setPowerSave(false); |
||||
|
if (totalPower > 999) |
||||
|
snprintf(mFmtText, DISP_FMT_TEXT_LEN, "%2.2f kW", (totalPower / 1000)); |
||||
|
else |
||||
|
snprintf(mFmtText, DISP_FMT_TEXT_LEN, "%3.0f W", totalPower); |
||||
|
|
||||
|
printText(mFmtText, 0); |
||||
|
} else { |
||||
|
printText("offline", 0); |
||||
|
// check if it's time to enter power saving mode
|
||||
|
if (mTimeout == 0) |
||||
|
mDisplay->setPowerSave(mEnPowerSafe); |
||||
|
} |
||||
|
|
||||
|
snprintf(mFmtText, DISP_FMT_TEXT_LEN, "today: %4.0f Wh", totalYieldDay); |
||||
|
printText(mFmtText, 1); |
||||
|
|
||||
|
snprintf(mFmtText, DISP_FMT_TEXT_LEN, "total: %.1f kWh", totalYieldTotal); |
||||
|
printText(mFmtText, 2); |
||||
|
|
||||
|
IPAddress ip = WiFi.localIP(); |
||||
|
if (!(mExtra % 10) && (ip)) |
||||
|
printText(ip.toString().c_str(), 3); |
||||
|
else if (!(mExtra % 5)) { |
||||
|
snprintf(mFmtText, DISP_FMT_TEXT_LEN, "%d Inverter on", isprod); |
||||
|
printText(mFmtText, 3); |
||||
|
} else if (NULL != mUtcTs) |
||||
|
printText(ah::getTimeStr(gTimezone.toLocal(*mUtcTs)).c_str(), 3); |
||||
|
|
||||
|
mDisplay->sendBuffer(); |
||||
|
|
||||
|
mDispY = 0; |
||||
|
mExtra++; |
||||
|
} |
||||
|
|
||||
|
private: |
||||
|
void calcLinePositions() { |
||||
|
uint8_t yOff[] = {0, 0}; |
||||
|
for (uint8_t i = 0; i < 4; i++) { |
||||
|
setFont(i); |
||||
|
yOff[getColumn(i)] += (mDisplay->getMaxCharHeight()); |
||||
|
mLineYOffsets[i] = yOff[getColumn(i)]; |
||||
|
if (isTwoRowLine(i)) |
||||
|
yOff[getColumn(i)] += mDisplay->getMaxCharHeight(); |
||||
|
yOff[getColumn(i)] += BOTTOM_MARGIN; |
||||
|
mLineXOffsets[i] = (getColumn(i) == 1 ? 80 : 0); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
inline void setFont(uint8_t line) { |
||||
|
switch (line) { |
||||
|
case 0: |
||||
|
mDisplay->setFont(u8g2_font_9x15_tf); |
||||
|
break; |
||||
|
case 3: |
||||
|
mDisplay->setFont(u8g2_font_tom_thumb_4x6_tf); |
||||
|
break; |
||||
|
default: |
||||
|
mDisplay->setFont(u8g2_font_tom_thumb_4x6_tf); |
||||
|
break; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
inline uint8_t getColumn(uint8_t line) { |
||||
|
if (line >= 1 && line <= 2) |
||||
|
return 1; |
||||
|
else |
||||
|
return 0; |
||||
|
} |
||||
|
|
||||
|
inline bool isTwoRowLine(uint8_t line) { |
||||
|
return ((line >= 1) && (line <= 2)); |
||||
|
} |
||||
|
|
||||
|
void printText(const char *text, uint8_t line) { |
||||
|
setFont(line); |
||||
|
|
||||
|
uint8_t dispX = mLineXOffsets[line] + ((mEnScreenSaver) ? (mExtra % 7) : 0); |
||||
|
|
||||
|
if (isTwoRowLine(line)) { |
||||
|
String stringText = String(text); |
||||
|
int space = stringText.indexOf(" "); |
||||
|
mDisplay->drawStr(dispX, mLineYOffsets[line], stringText.substring(0, space).c_str()); |
||||
|
if (space > 0) |
||||
|
mDisplay->drawStr(dispX, mLineYOffsets[line] + mDisplay->getMaxCharHeight(), stringText.substring(space + 1).c_str()); |
||||
|
} else |
||||
|
mDisplay->drawStr(dispX, mLineYOffsets[line], text); |
||||
|
} |
||||
|
}; |
@ -0,0 +1,138 @@ |
|||||
|
//-----------------------------------------------------------------------------
|
||||
|
// 2023 Ahoy, https://ahoydtu.de
|
||||
|
// Creative Commons - https://creativecommons.org/licenses/by-nc-sa/4.0/deed
|
||||
|
//-----------------------------------------------------------------------------
|
||||
|
|
||||
|
#pragma once |
||||
|
#include "Display_Mono.h" |
||||
|
|
||||
|
class DisplayMono128X64 : public DisplayMono { |
||||
|
public: |
||||
|
DisplayMono128X64() : DisplayMono() { |
||||
|
mEnPowerSafe = true; |
||||
|
mEnScreenSaver = true; |
||||
|
mLuminance = 60; |
||||
|
mDispY = 0; |
||||
|
mTimeout = DISP_DEFAULT_TIMEOUT; // interval at which to power save (milliseconds)
|
||||
|
mUtcTs = NULL; |
||||
|
mType = 0; |
||||
|
} |
||||
|
|
||||
|
void init(uint8_t type, uint8_t rotation, uint8_t cs, uint8_t dc, uint8_t reset, uint8_t clock, uint8_t data, uint32_t *utcTs, const char *version) { |
||||
|
if((0 == type) || (type > 4)) |
||||
|
return; |
||||
|
|
||||
|
u8g2_cb_t *rot = (u8g2_cb_t *)((rotation != 0x00) ? U8G2_R2 : U8G2_R0); |
||||
|
mType = type; |
||||
|
|
||||
|
switch (type) { |
||||
|
case 1: |
||||
|
mDisplay = new U8G2_SSD1306_128X64_NONAME_F_HW_I2C(rot, reset, clock, data); |
||||
|
break; |
||||
|
default: |
||||
|
case 2: |
||||
|
mDisplay = new U8G2_SH1106_128X64_NONAME_F_HW_I2C(rot, reset, clock, data); |
||||
|
break; |
||||
|
} |
||||
|
|
||||
|
mUtcTs = utcTs; |
||||
|
|
||||
|
mDisplay->begin(); |
||||
|
calcLinePositions(); |
||||
|
|
||||
|
mDisplay->clearBuffer(); |
||||
|
mDisplay->setContrast(mLuminance); |
||||
|
printText("AHOY!", 0, 35); |
||||
|
printText("ahoydtu.de", 2, 20); |
||||
|
printText(version, 3, 46); |
||||
|
mDisplay->sendBuffer(); |
||||
|
} |
||||
|
|
||||
|
void config(bool enPowerSafe, bool enScreenSaver, uint8_t lum) { |
||||
|
mEnPowerSafe = enPowerSafe; |
||||
|
mEnScreenSaver = enScreenSaver; |
||||
|
mLuminance = lum; |
||||
|
} |
||||
|
|
||||
|
void loop(void) { |
||||
|
if (mEnPowerSafe) { |
||||
|
if (mTimeout != 0) |
||||
|
mTimeout--; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
void disp(float totalPower, float totalYieldDay, float totalYieldTotal, uint8_t isprod) { |
||||
|
mDisplay->clearBuffer(); |
||||
|
|
||||
|
// set Contrast of the Display to raise the lifetime
|
||||
|
if (3 != mType) |
||||
|
mDisplay->setContrast(mLuminance); |
||||
|
|
||||
|
if ((totalPower > 0) && (isprod > 0)) { |
||||
|
mTimeout = DISP_DEFAULT_TIMEOUT; |
||||
|
mDisplay->setPowerSave(false); |
||||
|
|
||||
|
if (totalPower > 999) |
||||
|
snprintf(mFmtText, DISP_FMT_TEXT_LEN, "%2.2f kW", (totalPower / 1000)); |
||||
|
else |
||||
|
snprintf(mFmtText, DISP_FMT_TEXT_LEN, "%3.0f W", totalPower); |
||||
|
|
||||
|
printText(mFmtText, 0); |
||||
|
} else { |
||||
|
printText("offline", 0, 25); |
||||
|
// check if it's time to enter power saving mode
|
||||
|
if (mTimeout == 0) |
||||
|
mDisplay->setPowerSave(mEnPowerSafe); |
||||
|
} |
||||
|
|
||||
|
snprintf(mFmtText, DISP_FMT_TEXT_LEN, "today: %4.0f Wh", totalYieldDay); |
||||
|
printText(mFmtText, 1); |
||||
|
|
||||
|
snprintf(mFmtText, DISP_FMT_TEXT_LEN, "total: %.1f kWh", totalYieldTotal); |
||||
|
printText(mFmtText, 2); |
||||
|
|
||||
|
IPAddress ip = WiFi.localIP(); |
||||
|
if (!(mExtra % 10) && (ip)) |
||||
|
printText(ip.toString().c_str(), 3); |
||||
|
else if (!(mExtra % 5)) { |
||||
|
snprintf(mFmtText, DISP_FMT_TEXT_LEN, "%d Inverter on", isprod); |
||||
|
printText(mFmtText, 3); |
||||
|
} else if (NULL != mUtcTs) |
||||
|
printText(ah::getDateTimeStr(gTimezone.toLocal(*mUtcTs)).c_str(), 3); |
||||
|
|
||||
|
mDisplay->sendBuffer(); |
||||
|
|
||||
|
mDispY = 0; |
||||
|
mExtra++; |
||||
|
} |
||||
|
|
||||
|
private: |
||||
|
void calcLinePositions() { |
||||
|
uint8_t yOff = 0; |
||||
|
for (uint8_t i = 0; i < 4; i++) { |
||||
|
setFont(i); |
||||
|
yOff += (mDisplay->getMaxCharHeight()); |
||||
|
mLineYOffsets[i] = yOff; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
inline void setFont(uint8_t line) { |
||||
|
switch (line) { |
||||
|
case 0: |
||||
|
mDisplay->setFont(u8g2_font_ncenB14_tr); |
||||
|
break; |
||||
|
case 3: |
||||
|
mDisplay->setFont(u8g2_font_5x8_tr); |
||||
|
break; |
||||
|
default: |
||||
|
mDisplay->setFont(u8g2_font_ncenB10_tr); |
||||
|
break; |
||||
|
} |
||||
|
} |
||||
|
void printText(const char *text, uint8_t line, uint8_t dispX = 5) { |
||||
|
setFont(line); |
||||
|
|
||||
|
dispX += (mEnScreenSaver) ? (mExtra % 7) : 0; |
||||
|
mDisplay->drawStr(dispX, mLineYOffsets[line], text); |
||||
|
} |
||||
|
}; |
@ -0,0 +1,132 @@ |
|||||
|
//-----------------------------------------------------------------------------
|
||||
|
// 2023 Ahoy, https://ahoydtu.de
|
||||
|
// Creative Commons - https://creativecommons.org/licenses/by-nc-sa/4.0/deed
|
||||
|
//-----------------------------------------------------------------------------
|
||||
|
|
||||
|
#pragma once |
||||
|
#include "Display_Mono.h" |
||||
|
|
||||
|
class DisplayMono84X48 : public DisplayMono { |
||||
|
public: |
||||
|
DisplayMono84X48() : DisplayMono() { |
||||
|
mEnPowerSafe = true; |
||||
|
mEnScreenSaver = true; |
||||
|
mLuminance = 60; |
||||
|
mExtra = 0; |
||||
|
mDispY = 0; |
||||
|
mTimeout = DISP_DEFAULT_TIMEOUT; // interval at which to power save (milliseconds)
|
||||
|
mUtcTs = NULL; |
||||
|
mType = 0; |
||||
|
} |
||||
|
|
||||
|
void init(uint8_t type, uint8_t rotation, uint8_t cs, uint8_t dc, uint8_t reset, uint8_t clock, uint8_t data, uint32_t *utcTs, const char *version) { |
||||
|
if((0 == type) || (type > 4)) |
||||
|
return; |
||||
|
|
||||
|
u8g2_cb_t *rot = (u8g2_cb_t *)((rotation != 0x00) ? U8G2_R2 : U8G2_R0); |
||||
|
mType = type; |
||||
|
mDisplay = new U8G2_PCD8544_84X48_F_4W_SW_SPI(rot, clock, data, cs, dc, reset); |
||||
|
|
||||
|
mUtcTs = utcTs; |
||||
|
|
||||
|
mDisplay->begin(); |
||||
|
calcLinePositions(); |
||||
|
|
||||
|
mDisplay->clearBuffer(); |
||||
|
if (3 != mType) |
||||
|
mDisplay->setContrast(mLuminance); |
||||
|
printText("AHOY!", 0); |
||||
|
printText("ahoydtu.de", 2); |
||||
|
printText(version, 3); |
||||
|
mDisplay->sendBuffer(); |
||||
|
} |
||||
|
|
||||
|
void config(bool enPowerSafe, bool enScreenSaver, uint8_t lum) { |
||||
|
mEnPowerSafe = enPowerSafe; |
||||
|
mEnScreenSaver = enScreenSaver; |
||||
|
mLuminance = lum; |
||||
|
} |
||||
|
|
||||
|
void loop(void) { |
||||
|
if (mEnPowerSafe) { |
||||
|
if (mTimeout != 0) |
||||
|
mTimeout--; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
void disp(float totalPower, float totalYieldDay, float totalYieldTotal, uint8_t isprod) { |
||||
|
mDisplay->clearBuffer(); |
||||
|
|
||||
|
// set Contrast of the Display to raise the lifetime
|
||||
|
if (3 != mType) |
||||
|
mDisplay->setContrast(mLuminance); |
||||
|
|
||||
|
if ((totalPower > 0) && (isprod > 0)) { |
||||
|
mTimeout = DISP_DEFAULT_TIMEOUT; |
||||
|
mDisplay->setPowerSave(false); |
||||
|
|
||||
|
if (totalPower > 999) |
||||
|
snprintf(mFmtText, DISP_FMT_TEXT_LEN, "%2.2f kW", (totalPower / 1000)); |
||||
|
else |
||||
|
snprintf(mFmtText, DISP_FMT_TEXT_LEN, "%3.0f W", totalPower); |
||||
|
|
||||
|
printText(mFmtText, 0); |
||||
|
} else { |
||||
|
printText("offline", 0); |
||||
|
// check if it's time to enter power saving mode
|
||||
|
if (mTimeout == 0) |
||||
|
mDisplay->setPowerSave(mEnPowerSafe); |
||||
|
} |
||||
|
|
||||
|
snprintf(mFmtText, DISP_FMT_TEXT_LEN, "today: %4.0f Wh", totalYieldDay); |
||||
|
printText(mFmtText, 1); |
||||
|
|
||||
|
snprintf(mFmtText, DISP_FMT_TEXT_LEN, "total: %.1f kWh", totalYieldTotal); |
||||
|
printText(mFmtText, 2); |
||||
|
|
||||
|
IPAddress ip = WiFi.localIP(); |
||||
|
if (!(mExtra % 10) && (ip)) |
||||
|
printText(ip.toString().c_str(), 3); |
||||
|
else if (!(mExtra % 5)) { |
||||
|
snprintf(mFmtText, DISP_FMT_TEXT_LEN, "%d Inverter on", isprod); |
||||
|
printText(mFmtText, 3); |
||||
|
} else if (NULL != mUtcTs) |
||||
|
printText(ah::getTimeStr(gTimezone.toLocal(*mUtcTs)).c_str(), 3); |
||||
|
|
||||
|
mDisplay->sendBuffer(); |
||||
|
|
||||
|
mExtra = 1; |
||||
|
} |
||||
|
|
||||
|
private: |
||||
|
void calcLinePositions() { |
||||
|
uint8_t yOff = 0; |
||||
|
for (uint8_t i = 0; i < 4; i++) { |
||||
|
setFont(i); |
||||
|
yOff += (mDisplay->getMaxCharHeight()); |
||||
|
mLineYOffsets[i] = yOff; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
inline void setFont(uint8_t line) { |
||||
|
switch (line) { |
||||
|
case 0: |
||||
|
mDisplay->setFont(u8g2_font_logisoso16_tr); |
||||
|
break; |
||||
|
case 3: |
||||
|
mDisplay->setFont(u8g2_font_5x8_tr); |
||||
|
break; |
||||
|
default: |
||||
|
mDisplay->setFont(u8g2_font_5x8_tr); |
||||
|
break; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
void printText(const char *text, uint8_t line) { |
||||
|
uint8_t dispX = (line == 0) ? 10 : 5; |
||||
|
setFont(line); |
||||
|
|
||||
|
dispX += (mEnScreenSaver) ? (mExtra % 7) : 0; |
||||
|
mDisplay->drawStr(dispX, mLineYOffsets[line], text); |
||||
|
} |
||||
|
}; |
@ -0,0 +1,208 @@ |
|||||
|
//-----------------------------------------------------------------------------
|
||||
|
// 2023 Ahoy, https://ahoydtu.de
|
||||
|
// Creative Commons - https://creativecommons.org/licenses/by-nc-sa/4.0/deed
|
||||
|
//-----------------------------------------------------------------------------
|
||||
|
|
||||
|
#ifndef __PUB_MQTT_IV_DATA_H__ |
||||
|
#define __PUB_MQTT_IV_DATA_H__ |
||||
|
|
||||
|
#include "../utils/dbg.h" |
||||
|
#include "../hm/hmSystem.h" |
||||
|
#include "pubMqttDefs.h" |
||||
|
|
||||
|
typedef std::function<void(const char *subTopic, const char *payload, bool retained)> pubMqttPublisherType; |
||||
|
|
||||
|
template<class HMSYSTEM> |
||||
|
class PubMqttIvData { |
||||
|
public: |
||||
|
void setup(HMSYSTEM *sys, uint32_t *utcTs, std::queue<uint8_t> *sendList) { |
||||
|
mSys = sys; |
||||
|
mUtcTimestamp = utcTs; |
||||
|
mSendList = sendList; |
||||
|
mState = IDLE; |
||||
|
|
||||
|
memset(mIvLastRTRpub, 0, MAX_NUM_INVERTERS * 4); |
||||
|
mRTRDataHasBeenSent = false; |
||||
|
|
||||
|
mTable[IDLE] = &PubMqttIvData::stateIdle; |
||||
|
mTable[START] = &PubMqttIvData::stateStart; |
||||
|
mTable[FIND_NXT_IV] = &PubMqttIvData::stateFindNxtIv; |
||||
|
mTable[SEND_DATA] = &PubMqttIvData::stateSend; |
||||
|
mTable[SEND_TOTALS] = &PubMqttIvData::stateSendTotals; |
||||
|
} |
||||
|
|
||||
|
void loop() { |
||||
|
(this->*mTable[mState])(); |
||||
|
yield(); |
||||
|
} |
||||
|
|
||||
|
bool start(void) { |
||||
|
if(IDLE != mState) |
||||
|
return false; |
||||
|
|
||||
|
mRTRDataHasBeenSent = false; |
||||
|
mState = START; |
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
void setPublishFunc(pubMqttPublisherType cb) { |
||||
|
mPublish = cb; |
||||
|
} |
||||
|
|
||||
|
private: |
||||
|
enum State {IDLE, START, FIND_NXT_IV, SEND_DATA, SEND_TOTALS, NUM_STATES}; |
||||
|
typedef void (PubMqttIvData::*StateFunction)(); |
||||
|
|
||||
|
void stateIdle() { |
||||
|
; // nothing to do
|
||||
|
} |
||||
|
|
||||
|
void stateStart() { |
||||
|
mLastIvId = 0; |
||||
|
if(!mSendList->empty()) { |
||||
|
mCmd = mSendList->front(); |
||||
|
|
||||
|
if((RealTimeRunData_Debug != mCmd) || !mRTRDataHasBeenSent) { |
||||
|
mSendTotals = (RealTimeRunData_Debug == mCmd); |
||||
|
memset(mTotal, 0, sizeof(float) * 4); |
||||
|
mState = FIND_NXT_IV; |
||||
|
} else |
||||
|
mSendList->pop(); |
||||
|
} else |
||||
|
mState = IDLE; |
||||
|
} |
||||
|
|
||||
|
void stateFindNxtIv() { |
||||
|
bool found = false; |
||||
|
|
||||
|
for (; mLastIvId < mSys->getNumInverters(); mLastIvId++) { |
||||
|
mIv = mSys->getInverterByPos(mLastIvId); |
||||
|
if (NULL != mIv) { |
||||
|
if (mIv->config->enabled) { |
||||
|
found = true; |
||||
|
break; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
mLastIvId++; |
||||
|
|
||||
|
mPos = 0; |
||||
|
if(found) |
||||
|
mState = SEND_DATA; |
||||
|
else if(mSendTotals) |
||||
|
mState = SEND_TOTALS; |
||||
|
else { |
||||
|
mSendList->pop(); |
||||
|
mState = START; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
void stateSend() { |
||||
|
record_t<> *rec = mIv->getRecordStruct(mCmd); |
||||
|
uint32_t lastTs = mIv->getLastTs(rec); |
||||
|
bool pubData = (lastTs > 0); |
||||
|
if (mCmd == RealTimeRunData_Debug) |
||||
|
pubData &= (lastTs != mIvLastRTRpub[mIv->id]); |
||||
|
|
||||
|
if (pubData) { |
||||
|
if(mPos < rec->length) { |
||||
|
bool retained = false; |
||||
|
if (mCmd == RealTimeRunData_Debug) { |
||||
|
switch (rec->assign[mPos].fieldId) { |
||||
|
case FLD_YT: |
||||
|
case FLD_YD: |
||||
|
if ((rec->assign[mPos].ch == CH0) && (!mIv->isProducing(*mUtcTimestamp))) { // avoids returns to 0 on restart
|
||||
|
mPos++; |
||||
|
return; |
||||
|
} |
||||
|
retained = true; |
||||
|
break; |
||||
|
} |
||||
|
|
||||
|
// calculate total values for RealTimeRunData_Debug
|
||||
|
if (CH0 == rec->assign[mPos].ch) { |
||||
|
switch (rec->assign[mPos].fieldId) { |
||||
|
case FLD_PAC: |
||||
|
mTotal[0] += mIv->getValue(mPos, rec); |
||||
|
break; |
||||
|
case FLD_YT: |
||||
|
mTotal[1] += mIv->getValue(mPos, rec); |
||||
|
break; |
||||
|
case FLD_YD: |
||||
|
mTotal[2] += mIv->getValue(mPos, rec); |
||||
|
break; |
||||
|
case FLD_PDC: |
||||
|
mTotal[3] += mIv->getValue(mPos, rec); |
||||
|
break; |
||||
|
} |
||||
|
} |
||||
|
} else |
||||
|
mIvLastRTRpub[mIv->id] = lastTs; |
||||
|
|
||||
|
snprintf(mSubTopic, 32 + MAX_NAME_LENGTH, "%s/ch%d/%s", mIv->config->name, rec->assign[mPos].ch, fields[rec->assign[mPos].fieldId]); |
||||
|
snprintf(mVal, 40, "%g", ah::round3(mIv->getValue(mPos, rec))); |
||||
|
mPublish(mSubTopic, mVal, retained); |
||||
|
mPos++; |
||||
|
} else |
||||
|
mState = FIND_NXT_IV; |
||||
|
} else |
||||
|
mState = FIND_NXT_IV; |
||||
|
} |
||||
|
|
||||
|
void stateSendTotals() { |
||||
|
uint8_t fieldId; |
||||
|
if(mPos < 4) { |
||||
|
bool retained = true; |
||||
|
switch (mPos) { |
||||
|
default: |
||||
|
case 0: |
||||
|
fieldId = FLD_PAC; |
||||
|
retained = false; |
||||
|
break; |
||||
|
case 1: |
||||
|
fieldId = FLD_YT; |
||||
|
break; |
||||
|
case 2: |
||||
|
fieldId = FLD_YD; |
||||
|
break; |
||||
|
case 3: |
||||
|
fieldId = FLD_PDC; |
||||
|
retained = false; |
||||
|
break; |
||||
|
} |
||||
|
snprintf(mSubTopic, 32 + MAX_NAME_LENGTH, "total/%s", fields[fieldId]); |
||||
|
snprintf(mVal, 40, "%g", ah::round3(mTotal[mPos])); |
||||
|
mPublish(mSubTopic, mVal, retained); |
||||
|
mPos++; |
||||
|
} else { |
||||
|
mSendList->pop(); |
||||
|
mState = START; |
||||
|
} |
||||
|
|
||||
|
mRTRDataHasBeenSent = true; |
||||
|
} |
||||
|
|
||||
|
HMSYSTEM *mSys; |
||||
|
uint32_t *mUtcTimestamp; |
||||
|
pubMqttPublisherType mPublish; |
||||
|
State mState; |
||||
|
StateFunction mTable[NUM_STATES]; |
||||
|
|
||||
|
uint8_t mCmd; |
||||
|
uint8_t mLastIvId; |
||||
|
bool mSendTotals; |
||||
|
float mTotal[4]; |
||||
|
|
||||
|
Inverter<> *mIv; |
||||
|
uint8_t mPos; |
||||
|
uint32_t mIvLastRTRpub[MAX_NUM_INVERTERS]; |
||||
|
bool mRTRDataHasBeenSent; |
||||
|
|
||||
|
char mSubTopic[32 + MAX_NAME_LENGTH + 1]; |
||||
|
char mVal[40]; |
||||
|
|
||||
|
std::queue<uint8_t> *mSendList; |
||||
|
}; |
||||
|
|
||||
|
#endif /*__PUB_MQTT_IV_DATA_H__*/ |
Loading…
Reference in new issue