Add supporting of the gamepads batteries
This commit is contained in:
parent
8aee7492d4
commit
37d87be3c1
|
@ -154,6 +154,7 @@ const std::tuple<uint8_t, float, std::string, float> waybar::modules::Battery::g
|
|||
uint32_t total_energy = 0; // μWh
|
||||
uint32_t total_energy_full = 0;
|
||||
uint32_t total_energy_full_design = 0;
|
||||
uint32_t total_capacity{0};
|
||||
std::string status = "Unknown";
|
||||
for (auto const& item : batteries_) {
|
||||
auto bat = item.first;
|
||||
|
@ -161,6 +162,7 @@ const std::tuple<uint8_t, float, std::string, float> waybar::modules::Battery::g
|
|||
uint32_t energy_full;
|
||||
uint32_t energy_now;
|
||||
uint32_t energy_full_design;
|
||||
uint32_t capacity{0};
|
||||
std::string _status;
|
||||
std::getline(std::ifstream(bat / "status"), _status);
|
||||
|
||||
|
@ -188,11 +190,18 @@ const std::tuple<uint8_t, float, std::string, float> waybar::modules::Battery::g
|
|||
energy_now = ((uint64_t)charge_now * (uint64_t)voltage_now) / 1000000;
|
||||
energy_full = ((uint64_t)charge_full * (uint64_t)voltage_now) / 1000000;
|
||||
energy_full_design = ((uint64_t)charge_full_design * (uint64_t)voltage_now) / 1000000;
|
||||
} else {
|
||||
} // Gamepads such as PS Dualshock provide the only capacity
|
||||
else if (fs::exists(bat / "energy_now") && fs::exists(bat / "energy_full")) {
|
||||
std::ifstream(bat / "power_now") >> power_now;
|
||||
std::ifstream(bat / "energy_now") >> energy_now;
|
||||
std::ifstream(bat / "energy_full") >> energy_full;
|
||||
std::ifstream(bat / "energy_full_design") >> energy_full_design;
|
||||
} else {
|
||||
std::ifstream(bat / "capacity") >> capacity;
|
||||
power_now = 0;
|
||||
energy_now = 0;
|
||||
energy_full = 0;
|
||||
energy_full_design = 0;
|
||||
}
|
||||
|
||||
// Show the "smallest" status among all batteries
|
||||
|
@ -203,6 +212,7 @@ const std::tuple<uint8_t, float, std::string, float> waybar::modules::Battery::g
|
|||
total_energy += energy_now;
|
||||
total_energy_full += energy_full;
|
||||
total_energy_full_design += energy_full_design;
|
||||
total_capacity += capacity;
|
||||
}
|
||||
if (!adapter_.empty() && status == "Discharging") {
|
||||
bool online;
|
||||
|
@ -222,7 +232,12 @@ const std::tuple<uint8_t, float, std::string, float> waybar::modules::Battery::g
|
|||
time_remaining = 0.0f;
|
||||
}
|
||||
}
|
||||
float capacity = ((float)total_energy * 100.0f / (float) total_energy_full);
|
||||
float capacity{0.0f};
|
||||
if(total_energy_full > 0.0f) {
|
||||
capacity = ((float)total_energy * 100.0f / (float) total_energy_full);
|
||||
} else {
|
||||
capacity = (float)total_capacity;
|
||||
}
|
||||
// Handle design-capacity
|
||||
if (config_["design-capacity"].isBool() ? config_["design-capacity"].asBool() : false) {
|
||||
capacity = ((float)total_energy * 100.0f / (float) total_energy_full_design);
|
||||
|
|
Loading…
Reference in New Issue