Skip to content

Commit

Permalink
Merge with upstream
Browse files Browse the repository at this point in the history
Merge with upstream and project cleanup as automatic resolve produced some code artefacts
  • Loading branch information
OFreddy committed Dec 25, 2023
1 parent 19acc67 commit 980cd14
Show file tree
Hide file tree
Showing 19 changed files with 113 additions and 121 deletions.
11 changes: 6 additions & 5 deletions include/Display_Graphic_Diagram.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,18 @@

#define CHART_HEIGHT 20 // chart area hight in pixels
#define CHART_WIDTH 47 // chart area width in pixels
#define DIAG_POSX 80 // position were Diag is drawn at

// Left-Upper position of diagram is drawn
// (text of Y-axis is display left of that pos)
#define DIAG_POSX 80
#define DIAG_POSY 0

class DisplayGraphicDiagramClass {
public:
DisplayGraphicDiagramClass();

void init(Scheduler& scheduler, U8G2* display);
void redraw();
void redraw(uint8_t screenSaverOffsetX);

void updatePeriod();

Expand All @@ -34,6 +37,4 @@ class DisplayGraphicDiagramClass {

float _iRunningAverage = 0;
uint16_t _iRunningAverageCnt = 0;

uint8_t _graphPosX = DIAG_POSX;
};
};
1 change: 1 addition & 0 deletions include/SunPosition.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class SunPositionClass {

bool isDayPeriod() const;
bool isSunsetAvailable() const;
bool isValidInfo() const;
bool sunsetTime(struct tm* info) const;
bool sunriseTime(struct tm* info) const;
void setDoRecalc(const bool doRecalc);
Expand Down
12 changes: 7 additions & 5 deletions src/Display_Graphic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,12 +161,14 @@ void DisplayGraphicClass::loop()
if (Datastore.getIsAtLeastOneReachable()) {
displayPowerSave = false;
if (_isLarge) {
_diagram.redraw();
uint8_t screenSaverOffsetX = enableScreensaver ? (_mExtra % 7) : 0;
_diagram.redraw(screenSaverOffsetX);
}
if (Datastore.getTotalAcPowerEnabled() > 999) {
snprintf(_fmtText, sizeof(_fmtText), i18n_current_power_kw[_display_language], (Datastore.getTotalAcPowerEnabled() / 1000));
const float watts = Datastore.getTotalAcPowerEnabled();
if (watts > 999) {
snprintf(_fmtText, sizeof(_fmtText), i18n_current_power_kw[_display_language], watts / 1000);
} else {
snprintf(_fmtText, sizeof(_fmtText), i18n_current_power_w[_display_language], Datastore.getTotalAcPowerEnabled());
snprintf(_fmtText, sizeof(_fmtText), i18n_current_power_w[_display_language], watts);
}
printText(_fmtText, 0);
_previousMillis = millis();
Expand Down Expand Up @@ -224,4 +226,4 @@ void DisplayGraphicClass::setStatus(const bool turnOn)
_displayTurnedOn = turnOn;
}

DisplayGraphicClass Display;
DisplayGraphicClass Display;
43 changes: 23 additions & 20 deletions src/Display_Graphic_Diagram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,17 @@ void DisplayGraphicDiagramClass::averageLoop()

void DisplayGraphicDiagramClass::dataPointLoop()
{
if (_graphValuesCount >= CHART_WIDTH) {
for (uint8_t i = 0; i < CHART_WIDTH - 1; i++) {
if (_graphValuesCount >= std::size(_graphValues)) {
for (uint8_t i = 0; i < std::size(_graphValues) - 1; i++) {
_graphValues[i] = _graphValues[i + 1];
}
_graphValuesCount = CHART_WIDTH - 1;
_graphValuesCount = std::size(_graphValues) - 1;
}
if (_iRunningAverageCnt != 0) {
_graphValues[_graphValuesCount++] = _iRunningAverage / _iRunningAverageCnt;
_iRunningAverage = 0;
_iRunningAverageCnt = 0;
}

if (Configuration.get().Display.ScreenSaver) {
_graphPosX = DIAG_POSX - (_graphValuesCount % 2);
}
}

uint32_t DisplayGraphicDiagramClass::getSecondsPerDot()
Expand All @@ -64,41 +60,48 @@ void DisplayGraphicDiagramClass::updatePeriod()
_dataPointTask.setInterval(getSecondsPerDot() * TASK_SECOND);
}

void DisplayGraphicDiagramClass::redraw()
void DisplayGraphicDiagramClass::redraw(uint8_t screenSaverOffsetX)
{
uint8_t graphPosY = DIAG_POSY;
const uint8_t graphPosX = DIAG_POSX + ((screenSaverOffsetX > 3) ? 1 : 0); // screenSaverOffsetX expected to be in range 0..6
const uint8_t graphPosY = DIAG_POSY + ((screenSaverOffsetX > 3) ? 1 : 0);

// draw diagram axis
_display->drawVLine(_graphPosX, graphPosY, CHART_HEIGHT);
_display->drawHLine(_graphPosX, graphPosY + CHART_HEIGHT - 1, CHART_WIDTH);
_display->drawVLine(graphPosX, graphPosY, CHART_HEIGHT);
_display->drawHLine(graphPosX, graphPosY + CHART_HEIGHT - 1, CHART_WIDTH);

_display->drawLine(_graphPosX + 1, graphPosY + 1, _graphPosX + 2, graphPosY + 2); // UP-arrow
_display->drawLine(_graphPosX + CHART_WIDTH - 3, graphPosY + CHART_HEIGHT - 3, _graphPosX + CHART_WIDTH - 2, graphPosY + CHART_HEIGHT - 2); // LEFT-arrow
_display->drawLine(_graphPosX + CHART_WIDTH - 3, graphPosY + CHART_HEIGHT + 1, _graphPosX + CHART_WIDTH - 2, graphPosY + CHART_HEIGHT); // LEFT-arrow
_display->drawLine(graphPosX + 1, graphPosY + 1, graphPosX + 2, graphPosY + 2); // UP-arrow
_display->drawLine(graphPosX - 2, graphPosY + 2, graphPosX - 1, graphPosY + 1); // UP-arrow
_display->drawLine(graphPosX + CHART_WIDTH - 3, graphPosY + CHART_HEIGHT - 3, graphPosX + CHART_WIDTH - 2, graphPosY + CHART_HEIGHT - 2); // LEFT-arrow
_display->drawLine(graphPosX + CHART_WIDTH - 3, graphPosY + CHART_HEIGHT + 1, graphPosX + CHART_WIDTH - 2, graphPosY + CHART_HEIGHT); // LEFT-arrow

// draw AC value
_display->setFont(u8g2_font_tom_thumb_4x6_mr);
_display->setFont(u8g2_font_tom_thumb_4x6_mr); // 4 pixels per char
char fmtText[7];
const float maxWatts = *std::max_element(_graphValues.begin(), _graphValues.end());
snprintf(fmtText, sizeof(fmtText), "%dW", static_cast<uint16_t>(maxWatts));
if (maxWatts > 999) {
snprintf(fmtText, sizeof(fmtText), "%2.1fkW", maxWatts / 1000);
} else {
snprintf(fmtText, sizeof(fmtText), "%dW", static_cast<uint16_t>(maxWatts));
}
const uint8_t textLength = strlen(fmtText);
_display->drawStr(_graphPosX - (textLength * 4), graphPosY + 5, fmtText);
const uint8_t space_and_arrow_pixels = 2;
_display->drawStr(graphPosX - space_and_arrow_pixels - (textLength * 4), graphPosY + 5, fmtText);

// draw chart
const float scaleFactor = maxWatts / CHART_HEIGHT;
uint8_t axisTick = 1;
for (int i = 0; i < _graphValuesCount; i++) {
if (scaleFactor > 0) {
if (i == 0) {
_display->drawPixel(_graphPosX + 1 + i, graphPosY + CHART_HEIGHT - ((_graphValues[i] / scaleFactor) + 0.5)); // + 0.5 to round mathematical
_display->drawPixel(graphPosX + 1 + i, graphPosY + CHART_HEIGHT - ((_graphValues[i] / scaleFactor) + 0.5)); // + 0.5 to round mathematical
} else {
_display->drawLine(_graphPosX + i, graphPosY + CHART_HEIGHT - ((_graphValues[i - 1] / scaleFactor) + 0.5), _graphPosX + 1 + i, graphPosY + CHART_HEIGHT - ((_graphValues[i] / scaleFactor) + 0.5));
_display->drawLine(graphPosX + i, graphPosY + CHART_HEIGHT - ((_graphValues[i - 1] / scaleFactor) + 0.5), graphPosX + 1 + i, graphPosY + CHART_HEIGHT - ((_graphValues[i] / scaleFactor) + 0.5));
}
}

// draw one tick per hour to the x-axis
if (i * getSecondsPerDot() > (3600u * axisTick)) {
_display->drawPixel(_graphPosX + 1 + i, graphPosY + CHART_HEIGHT);
_display->drawPixel(graphPosX + 1 + i, graphPosY + CHART_HEIGHT);
axisTick++;
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/InverterSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,12 @@ void InverterSettingsClass::init(Scheduler& scheduler)
scheduler.addTask(_settingsTask);
_settingsTask.setCallback(std::bind(&InverterSettingsClass::settingsLoop, this));
_settingsTask.setIterations(TASK_FOREVER);
_settingsTask.setInterval(SUNPOS_UPDATE_INTERVAL);
_settingsTask.setInterval(INVERTER_UPDATE_SETTINGS_INTERVAL);
_settingsTask.enable();
}

void InverterSettingsClass::settingsLoop()
{
_lastUpdate = millis();
const CONFIG_T& config = Configuration.get();

for (uint8_t i = 0; i < INV_MAX_COUNT; i++) {
Expand Down
14 changes: 9 additions & 5 deletions src/SunPosition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ void SunPositionClass::loop()
updateSunData();
}

if (Configuration.get().Sunset_Deepsleep && !_isDayPeriod && (millis() > _bootDelay)) {
esp_sleep_enable_timer_wakeup(Configuration.get().Sunset_Deepsleeptime * uS_TO_S_FACTOR);
MessageOutput.print(F("SunsetClass - Going to sleep now for "));
MessageOutput.printf("%u s\n", Configuration.get().Sunset_Deepsleeptime);
if (Configuration.get().Ntp.Deepsleep && !isDayPeriod() && (millis() > _bootDelay)) {
esp_sleep_enable_timer_wakeup(Configuration.get().Ntp.Deepsleeptime * uS_TO_S_FACTOR);
MessageOutput.print(F("SunPositionClass - Going to sleep now for "));
MessageOutput.printf("%u s\n", Configuration.get().Ntp.Deepsleeptime);
delay(1000);
MessageOutput.flush();
esp_deep_sleep_start();
Expand All @@ -67,6 +67,11 @@ bool SunPositionClass::isSunsetAvailable() const
return _isSunsetAvailable;
}

bool SunPositionClass::isValidInfo() const
{
return _isValidInfo;
}

void SunPositionClass::setDoRecalc(const bool doRecalc)
{
_doRecalc = doRecalc;
Expand Down Expand Up @@ -141,7 +146,6 @@ void SunPositionClass::updateSunData()
_sunriseMinutes = static_cast<int>(sunriseRaw);
_sunsetMinutes = static_cast<int>(sunsetRaw);

_isDayPeriod = (minutesPastMidnight >= _sunriseMinutes) && (minutesPastMidnight < _sunsetMinutes);
_isSunsetAvailable = true;
_isValidInfo = true;
}
Expand Down
24 changes: 1 addition & 23 deletions src/WebApi_ntp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,8 @@ void WebApiNtpClass::onNtpStatus(AsyncWebServerRequest* request)
}
root["sun_settime"] = timeStringBuff;

root["sun_isValidInfo"] = SunPosition.isValidInfo();
root["sun_isSunsetAvailable"] = SunPosition.isSunsetAvailable();
root["sun_isDayPeriod"] = SunPosition.isDayPeriod();
root["deepsleep"] = config.Sunset_Deepsleep;

response->setLength();
request->send(response);
Expand Down Expand Up @@ -198,27 +197,6 @@ void WebApiNtpClass::onNtpAdminPost(AsyncWebServerRequest* request)
return;
}

if (root["deepsleeptime"].as<int16_t>() < 5 || root["deepsleeptime"].as<int16_t>() > 300) {
retMsg["message"] = "Deepsleep time must be a number between 5 and 300 seconds!";
response->setLength();
request->send(response);
return;
}

if (root["latitude"].as<double>() < -90.0 || root["latitude"].as<double>() > +90.0) {
retMsg["message"] = "Latitude must be a number between -90.0 and 90.0!";
response->setLength();
request->send(response);
return;
}

if (root["longitude"].as<double>() < -180.0 || root["longitude"].as<double>() > +180.0) {
retMsg["message"] = "Longitude must be a number between -180.0 and 180.0!";
response->setLength();
request->send(response);
return;
}

CONFIG_T& config = Configuration.get();
strlcpy(config.Ntp.Server, root["ntp_server"].as<String>().c_str(), sizeof(config.Ntp.Server));
strlcpy(config.Ntp.Timezone, root["ntp_timezone"].as<String>().c_str(), sizeof(config.Ntp.Timezone));
Expand Down
10 changes: 7 additions & 3 deletions src/WebApi_webapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ extern const uint8_t file_zones_json_end[] asm("_binary_webapp_dist_zones_json_g
extern const uint8_t file_app_js_end[] asm("_binary_webapp_dist_js_app_js_gz_end");
extern const uint8_t file_site_webmanifest_end[] asm("_binary_webapp_dist_site_webmanifest_end");

#ifdef AUTO_GIT_HASH
#define ETAG_HTTP_HEADER_VAL "\"" AUTO_GIT_HASH "\"" // ETag value must be between quotes
#endif

void WebApiWebappClass::init(AsyncWebServer& server)
{
_server = &server;
Expand Down Expand Up @@ -62,12 +66,12 @@ void WebApiWebappClass::init(AsyncWebServer& server)
});

_server->on("/js/app.js", HTTP_GET, [](AsyncWebServerRequest* request) {
#ifdef AUTO_GIT_HASH
#ifdef ETAG_HTTP_HEADER_VAL
// check client If-None-Match header vs ETag/AUTO_GIT_HASH
bool eTagMatch = false;
if (request->hasHeader("If-None-Match")) {
const AsyncWebHeader* h = request->getHeader("If-None-Match");
if (strncmp(AUTO_GIT_HASH, h->value().c_str(), strlen(AUTO_GIT_HASH)) == 0) {
if (strncmp(ETAG_HTTP_HEADER_VAL, h->value().c_str(), strlen(ETAG_HTTP_HEADER_VAL)) == 0) {
eTagMatch = true;
}
}
Expand All @@ -82,7 +86,7 @@ void WebApiWebappClass::init(AsyncWebServer& server)
}
// HTTP requires cache headers in 200 and 304 to be identical
response->addHeader("Cache-Control", "public, must-revalidate");
response->addHeader("ETag", AUTO_GIT_HASH);
response->addHeader("ETag", ETAG_HTTP_HEADER_VAL);
#else
AsyncWebServerResponse* response = request->beginResponse_P(200, "text/javascript", file_app_js_start, file_app_js_end - file_app_js_start);
response->addHeader("Content-Encoding", "gzip");
Expand Down
6 changes: 3 additions & 3 deletions webapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"vue-router": "^4.2.5"
},
"devDependencies": {
"@intlify/unplugin-vue-i18n": "^1.6.0",
"@intlify/unplugin-vue-i18n": "^2.0.0",
"@rushstack/eslint-patch": "^1.6.1",
"@tsconfig/node18": "^18.2.2",
"@types/bootstrap": "^5.2.10",
Expand All @@ -41,7 +41,7 @@
"typescript": "^5.3.3",
"vite": "^5.0.10",
"vite-plugin-compression": "^0.5.1",
"vite-plugin-css-injected-by-js": "^3.3.0",
"vue-tsc": "^1.8.25"
"vite-plugin-css-injected-by-js": "^3.3.1",
"vue-tsc": "^1.8.26"
}
}
1 change: 1 addition & 0 deletions webapp/src/locales/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,7 @@
"LocationConfiguration": "Standortkonfiguration",
"Longitude": "Längengrad:",
"Latitude": "Breitengrad:",
"Deepsleep": "Deepsleep",
"EnableDeepsleep": "Deepsleep aktivieren",
"EnableDeepsleepHint": "Wenn aktiviert wird der ESP32 in der Nacht in den Deep Sleep Modus versetzt um Energie zu sparen.",
"DeepsleepTime": "Deepsleep Periode:",
Expand Down
1 change: 1 addition & 0 deletions webapp/src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,7 @@
"LocationConfiguration": "Location Configuration",
"Longitude": "Longitude",
"Latitude": "Latitude",
"Deepsleep": "Deepsleep",
"EnableDeepsleep": "Enable Deepsleep",
"EnableDeepsleepHint": "When activated, the ESP32 is put into deep sleep mode at night to save energy.",
"DeepsleepTime": "Deepsleep Duration:",
Expand Down
10 changes: 3 additions & 7 deletions webapp/src/locales/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -260,13 +260,6 @@
"Status": "Statut",
"Synced": "synchronisée",
"NotSynced": "pas synchronisée",
"LocalTime": "Heure locale",
"Sunrise": "Nautical Lever du solei",
"Sunset": "Nautical Coucher du soleil",
"SunriseInformation": "Informations sur le lever et le coucher du soleil",
"Enabled": "activé",
"Disabled": "désactivé",
"TimezoneOffset": "Décalage du fuseau horaire",
"LocalTime": "Heure locale",
"Sunrise": "Lever du soleil",
"Sunset": "Coucher du soleil",
Expand Down Expand Up @@ -384,6 +377,7 @@
"LocationConfiguration": "Géolocalisation",
"Longitude": "Longitude",
"Latitude": "Latitude",
"Deepsleep": "Veille profonde",
"EnableDeepsleep": "Activer la veille profonde",
"EnableDeepsleepHint": "Lorsqu'il est activé, l'ESP32 est mis en mode veille profonde pour économiser de l'énergie.",
"DeepsleepTime": "Periode de la veille profonde:",
Expand Down Expand Up @@ -495,6 +489,8 @@
"PollEnableNight": "Interroger les données de l'onduleur la nuit",
"CommandEnable": "Envoyer des commandes",
"CommandEnableNight": "Envoyer des commandes la nuit",
"AddToTotal": "Add power and yield to the total",
"AddToTotalHint": "If this option is activated, the power and the yield of this inverter are taken into account in the totals in the live view.",
"StringName": "Nom de la ligne {num}:",
"StringNameHint": "Ici, vous pouvez spécifier un nom personnalisé pour le port respectif de votre onduleur.",
"StringMaxPower": "Puissance maximale de la ligne {num}:",
Expand Down
2 changes: 1 addition & 1 deletion webapp/src/types/NtpStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ export interface NtpStatus {
sun_risetime: string;
sun_settime: string;
sun_isDayPeriod: boolean;
sun_isValidInfo: boolean;
sun_isSunsetAvailable: boolean;
deepsleep: boolean;
}
Loading

0 comments on commit 980cd14

Please sign in to comment.