|
|
|
@ -33,6 +33,7 @@ void BatteryStats::update() {
|
|
|
|
|
if (batt_count > 0) {
|
|
|
|
|
current_watt = getPower();
|
|
|
|
|
current_percent = getPercent();
|
|
|
|
|
remaining_time = getTimeRemaining();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -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;
|
|
|
|
|