Added basic percentage display
This commit is contained in:
@ -2,8 +2,10 @@
|
|||||||
|
|
||||||
// 3rdparty lib includes
|
// 3rdparty lib includes
|
||||||
#include <screenmanager.h>
|
#include <screenmanager.h>
|
||||||
|
#include <tftinstance.h>
|
||||||
|
|
||||||
// local includes
|
// local includes
|
||||||
|
#include "battery.h"
|
||||||
#include "globals.h"
|
#include "globals.h"
|
||||||
#include "displays/menus/batterymenu.h"
|
#include "displays/menus/batterymenu.h"
|
||||||
|
|
||||||
@ -26,6 +28,22 @@ void BatteryGraphDisplay::redraw()
|
|||||||
using namespace espgui;
|
using namespace espgui;
|
||||||
Base::redraw();
|
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
|
// tft.drawLine() code
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,4 +12,7 @@ public:
|
|||||||
void redraw() override;
|
void redraw() override;
|
||||||
|
|
||||||
void buttonPressed(espgui::Button button) override;
|
void buttonPressed(espgui::Button button) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
float m_lastBatVoltage{0};
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user