From 6036d8efea2f1e63f6d80331b870c7b3c195f38c Mon Sep 17 00:00:00 2001 From: Bernhard Kirchen Date: Sat, 10 Feb 2024 17:07:31 +0100 Subject: [PATCH] implement oscillating screensaver this implementation avoids the display content jumping the full screensaver offset from right to left when the modulo operator wraps. this change makes the display content walk from right to left as it did walk from left to right. --- src/Display_Graphic.cpp | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/src/Display_Graphic.cpp b/src/Display_Graphic.cpp index 12b2aa56e..cdb807fca 100644 --- a/src/Display_Graphic.cpp +++ b/src/Display_Graphic.cpp @@ -103,27 +103,23 @@ void DisplayGraphicClass::printText(const char* text, const uint8_t line) if (!_isLarge) { dispX = (line == 0) ? 5 : 0; } else { - switch (line) { - case 0: - if (_diagram_mode == DiagramMode_t::Small) { - // Center between left border and diagram - dispX = (CHART_POSX - _display->getStrWidth(text)) / 2; - } else { - // Center on screen - dispX = (_display->getDisplayWidth() - _display->getStrWidth(text)) / 2; - } - break; - case 3: + if (line == 0 && _diagram_mode == DiagramMode_t::Small) { + // Center between left border and diagram + dispX = (CHART_POSX - _display->getStrWidth(text)) / 2; + } else { // Center on screen dispX = (_display->getDisplayWidth() - _display->getStrWidth(text)) / 2; - break; - default: - dispX = 5; - break; } } - dispX += enableScreensaver ? (_mExtra % 7) : 0; + if (enableScreensaver) { + unsigned maxOffset = (_isLarge?8:6); + unsigned period = 2 * maxOffset; + unsigned step = _mExtra % period; + int offset = (step <= maxOffset)?step:(period - step); + offset -= (_isLarge?5:0); // oscillate around center on large screens + dispX += offset; + } _display->drawStr(dispX, _lineOffsets[line], text); }