SOURCES: acpid.battery.conf, acpid.battery.sh - formatting/author ...
havner
havner at pld-linux.org
Mon Aug 14 23:32:24 CEST 2006
Author: havner Date: Mon Aug 14 21:32:24 2006 GMT
Module: SOURCES Tag: HEAD
---- Log message:
- formatting/author
- battery support
---- Files affected:
SOURCES:
acpid.battery.conf (1.1 -> 1.2) , acpid.battery.sh (1.2 -> 1.3)
---- Diffs:
================================================================
Index: SOURCES/acpid.battery.conf
diff -u SOURCES/acpid.battery.conf:1.1 SOURCES/acpid.battery.conf:1.2
--- SOURCES/acpid.battery.conf:1.1 Sat Jul 22 19:33:29 2006
+++ SOURCES/acpid.battery.conf Mon Aug 14 23:32:18 2006
@@ -1,5 +1,5 @@
# /etc/acpid/events/battery
-# This detects changes to AC connector status, and passes them to
+# This detects power related events and passes them to
# /etc/acpi/actions/battery.sh for further processing.
event=battery
================================================================
Index: SOURCES/acpid.battery.sh
diff -u SOURCES/acpid.battery.sh:1.2 SOURCES/acpid.battery.sh:1.3
--- SOURCES/acpid.battery.sh:1.2 Thu Aug 10 02:04:00 2006
+++ SOURCES/acpid.battery.sh Mon Aug 14 23:32:18 2006
@@ -1,39 +1,83 @@
#!/bin/sh
# /etc/acpid/actions/battery.sh
# based on work by Frank Dietrich <ablesoft at gmx.de>
+# Łukasz Pawelczyk <havner at pld-linux.org>
#
-# Detect AC connector plugged in or unplugged and take appropriate actions.
+# Handle power related events and take appropriate actions.
if [ $# != 1 ]; then
exit 1
fi
set $*
-# get the AC connector state from /proc filesystem.
-STATE=`sed -n 's/^.*\(off\|on\)-line.*/\1/p' /proc/acpi/ac_adapter/AC/state`
+AC=/proc/acpi/ac_adapter/AC
+BAT=/proc/acpi/battery/BAT0
-case "$STATE" in
- on)
- # AC connector plugged in
- logger "acpid: AC connector plugged in."
- # deactivate standby (spindown) timeout for the drive
- #hdparm -q -S 0 /dev/hda
- # handle processor
- #echo 0 > /proc/acpi/processor/CPU0/throttling
- #echo 0 > /proc/acpi/processor/CPU0/performance
- ;;
- off)
- # AC connector unplugged
- logger "acpid: AC connector unplugged."
- # activate standby (spindown) timeout for the drive
- # timeout 5 minutes (man hdparm, for more informations)
- #hdparm -q -S 60 /dev/hda
- # handle processor
- #echo 4 > /proc/acpi/processor/CPU0/throttling
- #echo 3 > /proc/acpi/processor/CPU0/performance
- ;;
- *)
- # AC connector in undetermined state
- logger "acpid: Could not determine new AC connector state."
- ;;
+# get the AC connector state (plugged/unplugged) from /proc filesystem.
+AC_STATE=`sed -n 's/^.*\(off\|on\)-line.*/\1/p' $AC/state`
+
+# get the battery state from /proc filesystem
+BAT_CAPACITY=`awk '/^remaining\ capacity:/ {print $3}' $BAT/state`
+BAT_WARNING=`awk '/^alarm:/ {print $2}' $BAT/alarm`
+BAT_CRITICAL=`awk '/^design\ capacity\ low:/ {print $4}' $BAT/info`
+if [ "$BAT_CAPACITY" -le "$((BAT_CRITICAL+200))" -a "$AC_STATE" = "off" ]; then
+ BAT_STATE=critical
+elif [ "$BAT_CAPACITY" -le "$((BAT_WARNING+200))" -a "$AC_STATE" = "off" ]; then
+ BAT_STATE=warning
+else
+ BAT_STATE=normal
+fi
+
+case "$AC_STATE" in
+ on)
+ # AC connector plugged in
+ logger "acpid: `basename $AC` connector plugged in."
+ # deactivate standby (spindown) timeout for the drive
+ #hdparm -q -S 0 /dev/hda
+ # handle processor
+ #echo 0 > /proc/acpi/processor/CPU0/throttling
+ #echo 0 > /proc/acpi/processor/CPU0/performance
+ ;;
+ off)
+ # AC connector unplugged
+ logger "acpid: `basename $AC` connector unplugged."
+ # activate standby (spindown) timeout for the drive
+ # timeout 5 minutes (man hdparm, for more informations)
+ #hdparm -q -S 60 /dev/hda
+ # handle processor
+ #echo 4 > /proc/acpi/processor/CPU0/throttling
+ #echo 3 > /proc/acpi/processor/CPU0/performance
+ ;;
+ *)
+ # AC connector in undetermined state
+ logger "acpid: Could not determine new `basename $AC` connector state."
+ ;;
+esac
+
+case "$BAT_STATE" in
+ warning)
+ # battery passed acpi alarm state and AC unplugged
+ logger "acpid: Remaining `basename $BAT` battery capacity low"
+ # play alarm sound
+ #play /path_to/alarm.wav
+ # put computer to sleep
+ #echo mem > /sys/power/state
+ #hibernate
+ ;;
+ critical)
+ # some laptops generate acpi event when machine is about to turn off
+ logger "acpid: Remaining `basename $BAT` battery capacity VERY low"
+ # play alarm sound
+ #play /path_to/alarm.wav
+ # put computer to sleep
+ #echo mem > /sys/power/state
+ #hibernate
+ ;;
+ normal)
+ # either battery is charged or AC plugged
+ ;;
+ *)
+ # battery in undetermined state
+ logger "acpid: Could not determine `basename $BAT` battery state"
+ ;;
esac
================================================================
---- CVS-web:
http://cvs.pld-linux.org/SOURCES/acpid.battery.conf?r1=1.1&r2=1.2&f=u
http://cvs.pld-linux.org/SOURCES/acpid.battery.sh?r1=1.2&r2=1.3&f=u
More information about the pld-cvs-commit
mailing list