Battery remaining time

gamescope-debug
FlightlessMango 2 years ago
parent a9f811a207
commit 39f6ae98ec

@ -33,6 +33,7 @@ void BatteryStats::update() {
if (batt_count > 0) {
current_watt = getPower();
current_percent = getPercent();
remaining_time = getTimeRemaining();
}
}
@ -40,7 +41,7 @@ float BatteryStats::getPercent()
{
float charge_n = 0;
float charge_f = 0;
for(int i =0; i < batt_count; i++) {
for(int i = 0; i < batt_count; i++) {
string syspath = battPath[i];
string charge_now = syspath + "/charge_now";
string charge_full = syspath + "/charge_full";
@ -89,7 +90,7 @@ float BatteryStats::getPercent()
float BatteryStats::getPower() {
float current = 0;
float voltage = 0;
for(int i =0; i < batt_count; i++) {
for(int i = 0; i < batt_count; i++) {
string syspath = battPath[i];
string current_power = syspath + "/current_now";
string current_voltage = syspath + "/voltage_now";
@ -130,4 +131,53 @@ float BatteryStats::getPower() {
return current * voltage;
}
float BatteryStats::getTimeRemaining(){
float current = 0;
float charge = 0;
for(int i = 0; i < batt_count; i++) {
string syspath = battPath[i];
string current_now = syspath + "/current_now";
string charge_now = syspath + "/charge_now";
string voltage_now = syspath + "/voltage_now";
string power_now = syspath + "/power_now";
if (fs::exists(current_now)) {
std::ifstream input(current_now);
std::string line;
if(std::getline(input, line)){
current_now_vec.push_back(stof(line));
}
} else if (fs::exists(power_now)){
float voltage = 0;
float power = 0;
std::ifstream input_power(power_now);
std::ifstream input_voltage(power_now);
std::string line;
if(std::getline(input_voltage, line)){
voltage = stof(line);
}
if(std::getline(input_power, line)){
power = stof(line);
}
current_now_vec.push_back(power / voltage);
}
if (fs::exists(charge_now)){
std::string line;
std::ifstream input(charge_now);
if(std::getline(input, line)){
charge += stof(line);
}
}
if (current_now_vec.size() > 25)
current_now_vec.erase(current_now_vec.begin());
}
for(auto& current_now : current_now_vec){
current += current_now;
}
current /= current_now_vec.size();
return charge / current;
}
BatteryStats Battery_Stats;

@ -7,14 +7,16 @@ class BatteryStats{
void update();
float getPower();
float getPercent();
float getTimeRemaining();
std::string battPath[2];
float current_watt = 0;
float current_percent = 0;
float remaining_time = 0;
std::string current_status;
std::string state [2];
int batt_count=0;
bool batt_check = false;
std::vector<float> current_now_vec = {};
};
extern BatteryStats Battery_Stats;

@ -729,6 +729,15 @@ void HudElements::battery(){
ImGui::PushFont(HUDElements.sw_stats->font1);
ImGui::Text("W");
ImGui::PopFont();
ImGui::TableNextRow(); ImGui::TableNextColumn(); ImGui::TableNextColumn(); ImGui::TableNextColumn();
float hours;
float minutes;
float seconds;
minutes = std::modf(Battery_Stats.remaining_time, &hours);
minutes *= 60;
seconds = std::modf(minutes, &minutes);
seconds *= 60;
right_aligned_text(HUDElements.colors.text, HUDElements.ralign_width, "%02.0f:%02.0f:%02.0f", hours, minutes, seconds);
}
}
}

Loading…
Cancel
Save