]> git.pld-linux.org Git - packages/acpid.git/commitdiff
- formatting/author
authorhavner <havner@pld-linux.org>
Mon, 14 Aug 2006 21:32:18 +0000 (21:32 +0000)
committercvs2git <feedback@pld-linux.org>
Sun, 24 Jun 2012 12:13:13 +0000 (12:13 +0000)
- battery support

Changed files:
    acpid.battery.conf -> 1.2
    acpid.battery.sh -> 1.3

acpid.battery.conf
acpid.battery.sh

index 84f2bc52ef3e954d724637190f0fb30a8e10e698..8cd113fda05d9035953c40bd73e69658e7d65da3 100644 (file)
@@ -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 13eb5ff58bec27b56c6c56c9b1eeef6310481f3e..3dc55d78272c151ccd347dccbddb84cf61749124 100644 (file)
@@ -1,39 +1,83 @@
 #!/bin/sh
 # /etc/acpid/actions/battery.sh
 # based on work by Frank Dietrich <ablesoft@gmx.de>
+# £ukasz Pawelczyk <havner@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
This page took 0.097938 seconds and 4 git commands to generate.