* usr/lib/byobu/battery: LP: #851100

- rework the battery logic to use /sys instead of /proc
This commit is contained in:
Dustin Kirkland 2011-10-22 03:04:01 -05:00
commit e02be1f46a
2 changed files with 55 additions and 40 deletions

2
debian/changelog vendored
View file

@ -19,6 +19,8 @@ byobu (4.43) unreleased; urgency=low
* usr/lib/byobu/.dirs: * usr/lib/byobu/.dirs:
- use /dev/shm for cache, LP: #872551, #869279 - use /dev/shm for cache, LP: #872551, #869279
- search and use a shared dir when possible - search and use a shared dir when possible
* usr/lib/byobu/battery: LP: #851100
- rework the battery logic to use /sys instead of /proc
[ Daniel Hahler ] [ Daniel Hahler ]
* usr/bin/byobu, usr/bin/byobu-launcher-install, usr/bin/byobu- * usr/bin/byobu, usr/bin/byobu-launcher-install, usr/bin/byobu-

View file

@ -30,49 +30,62 @@ __battery_detail() {
__battery() { __battery() {
local bat line present sign state percent full rem color bcolor local bat line present sign state percent full rem color bcolor
for bat in $BATTERY /proc/acpi/battery/*; do for bat in $BATTERY /sys/class/power_supply/* /proc/acpi/battery/*; do
[ -f "$bat/info" ] || continue
present=""; full=""; rem=""; state="" present=""; full=""; rem=""; state=""
while read line; do case "$bat" in
set -- ${line} /sys/*)
case "$line" in if [ -r "$bat/uevent" ]; then
present:*) . "$bat/uevent"
# make sure that this battery is present present="$POWER_SUPPLY_PRESENT"
[ "$2" = "no" ] && continue 2 full="$POWER_SUPPLY_CHARGE_FULL"
present="$2";; rem="$POWER_SUPPLY_CHARGE_NOW"
last\ full\ capacity:*) full="$4";; state="$POWER_SUPPLY_STATUS"
esac [ -n "$present" ] && [ -n "$full" ] && [ -n "$rem" ] && [ "$state" ] && break
[ -n "$present" -a -n "$full" ] && break fi
done < "${bat}/info" ;;
while read line; do /proc/*)
set -- ${line} [ -f "$bat/info" ] || continue
case "$line" in while read line; do
remaining\ capacity:*) rem="$3";; set -- ${line}
charging\ state:*) state="$3";; case "$line" in
esac present:*)
[ -n "$rem" -a -n "$state" ] && break # make sure that this battery is present
done < "$bat/state" [ "$2" = "no" ] && continue 2
percent=$(((100*$rem)/$full)) present="$2";;
if [ "$percent" -lt 33 ]; then last\ full\ capacity:*) full="$4";;
color="R k" esac
bcolor="b R k" [ -n "$present" -a -n "$full" ] && break
elif [ "$percent" -lt 67 ]; then done < "${bat}/info"
color="Y k" while read line; do
bcolor="b Y k" set -- ${line}
else case "$line" in
color="G k" remaining\ capacity:*) rem="$3";;
bcolor="b G k" charging\ state:*) state="$3";;
fi esac
percent="$percent$PCT" [ -n "$rem" -a -n "$state" ] && break
case $state in done < "$bat/state"
charging) sign="+" ;; ;;
discharging) sign="-" ;;
charged) sign="="; percent="" ;;
*) sign="$state" ;;
esac esac
color $bcolor; printf "%s" "$percent"; color -; color $color; printf "%s" "$sign"; color --
break
done done
percent=$(((100*$rem)/$full))
if [ "$percent" -lt 33 ]; then
color="R k"
bcolor="b R k"
elif [ "$percent" -lt 67 ]; then
color="Y k"
bcolor="b Y k"
else
color="G k"
bcolor="b G k"
fi
percent="$percent$PCT"
case $state in
charging|Charging|Unknown) sign="+" ;;
discharging|Discharging) sign="-" ;;
charged|Unknown) sign="="; percent="" ;;
*) sign="$state" ;;
esac
color $bcolor; printf "%s" "$percent"; color -; color $color; printf "%s" "$sign"; color --
} }
# vi: syntax=sh ts=4 noexpandtab # vi: syntax=sh ts=4 noexpandtab