X-Git-Url: https://git.sthu.org/?p=shutils.git;a=blobdiff_plain;f=dotfiles%2Fconky%2Fbatteryinfo.sh;fp=dotfiles%2Fconky%2Fbatteryinfo.sh;h=6dcc3a632e289b055395c1ae5a4f8b3dd7a6f815;hp=0000000000000000000000000000000000000000;hb=e5a6e77d71096cff4b5d1f4b39b76154842af40f;hpb=aed683d1d5066a1ecfa529973bb887b08dfcb893 diff --git a/dotfiles/conky/batteryinfo.sh b/dotfiles/conky/batteryinfo.sh new file mode 100755 index 0000000..6dcc3a6 --- /dev/null +++ b/dotfiles/conky/batteryinfo.sh @@ -0,0 +1,59 @@ +#!/bin/dash +# +# Stefan Huber +# Display battery info for conky + + + +if [ -e /sys/devices/platform/smapi/ ] +then + for b in `find /sys/devices/platform/smapi/ -type d -name BAT?` + do + if [ `cat $b/installed` = "1" ] + then + name=${b##*/} + remcap=`cat $b/remaining_capacity` + remcapper=`cat $b/remaining_percent` + ratenow=`cat $b/power_now` + rateavg=`cat $b/power_avg` + remtime=`cat $b/remaining_running_time` + tempmilli=`cat $b/temperature` + temp=`echo "$tempmilli/1000" | bc` + + if [ "$remtime" = "not_discharging" ]; then + remtime=`cat $b/remaining_charging_time` + fi + if [ "$remtime" = "not_charging" ]; then + remtime="--" + fi + + echo "$name rate: $ratenow mW [~ $rateavg mW]" + echo "rem: $remcap mWh [$remcapper%, $remtime min]" + #echo "$name temp: $temp°C" + fi + done +else + for b in `find /proc/acpi/battery/ -type d -name BAT?` + do + if [ `grep -c -E "^present: *yes" $b/state` = "1" ] + then + name=${b##*/} + fullcap=`grep "last full capacity" $b/info | awk ' { print $4 } '` + remcap=`grep "remaining capacity" $b/state | awk ' { print $3 } '` + rate=`grep "present rate" $b/state | awk ' { print $3 } '` + + if [ $rate = "0" ]; then + remtime="--" + else + remtime=`echo "$remcap*60/$rate" | bc` + fi + + remcapper=`echo "$remcap*100/$fullcap" | bc ` + + echo "$name rate: $rate mW" + echo "$name rem.: $remcap mWh [$remcapper%, $remtime min]" + fi + done +fi + +