PDA

View Full Version : Acpi battery script


SoniX
18th January 2007, 04:18 PM
I made myself this battery script:

#!/bin/sh
# Using the script to change brigtness when going to battery mode
ACAD_BRIGHTNESS=21
BATT_BRIGHTNESS=5

# ac/battery event handler

status=`awk '/^state: / { print $2 }' /proc/acpi/ac_adapter/ADP1/state`

case $status in
"on-line")
logger "Changing brightness to ACAD level"
/usr/bin/smartdimmer --set=$ACAD_BRIGHTNESS
exit 0
;;
"off-line")
logger "Changing brightness to BATT level"
/usr/bin/smartdimmer --set=$BATT_BRIGHTNESS
exit 0
;;
esac

Placed it into /etc/acpi/actions and made it executable!

Made myself this conf file

# Battery configuration
# Written by SoniX

#event=battery.*
#action=/etc/acpi/actions/battery.sh

Placed it into /etc/acpi/events

Reloaded the acpid deamon but this doesn't seem to work... Any idea's?

SoniX
18th January 2007, 04:39 PM
NOTE: I Have a SONY VAIO VGN-FE21H

SoniX
19th January 2007, 10:00 AM

Found a solution, removed all the previous files, made this script:

#!/bin/sh
# Using the script to change brigtness when going to battery mode
# Made by SoniX
FILENAME="state"
ACAD_BRIGHTNESS=21
BATT_BRIGHTNESS=5

while [ true ]
do
# ac/battery event handler
status=`awk '/^state: / { print $2 }' /proc/acpi/ac_adapter/ADP1/state`

oldstatus=`cat $FILENAME`

case $oldstatus in
$status);;
*)
case $status in
"on-line")
/usr/bin/smartdimmer --set=$ACAD_BRIGHTNESS
echo $status > $FILENAME
;;
"off-line")
/usr/bin/smartdimmer --set=$BATT_BRIGHTNESS
echo $status > $FILENAME
;;
esac

echo $status > $FILENAME

sleep 1
;;
esac
done

Put it somewhere and make gnome run this script in the background when starting a session

baschti
19th January 2007, 11:15 AM
hi SoniX,

i guess you script needs to much cpu time, 'cause of the while true statement - sure you have a sleep call, but it's better to use the event based approach
your config file isn't working because you commented out the interesting stuff
so it should look like:# Battery configuration
# Written by SoniX

event=battery.*
action=/etc/acpi/actions/battery.sh

SoniX
19th January 2007, 03:42 PM
STUPID ME!

Now ok, I will chance it to work with acpi, it's indeed much better. But the second script I wrote doesn't take so much cpu power. I don't see a difference, neither with "top" or an applet...

nosnahoj
19th January 2007, 03:52 PM
Why dont you just do two events. One that activates when going from battery to ac (event=ac_adapter) and one from ac to battery (event=battery.*).

SoniX
19th January 2007, 05:13 PM
I don't know why you should need 2 events... Everything works fine now after uncommenting those 2 lines. But I had to add /etc/acpi/actions/battery.sh to the gnome sessions. Otherwise when restarting it won't apply... Now everything works fine :)

nosnahoj
19th January 2007, 05:37 PM
I thought this was a bit simpler:

event=battery.*
action=/usr/bin/smartdimmer --set=5

event=ac_adapter
action=/usr/bin/smartdimmer --set=21

SoniX
19th January 2007, 07:05 PM
I thought this was a bit simpler:

event=battery.*
action=/usr/bin/smartdimmer --set=5

event=ac_adapter
action=/usr/bin/smartdimmer --set=21

True, but I wan't to add more options, like getting the cpu level down, slowing fans, ... This was just a start :-)

EDIT
I don't think it will work, 'cause the battery event is trigerred when pluging and unpluging the power cable...

nosnahoj
19th January 2007, 07:52 PM
Oh, my bad.. i forgot that..
Try this, Its nice if you want your hd to spin down:
http://dries.ulyssis.org/rpm/packages/laptop-mode-tools/info.html