diff --git a/main/displays/batterygraphdisplay.cpp b/main/displays/batterygraphdisplay.cpp index ff63cb1..25261c7 100644 --- a/main/displays/batterygraphdisplay.cpp +++ b/main/displays/batterygraphdisplay.cpp @@ -2,8 +2,10 @@ // 3rdparty lib includes #include +#include // local includes +#include "battery.h" #include "globals.h" #include "displays/menus/batterymenu.h" @@ -26,6 +28,22 @@ void BatteryGraphDisplay::redraw() using namespace espgui; Base::redraw(); + if (const auto avgVoltage = controllers.getAvgVoltage(); avgVoltage) + { + if (*avgVoltage == m_lastBatVoltage) + return; + const auto cellType = configs.battery.cellType.value; + + uint16_t onePercent = tft.width() / 100; + uint16_t xOffset = onePercent * getBatteryPercentage(*avgVoltage, cellType); + uint16_t lastXOffset = onePercent * getBatteryPercentage(m_lastBatVoltage, cellType); + + // clear the old one and draw the new one + tft.fillRect(lastXOffset, 40, onePercent, tft.height() - 40, TFT_BLACK); + tft.fillRect(xOffset, 40, onePercent, tft.height() - 40, TFT_WHITE); + m_lastBatVoltage = *avgVoltage; + } + // tft.drawLine() code } diff --git a/main/displays/batterygraphdisplay.h b/main/displays/batterygraphdisplay.h index d481b8f..725a723 100644 --- a/main/displays/batterygraphdisplay.h +++ b/main/displays/batterygraphdisplay.h @@ -12,4 +12,7 @@ public: void redraw() override; void buttonPressed(espgui::Button button) override; + +private: + float m_lastBatVoltage{0}; };