Added basic percentage display

This commit is contained in:
CommanderRedYT
2022-02-28 01:45:03 +01:00
parent 7f6fa967c8
commit b48a40742e
2 changed files with 21 additions and 0 deletions

View File

@ -2,8 +2,10 @@
// 3rdparty lib includes
#include <screenmanager.h>
#include <tftinstance.h>
// 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
}

View File

@ -12,4 +12,7 @@ public:
void redraw() override;
void buttonPressed(espgui::Button button) override;
private:
float m_lastBatVoltage{0};
};