Added new Battery Percentage String
This commit is contained in:
@@ -112,12 +112,7 @@ float getBatteryPercentage(float batVoltage, BatteryCellType cellType)
|
|||||||
|
|
||||||
float getRemainingWattHours()
|
float getRemainingWattHours()
|
||||||
{
|
{
|
||||||
float target_mah = 2000; //default
|
float target_mah = getTarget_mAh();
|
||||||
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 avgVoltage = 0;
|
float avgVoltage = 0;
|
||||||
for (auto &controller : controllers)
|
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);
|
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()
|
std::string getBatteryPercentageString()
|
||||||
{
|
{
|
||||||
float avgVoltage = 0;
|
float avgVoltage = 0;
|
||||||
@@ -142,6 +154,12 @@ std::string getBatteryPercentageString()
|
|||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string getBatteryAdvancedPercentageString()
|
||||||
|
{
|
||||||
|
std::string output = fmt::format("Battery: {:.1f}%", getPercentageByWh(drivingStatistics.batteryWhEstimate));
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
std::string getBatteryRemainingWattHoursString()
|
std::string getBatteryRemainingWattHoursString()
|
||||||
{
|
{
|
||||||
return fmt::format("{:.1f}Wh", getRemainingWattHours());
|
return fmt::format("{:.1f}Wh", getRemainingWattHours());
|
||||||
|
@@ -29,3 +29,8 @@ std::string getBatteryCellTypeString();
|
|||||||
std::string getRemainingRangeString();
|
std::string getRemainingRangeString();
|
||||||
|
|
||||||
std::string getBatteryDebugString();
|
std::string getBatteryDebugString();
|
||||||
|
|
||||||
|
std::string getBatteryAdvancedPercentageString();
|
||||||
|
|
||||||
|
float getPercentageByWh(float wh);
|
||||||
|
float getTarget_mAh();
|
||||||
|
@@ -6,6 +6,7 @@
|
|||||||
#include "fmt/core.h"
|
#include "fmt/core.h"
|
||||||
|
|
||||||
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 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 BatteryDebugText : public virtual espgui::TextInterface { public: std::string text() const override { return getBatteryDebugString(); } };
|
||||||
class BatteryDebug2Text : public virtual espgui::TextInterface {
|
class BatteryDebug2Text : public virtual espgui::TextInterface {
|
||||||
@@ -33,6 +34,7 @@ BatteryDebugMenu::BatteryDebugMenu()
|
|||||||
constructMenuItem<makeComponent<MenuItem, BatteryDebugText, DisabledColor, DummyAction>>();
|
constructMenuItem<makeComponent<MenuItem, BatteryDebugText, DisabledColor, DummyAction>>();
|
||||||
constructMenuItem<makeComponent<MenuItem, BatteryDebug2Text, DisabledColor, DummyAction>>();
|
constructMenuItem<makeComponent<MenuItem, BatteryDebug2Text, DisabledColor, DummyAction>>();
|
||||||
constructMenuItem<makeComponent<MenuItem, BatteryDebug3Text, 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>>>();
|
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_BACK>, SwitchScreenAction<DebugMenu>, StaticMenuItemIcon<&espgui::icons::back>>>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user