Merge pull request #2134 from bruceblore/battery-weighted-percentage

Display battery percentage as weighted average of battery levels
This commit is contained in:
Alexis Rouillard 2023-09-04 22:01:40 +02:00 committed by GitHub
commit 6f66af9ab9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 0 deletions

View File

@ -534,6 +534,13 @@ const std::tuple<uint8_t, float, std::string, float> waybar::modules::Battery::g
}
}
// Handle weighted-average
if ((config_["weighted-average"].isBool() ? config_["weighted-average"].asBool() : false) &&
total_energy_exists && total_energy_full_exists) {
if (total_energy_full > 0.0f)
calculated_capacity = ((float)total_energy * 100.0f / (float)total_energy_full);
}
// Handle design-capacity
if ((config_["design-capacity"].isBool() ? config_["design-capacity"].asBool() : false) &&
total_energy_exists && total_energy_full_design_exists) {