Feature: Add screensavermode also to diagram drawing.

This commit is contained in:
Stefan Oberhumer 2023-12-22 23:35:17 +01:00 committed by Thomas Basler
parent 733a566172
commit ac427523b5
3 changed files with 32 additions and 26 deletions

View File

@ -7,7 +7,10 @@
#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 {
@ -15,7 +18,7 @@ public:
DisplayGraphicDiagramClass();
void init(Scheduler& scheduler, U8G2* display);
void redraw();
void redraw(uint8_t screenSaverOffsetX);
void updatePeriod();
@ -34,6 +37,4 @@ private:
float _iRunningAverage = 0;
uint16_t _iRunningAverageCnt = 0;
uint8_t _graphPosX = DIAG_POSX;
};

View File

@ -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));
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();

View File

@ -48,10 +48,6 @@ void DisplayGraphicDiagramClass::dataPointLoop()
_iRunningAverage = 0;
_iRunningAverageCnt = 0;
}
if (Configuration.get().Display.ScreenSaver) {
_graphPosX = DIAG_POSX - (_graphValuesCount % 2);
}
}
uint32_t DisplayGraphicDiagramClass::getSecondsPerDot()
@ -64,25 +60,32 @@ void DisplayGraphicDiagramClass::updatePeriod()
_dataPointTask.setInterval(getSecondsPerDot() * TASK_SECOND);
}
void DisplayGraphicDiagramClass::redraw()
void DisplayGraphicDiagramClass::redraw(uint8_t screenSaverOffsetX)
{
uint8_t graphPosX = DIAG_POSX + ((screenSaverOffsetX > 3) ? 1 : 0); // screenSaverOffsetX expected to be in range 0..6
uint8_t graphPosY = DIAG_POSY;
// 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;
@ -90,15 +93,15 @@ void DisplayGraphicDiagramClass::redraw()
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++;
}
}