Added new Battery Percentage String

This commit is contained in:
CommanderRedYT
2021-11-18 01:13:16 +01:00
parent cd669c03aa
commit a6651c1cd1
3 changed files with 31 additions and 6 deletions

View File

@ -112,12 +112,7 @@ float getBatteryPercentage(float batVoltage, BatteryCellType cellType)
float getRemainingWattHours()
{
float target_mah = 2000; //default
if(BatteryCellType(settings.battery.cellType) == BatteryCellType::_22P) target_mah = 2200;
if(BatteryCellType(settings.battery.cellType) == BatteryCellType::HG2) target_mah = 3000;
if(BatteryCellType(settings.battery.cellType) == BatteryCellType::MH1) target_mah = 3200;
if(BatteryCellType(settings.battery.cellType) == BatteryCellType::VTC5) target_mah = 2600;
if(BatteryCellType(settings.battery.cellType) == BatteryCellType::BAK_25R) target_mah = 2500;
float target_mah = getTarget_mAh();
float avgVoltage = 0;
for (auto &controller : controllers)
@ -129,6 +124,23 @@ float getRemainingWattHours()
return (target_mah / 1000.f) * 3.7 * settings.battery.cellsParallel * settings.battery.cellsSeries * (getBatteryPercentage(avgVoltage, BatteryCellType(settings.battery.cellType)) / 100);
}
float getPercentageByWh(float wh)
{
const float maxWh = (getTarget_mAh() / 1000.f) * 3.7 * settings.battery.cellsParallel * settings.battery.cellsSeries;
return maxWh / wh;
}
float getTarget_mAh()
{
float target_mah = 2000; //default
if(BatteryCellType(settings.battery.cellType) == BatteryCellType::_22P) target_mah = 2200;
if(BatteryCellType(settings.battery.cellType) == BatteryCellType::HG2) target_mah = 3000;
if(BatteryCellType(settings.battery.cellType) == BatteryCellType::MH1) target_mah = 3200;
if(BatteryCellType(settings.battery.cellType) == BatteryCellType::VTC5) target_mah = 2600;
if(BatteryCellType(settings.battery.cellType) == BatteryCellType::BAK_25R) target_mah = 2500;
return target_mah;
}
std::string getBatteryPercentageString()
{
float avgVoltage = 0;
@ -142,6 +154,12 @@ std::string getBatteryPercentageString()
return output;
}
std::string getBatteryAdvancedPercentageString()
{
std::string output = fmt::format("Battery: {:.1f}%", getPercentageByWh(drivingStatistics.batteryWhEstimate));
return output;
}
std::string getBatteryRemainingWattHoursString()
{
return fmt::format("{:.1f}Wh", getRemainingWattHours());

View File

@ -29,3 +29,8 @@ std::string getBatteryCellTypeString();
std::string getRemainingRangeString();
std::string getBatteryDebugString();
std::string getBatteryAdvancedPercentageString();
float getPercentageByWh(float wh);
float getTarget_mAh();

View File

@ -6,6 +6,7 @@
#include "fmt/core.h"
class CurrentBatteryStatusText : public virtual espgui::TextInterface { public: std::string text() const override { return getBatteryPercentageString(); } };
class CurrentAdvancedBatteryPercentage : public virtual espgui::TextInterface { public: std::string text() const override { return getBatteryAdvancedPercentageString(); } };
class BatteryDebugText : public virtual espgui::TextInterface { public: std::string text() const override { return getBatteryDebugString(); } };
class BatteryDebug2Text : public virtual espgui::TextInterface {
@ -33,6 +34,7 @@ BatteryDebugMenu::BatteryDebugMenu()
constructMenuItem<makeComponent<MenuItem, BatteryDebugText, DisabledColor, DummyAction>>();
constructMenuItem<makeComponent<MenuItem, BatteryDebug2Text, DisabledColor, DummyAction>>();
constructMenuItem<makeComponent<MenuItem, BatteryDebug3Text, DisabledColor, DummyAction>>();
constructMenuItem<makeComponent<MenuItem, BatteryDebug3Text, CurrentAdvancedBatteryPercentage, DummyAction>>();
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_BACK>, SwitchScreenAction<DebugMenu>, StaticMenuItemIcon<&espgui::icons::back>>>();
}