sxmo: battery_estimate: improve edge cases
This commit is contained in:
parent
6d216c14fa
commit
e7d5b14ab0
|
@ -10,22 +10,23 @@ bat_dis=""
|
||||||
bat_chg=""
|
bat_chg=""
|
||||||
|
|
||||||
fmt_minutes() {
|
fmt_minutes() {
|
||||||
if [[ $2 -gt 1440 ]]; then
|
# args: <battery symbol> <text if ludicrous estimate> <estimated minutes to full/empty>
|
||||||
echo "∞" # more than 1d
|
if [[ $3 -gt 1440 ]]; then
|
||||||
|
printf "%s %s" "$1" "$2" # more than 1d
|
||||||
else
|
else
|
||||||
hr=$(($2 / 60))
|
hr=$(($3 / 60))
|
||||||
hr_in_min=$(($hr * 60))
|
hr_in_min=$(($hr * 60))
|
||||||
min=$(($2 - $hr_in_min))
|
min=$(($3 - $hr_in_min))
|
||||||
printf "%s %dh%02dm" "$1" "$hr" "$min"
|
printf "%s %dh%02dm" "$1" "$hr" "$min"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
if [[ $rate -lt 0 ]]; then
|
if [[ $rate -lt 0 ]]; then
|
||||||
# discharging
|
# discharging
|
||||||
fmt_minutes "$bat_dis" $(($full * 60 * $perc / (-100 * $rate)))
|
fmt_minutes "$bat_dis" '∞' "$(($full * 60 * $perc / (-100 * $rate)))"
|
||||||
elif [[ $rate -gt 0 ]]; then
|
elif [[ $rate -gt 0 ]]; then
|
||||||
# charging
|
# charging
|
||||||
fmt_minutes "$bat_chg" $(($full * 60 * $perc_left / (100 * $rate)))
|
fmt_minutes "$bat_chg" '100%' "$(($full * 60 * $perc_left / (100 * $rate)))"
|
||||||
else
|
else
|
||||||
echo " N/A"
|
echo "$bat_dis $perc%"
|
||||||
fi
|
fi
|
||||||
|
|
Loading…
Reference in New Issue
Block a user