Added labels for percentages
This commit is contained in:
@ -9,6 +9,8 @@
|
|||||||
#include <textwithvaluehelper.h>
|
#include <textwithvaluehelper.h>
|
||||||
#include <fmt/core.h>
|
#include <fmt/core.h>
|
||||||
|
|
||||||
|
#include <tftinstance.h>
|
||||||
|
|
||||||
// Local includes
|
// Local includes
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
#include "icons/settings.h"
|
#include "icons/settings.h"
|
||||||
@ -38,6 +40,15 @@ constexpr char TEXT_VOLTAGECALIBRATION_RESET[] = "Reset calibration";
|
|||||||
constexpr char TEXT_BACK[] = "Back";
|
constexpr char TEXT_BACK[] = "Back";
|
||||||
|
|
||||||
class CurrentBatteryStatusText : public virtual espgui::TextInterface { public: std::string text() const override { return getBatteryPercentageString(); } };
|
class CurrentBatteryStatusText : public virtual espgui::TextInterface { public: std::string text() const override { return getBatteryPercentageString(); } };
|
||||||
|
class WhStatisticsText : public virtual espgui::TextInterface { public: std::string text() const override
|
||||||
|
{
|
||||||
|
if (battery::bootBatWh)
|
||||||
|
{
|
||||||
|
return fmt::format("&s&1{}Wh => &2{}Wh &6({})", (int)*battery::bootBatWh, (int)getRemainingWattHours(), (int)getRemainingWattHours() - (int)battery::bootBatWh.value());
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
using BatteryCellSeriesChangeScreen = espgui::makeComponent<
|
using BatteryCellSeriesChangeScreen = espgui::makeComponent<
|
||||||
BobbyChangeValueDisplay<uint8_t>,
|
BobbyChangeValueDisplay<uint8_t>,
|
||||||
@ -64,10 +75,10 @@ using BatteryWHperKMChangeScreen = espgui::makeComponent<
|
|||||||
>;
|
>;
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
|
using namespace espgui;
|
||||||
|
|
||||||
BatteryMenu::BatteryMenu()
|
BatteryMenu::BatteryMenu()
|
||||||
{
|
{
|
||||||
using namespace espgui;
|
|
||||||
|
|
||||||
constructMenuItem<makeComponent<MenuItem, CurrentBatteryStatusText, DisabledColor, DummyAction>>();
|
constructMenuItem<makeComponent<MenuItem, CurrentBatteryStatusText, DisabledColor, DummyAction>>();
|
||||||
constructMenuItem<makeComponent<MenuItem, EmptyText, DummyAction>>();
|
constructMenuItem<makeComponent<MenuItem, EmptyText, DummyAction>>();
|
||||||
constructMenuItem<makeComponent<MenuItem, TextWithValueHelper<TEXT_CELL_SERIES, BatterySeriesCellsAccessor>, SwitchScreenAction<BatteryCellSeriesChangeScreen>>>();
|
constructMenuItem<makeComponent<MenuItem, TextWithValueHelper<TEXT_CELL_SERIES, BatterySeriesCellsAccessor>, SwitchScreenAction<BatteryCellSeriesChangeScreen>>>();
|
||||||
@ -75,6 +86,7 @@ BatteryMenu::BatteryMenu()
|
|||||||
constructMenuItem<makeComponent<MenuItem, TextWithValueHelper<TEXT_BATTERY_WHKM, BatteryWHperKMAccessor>, SwitchScreenAction<BatteryWHperKMChangeScreen>>>();
|
constructMenuItem<makeComponent<MenuItem, TextWithValueHelper<TEXT_BATTERY_WHKM, BatteryWHperKMAccessor>, SwitchScreenAction<BatteryWHperKMChangeScreen>>>();
|
||||||
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_SELECT_CELL_TYPE>, SwitchScreenAction<BatteryTypeMenu>>>();
|
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_SELECT_CELL_TYPE>, SwitchScreenAction<BatteryTypeMenu>>>();
|
||||||
constructMenuItem<makeComponent<MenuItem, EmptyText, DummyAction>>();
|
constructMenuItem<makeComponent<MenuItem, EmptyText, DummyAction>>();
|
||||||
|
constructMenuItem<makeComponent<MenuItem, WhStatisticsText, DummyAction>>();
|
||||||
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_BATTERY_CALIBRATE>, SwitchScreenAction<CalibrateVoltageDisplay>, StaticMenuItemIcon<&bobbyicons::settings>>>();
|
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_BATTERY_CALIBRATE>, SwitchScreenAction<CalibrateVoltageDisplay>, StaticMenuItemIcon<&bobbyicons::settings>>>();
|
||||||
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_BACK>, SwitchScreenAction<MainMenu>, StaticMenuItemIcon<&espgui::icons::back>>>();
|
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_BACK>, SwitchScreenAction<MainMenu>, StaticMenuItemIcon<&espgui::icons::back>>>();
|
||||||
}
|
}
|
||||||
@ -84,6 +96,13 @@ std::string BatteryMenu::text() const
|
|||||||
return TEXT_BATTERY;
|
return TEXT_BATTERY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void BatteryMenu::initScreen()
|
||||||
|
{
|
||||||
|
Base::initScreen();
|
||||||
|
m_batPercentBootLabel.start();
|
||||||
|
m_batPercentNowLabel.start();
|
||||||
|
}
|
||||||
|
|
||||||
void BatteryMenu::start()
|
void BatteryMenu::start()
|
||||||
{
|
{
|
||||||
Base::start();
|
Base::start();
|
||||||
@ -103,7 +122,16 @@ void BatteryMenu::redraw()
|
|||||||
|
|
||||||
const auto batPercent = getBatteryPercentage(avgVoltage, BatteryCellType(configs.battery.cellType.value));
|
const auto batPercent = getBatteryPercentage(avgVoltage, BatteryCellType(configs.battery.cellType.value));
|
||||||
if (battery::bootBatPercentage)
|
if (battery::bootBatPercentage)
|
||||||
|
{
|
||||||
m_doubleProgressBarBatPercentage.redraw(batPercent, *battery::bootBatPercentage);
|
m_doubleProgressBarBatPercentage.redraw(batPercent, *battery::bootBatPercentage);
|
||||||
|
|
||||||
|
tft.setTextFont(2);
|
||||||
|
tft.setTextColor(TFT_DARKGREY);
|
||||||
|
m_batPercentNowLabel.redraw(fmt::format("{:.2f} %", batPercent));
|
||||||
|
m_batPercentBootLabel.redraw(fmt::format("{:.2f} %", *battery::bootBatPercentage));
|
||||||
|
tft.setTextFont(4);
|
||||||
|
tft.setTextColor(TFT_WHITE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void BatteryMenu::back()
|
void BatteryMenu::back()
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
// local includes
|
// local includes
|
||||||
#include "displays/bobbymenudisplay.h"
|
#include "displays/bobbymenudisplay.h"
|
||||||
#include "widgets/doubleprogressbar.h"
|
#include "widgets/doubleprogressbar.h"
|
||||||
|
#include "widgets/label.h"
|
||||||
|
|
||||||
class BatteryMenu : public BobbyMenuDisplay
|
class BatteryMenu : public BobbyMenuDisplay
|
||||||
{
|
{
|
||||||
@ -13,10 +14,13 @@ public:
|
|||||||
|
|
||||||
std::string text() const override;
|
std::string text() const override;
|
||||||
|
|
||||||
|
void initScreen() override;
|
||||||
void start() override;
|
void start() override;
|
||||||
void redraw() override;
|
void redraw() override;
|
||||||
void back() override;
|
void back() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bobbygui::DoubleProgressBar m_doubleProgressBarBatPercentage{75, 68, 90, 24, 0, 100, TFT_RED, TFT_GREEN};
|
bobbygui::DoubleProgressBar m_doubleProgressBarBatPercentage{75, 68, 90, 24, 0, 100, TFT_RED, TFT_GREEN};
|
||||||
|
espgui::Label m_batPercentNowLabel {170, 67};
|
||||||
|
espgui::Label m_batPercentBootLabel{170, 83};
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user