add an option to use battery design capacity as a reference for percentage informations

This commit is contained in:
ocisra 2021-01-03 15:25:19 +01:00
parent 7b7edc9029
commit 00046d309d
2 changed files with 15 additions and 1 deletions

View File

@ -22,6 +22,11 @@ The *battery* module displays the current capacity and state (eg. charging) of y
typeof: integer ++
Define the max percentage of the battery, for when you've set the battery to stop charging at a lower level to save it. For example, if you've set the battery to stop at 80% that will become the new 100%.
*design-capacity*: ++
typeof: bool ++
default: false ++
Option to use the battery design capacity instead of it's current maximal capacity.
*interval*: ++
typeof: integer ++
default: 60 ++

View File

@ -142,12 +142,14 @@ const std::tuple<uint8_t, float, std::string> waybar::modules::Battery::getInfos
uint32_t total_power = 0; // μW
uint32_t total_energy = 0; // μWh
uint32_t total_energy_full = 0;
uint32_t total_energy_full_design = 0;
std::string status = "Unknown";
for (auto const& item : batteries_) {
auto bat = item.first;
uint32_t power_now;
uint32_t energy_full;
uint32_t energy_now;
uint32_t energy_full_design;
std::string _status;
std::ifstream(bat / "status") >> _status;
auto rate_path = fs::exists(bat / "current_now") ? "current_now" : "power_now";
@ -156,12 +158,15 @@ const std::tuple<uint8_t, float, std::string> waybar::modules::Battery::getInfos
std::ifstream(bat / now_path) >> energy_now;
auto full_path = fs::exists(bat / "charge_full") ? "charge_full" : "energy_full";
std::ifstream(bat / full_path) >> energy_full;
auto full_design_path = fs::exists(bat / "charge_full_design") ? "charge_full_design" : "energy_full_design";
std::ifstream(bat / full_design_path) >> energy_full_design;
if (_status != "Unknown") {
status = _status;
}
total_power += power_now;
total_energy += energy_now;
total_energy_full += energy_full;
total_energy_full_design += energy_full_design;
}
if (!adapter_.empty() && status == "Discharging") {
bool online;
@ -182,6 +187,10 @@ const std::tuple<uint8_t, float, std::string> waybar::modules::Battery::getInfos
}
}
float capacity = ((float)total_energy * 100.0f / (float) total_energy_full);
// Handle design-capacity
if (config_["design-capacity"].isBool() ? config_["design-capacity"].asBool() : false) {
capacity = ((float)total_energy * 100.0f / (float) total_energy_full_design);
}
// Handle full-at
if (config_["full-at"].isUInt()) {
auto full_at = config_["full-at"].asUInt();