From e7d5b14ab0c118a99bbef0d39b6d7b3dd40b1a6a Mon Sep 17 00:00:00 2001 From: Colin Date: Fri, 21 Jul 2023 22:51:24 +0000 Subject: [PATCH] sxmo: battery_estimate: improve edge cases --- hosts/modules/gui/sxmo/battery_estimate | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/hosts/modules/gui/sxmo/battery_estimate b/hosts/modules/gui/sxmo/battery_estimate index 8183354e..59a6f933 100755 --- a/hosts/modules/gui/sxmo/battery_estimate +++ b/hosts/modules/gui/sxmo/battery_estimate @@ -10,22 +10,23 @@ bat_dis="󱊢" bat_chg="󱊥" fmt_minutes() { - if [[ $2 -gt 1440 ]]; then - echo "∞" # more than 1d + # args: + if [[ $3 -gt 1440 ]]; then + printf "%s %s" "$1" "$2" # more than 1d else - hr=$(($2 / 60)) + hr=$(($3 / 60)) hr_in_min=$(($hr * 60)) - min=$(($2 - $hr_in_min)) + min=$(($3 - $hr_in_min)) printf "%s %dh%02dm" "$1" "$hr" "$min" fi } if [[ $rate -lt 0 ]]; then # discharging - fmt_minutes "$bat_dis" $(($full * 60 * $perc / (-100 * $rate))) + fmt_minutes "$bat_dis" '∞' "$(($full * 60 * $perc / (-100 * $rate)))" elif [[ $rate -gt 0 ]]; then # charging - fmt_minutes "$bat_chg" $(($full * 60 * $perc_left / (100 * $rate))) + fmt_minutes "$bat_chg" '100%' "$(($full * 60 * $perc_left / (100 * $rate)))" else - echo "󱊢 N/A" + echo "$bat_dis $perc%" fi