From 08f5f444eb91006a2d457e12b9860d45b5117a3c Mon Sep 17 00:00:00 2001 From: David Bimmler Date: Fri, 7 Jul 2023 11:20:36 +0200 Subject: [PATCH] battery: correct time_to_empty calculation The kernel docs state that time_to_empty contains the estimation of remaining time in seconds. Hence, calculate estimate minutes and hours from that in a more correct way. Signed-off-by: David Bimmler --- CHANGELOG.md | 1 + modules/battery.c | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 48373d6..cd36c33 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -52,6 +52,7 @@ * pipewire: use roundf instead of ceilf for more accuracy ([#262][262]) * Crash when a yaml anchor has a value to already exists in the target yaml node ([#286][286]). +* battery: Fix time conversion in battery estimation ([#303][303]). [239]: https://codeberg.org/dnkl/yambar/issues/239 [241]: https://codeberg.org/dnkl/yambar/issues/241 diff --git a/modules/battery.c b/modules/battery.c index db00add..2b04d65 100644 --- a/modules/battery.c +++ b/modules/battery.c @@ -86,8 +86,9 @@ content(struct module *mod) unsigned long minutes; if (m->time_to_empty >= 0) { - hours = m->time_to_empty / 60; - minutes = m->time_to_empty % 60; + minutes = m->time_to_empty / 60; + hours = minutes / 60; + minutes = minutes % 60; } else if (m->energy_full >= 0 && m->charge && m->power >= 0) { unsigned long energy = m->state == STATE_CHARGING ? m->energy_full - m->energy : m->energy;