Feature: Add screensavermode also to diagram drawing.
This commit is contained in:
parent
733a566172
commit
ac427523b5
@ -7,7 +7,10 @@
|
|||||||
|
|
||||||
#define CHART_HEIGHT 20 // chart area hight in pixels
|
#define CHART_HEIGHT 20 // chart area hight in pixels
|
||||||
#define CHART_WIDTH 47 // chart area width 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
|
#define DIAG_POSY 0
|
||||||
|
|
||||||
class DisplayGraphicDiagramClass {
|
class DisplayGraphicDiagramClass {
|
||||||
@ -15,7 +18,7 @@ public:
|
|||||||
DisplayGraphicDiagramClass();
|
DisplayGraphicDiagramClass();
|
||||||
|
|
||||||
void init(Scheduler& scheduler, U8G2* display);
|
void init(Scheduler& scheduler, U8G2* display);
|
||||||
void redraw();
|
void redraw(uint8_t screenSaverOffsetX);
|
||||||
|
|
||||||
void updatePeriod();
|
void updatePeriod();
|
||||||
|
|
||||||
@ -34,6 +37,4 @@ private:
|
|||||||
|
|
||||||
float _iRunningAverage = 0;
|
float _iRunningAverage = 0;
|
||||||
uint16_t _iRunningAverageCnt = 0;
|
uint16_t _iRunningAverageCnt = 0;
|
||||||
|
|
||||||
uint8_t _graphPosX = DIAG_POSX;
|
|
||||||
};
|
};
|
||||||
@ -161,12 +161,14 @@ void DisplayGraphicClass::loop()
|
|||||||
if (Datastore.getIsAtLeastOneReachable()) {
|
if (Datastore.getIsAtLeastOneReachable()) {
|
||||||
displayPowerSave = false;
|
displayPowerSave = false;
|
||||||
if (_isLarge) {
|
if (_isLarge) {
|
||||||
_diagram.redraw();
|
uint8_t screenSaverOffsetX = enableScreensaver ? (_mExtra % 7) : 0;
|
||||||
|
_diagram.redraw(screenSaverOffsetX);
|
||||||
}
|
}
|
||||||
if (Datastore.getTotalAcPowerEnabled() > 999) {
|
float watts = Datastore.getTotalAcPowerEnabled();
|
||||||
snprintf(_fmtText, sizeof(_fmtText), i18n_current_power_kw[_display_language], (Datastore.getTotalAcPowerEnabled() / 1000));
|
if (watts > 999) {
|
||||||
|
snprintf(_fmtText, sizeof(_fmtText), i18n_current_power_kw[_display_language], watts / 1000);
|
||||||
} else {
|
} 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);
|
printText(_fmtText, 0);
|
||||||
_previousMillis = millis();
|
_previousMillis = millis();
|
||||||
|
|||||||
@ -48,10 +48,6 @@ void DisplayGraphicDiagramClass::dataPointLoop()
|
|||||||
_iRunningAverage = 0;
|
_iRunningAverage = 0;
|
||||||
_iRunningAverageCnt = 0;
|
_iRunningAverageCnt = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Configuration.get().Display.ScreenSaver) {
|
|
||||||
_graphPosX = DIAG_POSX - (_graphValuesCount % 2);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t DisplayGraphicDiagramClass::getSecondsPerDot()
|
uint32_t DisplayGraphicDiagramClass::getSecondsPerDot()
|
||||||
@ -64,25 +60,32 @@ void DisplayGraphicDiagramClass::updatePeriod()
|
|||||||
_dataPointTask.setInterval(getSecondsPerDot() * TASK_SECOND);
|
_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;
|
uint8_t graphPosY = DIAG_POSY;
|
||||||
|
|
||||||
// draw diagram axis
|
// draw diagram axis
|
||||||
_display->drawVLine(_graphPosX, graphPosY, CHART_HEIGHT);
|
_display->drawVLine(graphPosX, graphPosY, CHART_HEIGHT);
|
||||||
_display->drawHLine(_graphPosX, graphPosY + CHART_HEIGHT - 1, CHART_WIDTH);
|
_display->drawHLine(graphPosX, graphPosY + CHART_HEIGHT - 1, CHART_WIDTH);
|
||||||
|
|
||||||
_display->drawLine(_graphPosX + 1, graphPosY + 1, _graphPosX + 2, graphPosY + 2); // UP-arrow
|
_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 - 2, graphPosY + 2, graphPosX - 1, graphPosY + 1); // UP-arrow
|
||||||
_display->drawLine(_graphPosX + CHART_WIDTH - 3, graphPosY + CHART_HEIGHT + 1, _graphPosX + CHART_WIDTH - 2, graphPosY + CHART_HEIGHT); // LEFT-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
|
// 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];
|
char fmtText[7];
|
||||||
const float maxWatts = *std::max_element(_graphValues.begin(), _graphValues.end());
|
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);
|
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
|
// draw chart
|
||||||
const float scaleFactor = maxWatts / CHART_HEIGHT;
|
const float scaleFactor = maxWatts / CHART_HEIGHT;
|
||||||
@ -90,15 +93,15 @@ void DisplayGraphicDiagramClass::redraw()
|
|||||||
for (int i = 0; i < _graphValuesCount; i++) {
|
for (int i = 0; i < _graphValuesCount; i++) {
|
||||||
if (scaleFactor > 0) {
|
if (scaleFactor > 0) {
|
||||||
if (i == 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 {
|
} 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
|
// draw one tick per hour to the x-axis
|
||||||
if (i * getSecondsPerDot() > (3600u * axisTick)) {
|
if (i * getSecondsPerDot() > (3600u * axisTick)) {
|
||||||
_display->drawPixel(_graphPosX + 1 + i, graphPosY + CHART_HEIGHT);
|
_display->drawPixel(graphPosX + 1 + i, graphPosY + CHART_HEIGHT);
|
||||||
axisTick++;
|
axisTick++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user