From bad6cfae6f638b166d55ad543050c69286038840 Mon Sep 17 00:00:00 2001 From: Bruce Blore Date: Sat, 22 Apr 2023 23:43:04 -0700 Subject: [PATCH] Added option to calculate battery percentage as total_energy * 100 / total_energy_full --- src/modules/battery.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/modules/battery.cpp b/src/modules/battery.cpp index abd1240c..83e7398c 100644 --- a/src/modules/battery.cpp +++ b/src/modules/battery.cpp @@ -533,6 +533,13 @@ const std::tuple 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) {