From e02be1f46a7fe7e740fc8486d5363150d8a8bf4e Mon Sep 17 00:00:00 2001 From: Dustin Kirkland Date: Sat, 22 Oct 2011 03:04:01 -0500 Subject: [PATCH] * usr/lib/byobu/battery: LP: #851100 - rework the battery logic to use /sys instead of /proc --- debian/changelog | 2 + usr/lib/byobu/battery | 93 ++++++++++++++++++++++++------------------- 2 files changed, 55 insertions(+), 40 deletions(-) diff --git a/debian/changelog b/debian/changelog index f1dede20..b1f203cc 100644 --- a/debian/changelog +++ b/debian/changelog @@ -19,6 +19,8 @@ byobu (4.43) unreleased; urgency=low * usr/lib/byobu/.dirs: - use /dev/shm for cache, LP: #872551, #869279 - 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 ] * usr/bin/byobu, usr/bin/byobu-launcher-install, usr/bin/byobu- diff --git a/usr/lib/byobu/battery b/usr/lib/byobu/battery index ac38725a..ee930d71 100755 --- a/usr/lib/byobu/battery +++ b/usr/lib/byobu/battery @@ -30,49 +30,62 @@ __battery_detail() { __battery() { local bat line present sign state percent full rem color bcolor - for bat in $BATTERY /proc/acpi/battery/*; do - [ -f "$bat/info" ] || continue + for bat in $BATTERY /sys/class/power_supply/* /proc/acpi/battery/*; do present=""; full=""; rem=""; state="" - while read line; do - set -- ${line} - case "$line" in - present:*) - # make sure that this battery is present - [ "$2" = "no" ] && continue 2 - present="$2";; - last\ full\ capacity:*) full="$4";; - esac - [ -n "$present" -a -n "$full" ] && break - done < "${bat}/info" - while read line; do - set -- ${line} - case "$line" in - remaining\ capacity:*) rem="$3";; - charging\ state:*) state="$3";; - esac - [ -n "$rem" -a -n "$state" ] && break - done < "$bat/state" - 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) sign="+" ;; - discharging) sign="-" ;; - charged) sign="="; percent="" ;; - *) sign="$state" ;; + case "$bat" in + /sys/*) + if [ -r "$bat/uevent" ]; then + . "$bat/uevent" + present="$POWER_SUPPLY_PRESENT" + full="$POWER_SUPPLY_CHARGE_FULL" + rem="$POWER_SUPPLY_CHARGE_NOW" + state="$POWER_SUPPLY_STATUS" + [ -n "$present" ] && [ -n "$full" ] && [ -n "$rem" ] && [ "$state" ] && break + fi + ;; + /proc/*) + [ -f "$bat/info" ] || continue + while read line; do + set -- ${line} + case "$line" in + present:*) + # make sure that this battery is present + [ "$2" = "no" ] && continue 2 + present="$2";; + last\ full\ capacity:*) full="$4";; + esac + [ -n "$present" -a -n "$full" ] && break + done < "${bat}/info" + while read line; do + set -- ${line} + case "$line" in + remaining\ capacity:*) rem="$3";; + charging\ state:*) state="$3";; + esac + [ -n "$rem" -a -n "$state" ] && break + done < "$bat/state" + ;; esac - color $bcolor; printf "%s" "$percent"; color -; color $color; printf "%s" "$sign"; color -- - break 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