Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
[SCRIPT]s to handle ACPI events (incl. laptop-mode)
View unanswered posts
View posts from last 24 hours

Goto page Previous  1, 2, 3  Next  
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message
hulk2nd
Guru
Guru


Joined: 25 Mar 2003
Posts: 512
Location: Freiburg, Germany

PostPosted: Fri Dec 12, 2003 1:36 am    Post subject: Reply with quote

check the patch at the beginning:

LID_STATE=/proc/acpi/button/lid/LID/state

for example in my case it is LID0 instead of LID.

greets,
hulk
Back to top
View user's profile Send private message
bdraw
n00b
n00b


Joined: 24 Nov 2003
Posts: 21
Location: Tampa

PostPosted: Fri Dec 12, 2003 7:14 pm    Post subject: Reply with quote

hulk2nd wrote:
check the patch at the beginning:

LID_STATE=/proc/acpi/button/lid/LID/state

for example in my case it is LID0 instead of LID.


Thanks for the sugestion.
The path is set correctly, and I can tell the IF statment is true because the event gets loged.
I switched to metalog and it seems there is more information that might help.
This is from /var/log/acpi
Code:

[Fri Dec 12 14:08:42 2003] received event "button/lid LID 00000080 00000003"
[Fri Dec 12 14:08:42 2003] executing action "/etc/acpi/default.sh button/lid LID 00000080 00000003"
[Fri Dec 12 14:08:42 2003] BEGIN HANDLER MESSAGES
[Fri Dec 12 14:08:42 2003] END HANDLER MESSAGES
[Fri Dec 12 14:08:42 2003] action exited with status 0
[Fri Dec 12 14:08:42 2003] executing action "/etc/acpi/action.sh button/lid LID 00000080 00000003"
[Fri Dec 12 14:08:42 2003] BEGIN HANDLER MESSAGES
#### NO ACTION FOR EVENT:
[Fri Dec 12 14:08:42 2003] END HANDLER MESSAGES
[Fri Dec 12 14:08:42 2003] action exited with status 1
[Fri Dec 12 14:08:42 2003] completed event "button/lid LID 00000080 00000003"
[Fri Dec 12 14:08:46 2003] received event "button/lid LID 00000080 00000004"
[Fri Dec 12 14:08:46 2003] executing action "/etc/acpi/default.sh button/lid LID 00000080 00000004"
[Fri Dec 12 14:08:46 2003] BEGIN HANDLER MESSAGES
[Fri Dec 12 14:08:46 2003] END HANDLER MESSAGES
[Fri Dec 12 14:08:46 2003] action exited with status 0
[Fri Dec 12 14:08:46 2003] executing action "/etc/acpi/action.sh button/lid LID 00000080 00000004"
[Fri Dec 12 14:08:46 2003] BEGIN HANDLER MESSAGES
#### NO ACTION FOR EVENT:
[Fri Dec 12 14:08:46 2003] END HANDLER MESSAGES
[Fri Dec 12 14:08:46 2003] action exited with status 1
[Fri Dec 12 14:08:46 2003] completed event "button/lid LID 00000080 00000004"

_________________
If it's too easy it's boring.
Ben
Back to top
View user's profile Send private message
friday
n00b
n00b


Joined: 07 Feb 2003
Posts: 28
Location: Germany

PostPosted: Sun Dec 21, 2003 7:41 pm    Post subject: Reply with quote

bdraw, it seems you have messed up the script somehow.
Otherwise it wouldn't echo the "#### no action..." stuff to /var/log/acpi.

Have you changed the order within the case ... esac switch?
Back to top
View user's profile Send private message
b0fh
Guru
Guru


Joined: 16 Jun 2003
Posts: 426

PostPosted: Mon Dec 22, 2003 10:23 am    Post subject: Reply with quote

I'd like to put my Thinkpad T23 into sleep-mode when lid is closed. This worked properly and without acpid in kernel version < 2.6.0-test10. But in 2.6.0 it only enters sleep-mode when I pass acpi=off at bootup... Very strange. Any ideas how to fix this?
Back to top
View user's profile Send private message
Sibben
n00b
n00b


Joined: 16 Nov 2003
Posts: 40
Location: Sweden

PostPosted: Mon Dec 22, 2003 10:28 pm    Post subject: Reply with quote

b0fh:

Unfortunalty I don't have a solution but if you get it working don't forget to take the network down when the lid is closed and turn it on when you open the lid. Maybe it's not neccesary to do a ifconfig ethX down on a lid close but I guess it more correct then not doing so.

And many thanks to everybody who has contributed to this thread, it's great!
Back to top
View user's profile Send private message
Toshimitsu
n00b
n00b


Joined: 25 Dec 2003
Posts: 3

PostPosted: Fri Dec 26, 2003 5:03 am    Post subject: Reply with quote

Like your script, but I did some modifications to it myself.
I've got a Dell X300, and i've got the following ACPI events:

Lid closing: LID0 00000080 0000000x
Suspend (Fn+esc): SLPB 00000080 0000000x
AC plugged out: ADP1 00000080 00000000
AC plugged in: ADP1 00000080 00000001

So i had to do the corresponding changes to the action and on_boot script.

My laptop automatically dims the display when power is plugged out, and the display-light-buttons work without any programs running. So.. I didn't bother having the xgamma-commands in there.

The only problem I'm having now is that the powerbutton don't seem to be generating any events.. I've got the file /proc/acpi/button/power/PWRF/info .. but apparently something's not working 100% ..

Oh, and to tune the cpu-speed, i just use speedfreq -p performance/dynamic when the power's plugged in/out.
Back to top
View user's profile Send private message
jana
n00b
n00b


Joined: 23 Oct 2002
Posts: 24
Location: Blacksburg, VA

PostPosted: Tue Jan 06, 2004 4:09 am    Post subject: x300 / x200 Reply with quote

Toshimitsu,

Thanks to some great help from jetblack in this forum, I've been working on getting ACPI functioning on my Dell x200. I know the machines are different, but it sounds like you've got some features that we don't, perhaps working out of the box... what kernel are you running? Did you have to do any tweaking to get ACPI going? (Unrelated: do you have an internal wireless card? I've got a friend who can't get his to work.)

As far as your power button problem... I know that I don't have a PWRF/state file. Do you, or are you trying to throw an event due to something in the info file?

thanks!
- j
_________________
"That does not make sense to me. But, you are very small."
Back to top
View user's profile Send private message
MiNeR
n00b
n00b


Joined: 06 Jan 2004
Posts: 2
Location: Wuppertal, Germany

PostPosted: Tue Jan 06, 2004 8:30 pm    Post subject: Reply with quote

hello!
there are nice scripts in this post.
thx @all!!! but i was not very happy with the radeontool light off / xscreensaver solution because if i was working on the console and the light turns off, i needed to switch to the x display to deactivate the screensaver and get the backlight on. so i wrote a little c program what does all the things for me. i waits for 20 minutes of idle and then turns off the backlight. if you move the mouse or press a key the light turns on again.

it is written for the 2.6 kernel.
hope you like it :D

Code:

#include <stdio.h>
#include <time.h>

int main( int argc, char argv[] )
{
   int i, j;
   char ch, buffer[1024]="", kb[512]="", kb_old[512]="", ps2[512]="", ps2_old[512]="";
   char *colon, *found, *last;
   FILE *fd;
   time_t saved_time;
   enum bool { true = 1, false = 0 } off=false;

   saved_time = time(NULL);

   while (1) {

      for (j=0; j<2; j++) {

         fd = popen( "cat /proc/interrupts", "r" );
         if ( fd == NULL ) {
            exit(-1);
         }

         i=0;
         while ( (ch = fgetc(fd)) != EOF && i < 1024 ) {
            buffer[i] = ch;
            i++;
         }

         pclose(fd);

         i=0;
         colon = buffer;
         while (1) {

            found = strstr( colon, "i8042" );

            if ( found != NULL ) {

               while ( colon < found ) {
                  last = colon;
                  colon = strstr( colon+1, ":" );
               }

               if ( j != 0 ) {
                  if ( i == 0 )
                     memcpy( kb, last, found-last-1 );
                  else
                     memcpy( ps2, last, found-last-1 );

               } else {
                  if ( i == 0 )
                     memcpy( kb_old, last, found-last-1 );
                  else
                     memcpy( ps2_old, last, found-last-1 );
               }

               i++;

            } else {
               
               if ( j == 0 )
                  sleep(1);

               break;
            }

         }

      }

      if ( strcmp( kb, kb_old) == 0 && strcmp( ps2, ps2_old ) == 0 ) {
         
         fprintf( stderr, "no userinput\n" );

         if ( off == false && time(NULL) - saved_time >= 20*60 ) {
            system("sudo /usr/bin/radeontool light off");
            off=true;
         }

      } else {

         fprintf( stderr, "userinput\n" );
         saved_time = time(NULL);
         
         if ( off == true ) {
            system("sudo /usr/bin/radeontool light on");
            off=false;
         }
      }

      fprintf( stderr, "time: %ld\nsaved time: %ld\nsaved t. - t.: %ld\n", time(NULL), saved_time, time(NULL)-saved_time );
   }
}

Back to top
View user's profile Send private message
angagon
n00b
n00b


Joined: 19 Mar 2003
Posts: 21
Location: Colorado Springs, CO

PostPosted: Mon Jan 12, 2004 9:30 pm    Post subject: Reply with quote

I have an ACPI script that does a
Code:
su $USER -c "/usr/X11R6/bin/xset dpms force off -display :0.0"

and obviously the on version as well. But when I push the lid button /var/log/acpid complains
Code:
Xlib: connection to ":0.0" refused by server
Xlib: No protocol specified

/usr/X11R6/bin/xset:  unable to open display ":0.0"

I have set
Code:
xhost +localhost
, but while that command doesn't complain it seems not to affect anything. But if I do a
Code:
xhost +
the xset command works.

Any ideas?

EDIT:
Oh, yeah, before I knew about xhost if I just restarted acpid upon starting X, xset worked.
_________________
"Not everyone knows Josiah Royce's definition of a liar as a man who willfully misplaces his ontological predicates, but everyone who has ever told a lie will recognize its accuracy."
Ch. 94: Truth - "The Great Ideas"
Back to top
View user's profile Send private message
friday
n00b
n00b


Joined: 07 Feb 2003
Posts: 28
Location: Germany

PostPosted: Sat Jan 17, 2004 7:29 am    Post subject: Reply with quote

I just updated the scripts to suport laptop-mode capable kernels :-)
Back to top
View user's profile Send private message
Bouncelot
n00b
n00b


Joined: 09 Sep 2003
Posts: 56

PostPosted: Fri Jan 23, 2004 1:33 pm    Post subject: Reply with quote

I am trying out the scripts, thanks guys! so far so good. :)

was wondering where/how I can get "/sbin/laptop-mode" is this another script? I found and added the laptopmode patch to the kernel, but can find no refrences to a laptop-mode exicutable....


Thanks,
Back to top
View user's profile Send private message
friday
n00b
n00b


Joined: 07 Feb 2003
Posts: 28
Location: Germany

PostPosted: Fri Jan 23, 2004 1:57 pm    Post subject: Reply with quote

Yes, /sbin/laptopmode is a script.
It was in the docs with mm-sources-2.6.1-mm4 I think.
Back to top
View user's profile Send private message
Bouncelot
n00b
n00b


Joined: 09 Sep 2003
Posts: 56

PostPosted: Fri Jan 23, 2004 2:04 pm    Post subject: Reply with quote

found it, thanks.
Back to top
View user's profile Send private message
Bouncelot
n00b
n00b


Joined: 09 Sep 2003
Posts: 56

PostPosted: Sat Jan 24, 2004 3:52 pm    Post subject: Reply with quote

There were some changes i had to make.

for the xset and xgamma I had to su to the current user. otherwise I got "/usr/X11R6/bin/xset: unable to open display "0:0""

Code:

su $USER -c "$XGAMMA -d :0 -gamma 1.0" # set gamma in X to 100%
su $USER -c "$XSET -d :0 dpms 0 0 600" # shutdown display after 600s


I hardcoded $USER to my username, also "-d 0:0" wouldn't work but "-d :0" did...

I also changed acad in and out to do the hd, speedstep, and laptop mode things even if X was not running.

Code:

   $LOGGER "AC Adapter plugged IN"

   if ps -A | grep -q X
   then
      su $USER -c "$XGAMMA -d :0 -gamma 1.0" # set gamma in X to 100%
      su $USER -c "$XSET -d :0 dpms 0 0 600" # shutdown display after 600s
   fi
   $SPEEDFREQ -p performance
   $LAPTOPMODE stop # stop laptop-mode
   $HDPARM -S 240 /dev/hda > /dev/null 2>&1 # spindown after 20min
   $HDPARM -B 255 /dev/hda > /dev/null 2>&1 # disable drive's APM


finaly I had to remove the call to no_action, and insert it's contents directly into the case statment, $+ had no value once no_action was called.

Code:

*)
      #no_action
      echo "#### NO ACTION FOR EVENT: " $*
      exit 1
;;


I may be looking at battery status next week, if I work anything out I'll post it here.
Back to top
View user's profile Send private message
jetblack
Guru
Guru


Joined: 15 Jan 2003
Posts: 340
Location: Evanston, IL, USA

PostPosted: Sat Jan 31, 2004 4:44 pm    Post subject: Reply with quote

Thanks for all these scripts! I've been playing around with them now that I've got ACPI mostly working. I don't have any major changes to contribute yet, but I do have a question.

I'm using the hdparm settings suggested here, and I've noticed that something seems to be accessing my hard drive every 10-30 seconds, even if I'm not doing anything on the machine. Perhaps I should expect that, since I have to access /proc/acpi/battery/BAT1/info & /proc/acpi/battery/BAT1/state whenever there is a battery event. Of course, this causes the drive to spin back up momentarily. Does anyone else notice that? Will that significantly reduce my hard drive's lifespan down the road? Also, will the repeated spinups cancel out any power savings that I'm getting from using these hdparm settings?

Thanks again for the great thread!
Back to top
View user's profile Send private message
friday
n00b
n00b


Joined: 07 Feb 2003
Posts: 28
Location: Germany

PostPosted: Sat Jan 31, 2004 11:04 pm    Post subject: Reply with quote

Bouncelot wrote:

I also changed acad in and out to do the hd, speedstep, and laptop mode things even if X was not running.


That makes somewhat more sense. Thanks for pointing this out.
I made that changes when I was pretty tired :roll:

jetblack wrote:

I'm using the hdparm settings suggested here, and I've noticed that something seems to be accessing my hard drive every 10-30 seconds, even if I'm not doing anything on the machine.
Perhaps I should expect that, since I have to access /proc/acpi/battery/BAT1/info & /proc/acpi/battery/BAT1/state whenever there is a battery event. Of course, this causes the drive to spin back up momentarily. Does anyone else notice that?


/proc is not a real filesystem but a virtual one. So I don't think there is any access to your hd when reading/writing proc.

Maybe you are low on mem and grep/awk/whatever is loaded from disk each time, but I don't think this happens under linux. These should be in mem and not swapped out since they're run quite often when using these scripts.

Does $LAPTOPMODE exist on your drive?
Is it actually the right script?
Do you have a kernel with laptop-mode?

jetblack wrote:

Will that significantly reduce my hard drive's lifespan down the road? Also, will the repeated spinups cancel out any power savings that I'm getting from using these hdparm settings?


Recent HD's built into laptops are designed to be spun up/down a lot of times, so this won't be too significant. I think there was some discussion about that on the net...

Repeated spinups do of course effect the powerconsumption.
AFAIR someone reported an increase from 2h to 3h for his laptop running on battery. That's a 50% gain 8O
Back to top
View user's profile Send private message
jetblack
Guru
Guru


Joined: 15 Jan 2003
Posts: 340
Location: Evanston, IL, USA

PostPosted: Sun Feb 01, 2004 2:14 pm    Post subject: Reply with quote

friday wrote:
/proc is not a real filesystem but a virtual one. So I don't think there is any access to your hd when reading/writing proc.


*slaps head*

Oh yeah. I'm not sure what (or if) I was thinking there. I guess if the system is writing to anything, it's /var/log/acpid.log (or whatever that file is). That's a possibility.

friday wrote:
Maybe you are low on mem and grep/awk/whatever is loaded from disk each time, but I don't think this happens under linux. These should be in mem and not swapped out since they're run quite often when using these scripts.


Possible - I'll check that out later today, but I should have plenty of memory.

friday wrote:
Does $LAPTOPMODE exist on your drive?
Is it actually the right script?
Do you have a kernel with laptop-mode?


Oh, I'm not doing anything with laptop-mode yet. I was taking it a step at a time. If I can't track this down, I'll give laptop-mode a try and see if it helps.

friday wrote:
Recent HD's built into laptops are designed to be spun up/down a lot of times, so this won't be too significant. I think there was some discussion about that on the net...

Repeated spinups do of course effect the powerconsumption.
AFAIR someone reported an increase from 2h to 3h for his laptop running on battery. That's a 50% gain 8O


Glad to hear about the spinups. That is an impressive gain. I'll have to do some benchmarking. I can say that it seemed to last longer yesterday, but that's not particularly quantitative. :)
Back to top
View user's profile Send private message
friday
n00b
n00b


Joined: 07 Feb 2003
Posts: 28
Location: Germany

PostPosted: Sun Feb 01, 2004 4:42 pm    Post subject: Reply with quote

jetblack wrote:

Oh, I'm not doing anything with laptop-mode yet. I was taking it a step at a time. If I can't track this down, I'll give laptop-mode a try and see if it helps.


It really should solve this problem, see
ftp://ftp.kernel.org/pub/linux/kernel/people/akpm/patches/2.6/2.6.2-rc1/2.6.2-rc1-mm1/broken-out/laptop-mode-2.patch

I could not find a better source on the web, but the doc comes with the kernel sources. At least mm-sources :)
Back to top
View user's profile Send private message
jetblack
Guru
Guru


Joined: 15 Jan 2003
Posts: 340
Location: Evanston, IL, USA

PostPosted: Mon Feb 02, 2004 5:33 am    Post subject: Reply with quote

friday wrote:
jetblack wrote:

Oh, I'm not doing anything with laptop-mode yet. I was taking it a step at a time. If I can't track this down, I'll give laptop-mode a try and see if it helps.


It really should solve this problem, see
ftp://ftp.kernel.org/pub/linux/kernel/people/akpm/patches/2.6/2.6.2-rc1/2.6.2-rc1-mm1/broken-out/laptop-mode-2.patch

I could not find a better source on the web, but the doc comes with the kernel sources. At least mm-sources :)


Thanks. It certainly helps. Looks like it's about every 30-60 seconds now. I'll keep playing with it, but at least there doesn't seem to be any reason not to use laptop-mode. And fortunately, it applies to the vanilla kernels, since I'm using a rather heavily patched 2.6.1 kernel, and some of the patches don't apply to mm-sources. I could probably fix them, but I'm feeling lazy right now. ;)
Back to top
View user's profile Send private message
MyZelF
Bodhisattva
Bodhisattva


Joined: 25 Feb 2003
Posts: 2010
Location: Venice, Italy

PostPosted: Sun Feb 08, 2004 9:22 pm    Post subject: Reply with quote

hulk2nd wrote:

there is a perl script that recognizes a running xscreensaver and then activates the radeontool.


Here's another one, that doesn't require neither xscreensaver nor perl:

Code:
#!/bin/bash

################################################################
# dpmswatch.sh
# Copyright 2003 Rob Mahurin <rob@utk.edu>
# Available for use under the General Public License
# No warranty etc.
##
#  This is based on lightwatch.pl, but instead of using
#  xscreensaver-command -watch, it uses xset to query the DPMS state
#  of the LCD.  If the desired DPMS state is off, blank the LCD
#  backlight using radeontool.
##
#  If your system gives a different output to this command :
#  $ for i in standby suspend off on ; do
#      xset dpms force $i ;
#      xset q ;
#    done | grep Monitor | awk '{print $3 $4 }'
#    inStandby
#    inSuspend
#    Off
#    On
#  then you may have to modify this script.
##
#  It's written in shell instead of Perl because that's what I know.
################################################################

# commands to use.  Correct on Debian woody.
XSET=/usr/bin/X11/xset
RADEONTOOL=/usr/bin/radeontool

# The polling intervals, for feeding to sleep(1).  Is there way to
# make this event-driven, rather than poll all the time?  Does it
# matter?
#
# Notice that we don't want to watch the xscreensaver, since that
# would bring up the password box without turning on the LCD.  Very
# confusing.
inStandby_INTERVAL=5s
inSuspend_INTERVAL=5s
Off_INTERVAL=1s
On_INTERVAL=5s
INTERVAL=0s;

# check to make sure we have all the commands we need
for i in $XSET $RADEONTOOL
do    [ -x $i ] || { echo $i not found >&2 || exit 0 ; }
done

while : ; do
    # what is the state of the monitor?
    STATE=$($XSET q | grep Monitor | awk '{print $3 $4}')

    # if the monitor is in standby or suspend, change the polling
    # interval # but turn the light on or off.  If the monitor is Off,
    # turn off the # LCD backlight.  If the monitor is On, turn on the
    # backlight.  Then sleep until it's time to check again.
    case $STATE in
        inStandby)
                INTERVAL=$inStandby_INTERVAL
                ;;
        inSuspend)
                INTERVAL=$inSuspend_INTERVAL
                ;;
        Off)
                INTERVAL=$Off_INTERVAL
                $RADEONTOOL light off
                ;;
        On)
                INTERVAL=$On_INTERVAL
                $RADEONTOOL light on
                ;;
        # if something strange happens, turn the light on and fail.
        *)
                $RADEONTOOL light on
                exit 1
                ;;
    esac
    sleep $INTERVAL
done


I found it here.
Back to top
View user's profile Send private message
dsd
Developer
Developer


Joined: 30 Mar 2003
Posts: 2162
Location: nr London

PostPosted: Fri Feb 13, 2004 7:42 pm    Post subject: Reply with quote

broken link (403):
http://cknoerle.homelinux.org/nx9000/stuff/acpi/acpi-2004.02.12.tgz
_________________
http://dev.gentoo.org/~dsd
Back to top
View user's profile Send private message
friday
n00b
n00b


Joined: 07 Feb 2003
Posts: 28
Location: Germany

PostPosted: Sat Feb 14, 2004 1:29 pm    Post subject: Reply with quote

I fixed the broken link. Thanks dsd.
The file just had wrong permissions.
Back to top
View user's profile Send private message
MaGuS
Guru
Guru


Joined: 13 Jun 2002
Posts: 303
Location: Luebeck, Germany

PostPosted: Mon Feb 16, 2004 11:06 am    Post subject: Reply with quote

Hi,

since I am using speedfreqd and I had no use for the "dynamic" level I tried this:
Code:

battery ()
{
   if grep -q discharging $BAT_STATE
   then
      BAT_REMAIN=`awk '/remaining/ { print $3 }' $BAT_STATE`
      BAT_FULL=`awk '/last/ { print $4 }' $BAT_INFO`
      let "BAT_HALF=($BAT_FULL / 2 )"
      if (($BAT_REMAIN < $BAT_HALF))
      then
      $SPEEDFREQ -p powersave
   fi
      if (($BAT_REMAIN < `awk '/warning/ { print $4 }' $BAT_INFO`))
      then
         $LOGGER "battery capacity is critically low"
echo "System is going down!" > /dev/speech
         btn_pwr
      fi
   fi
}


I could not test it because my battery is full at the moment, but it should work.

If the battery level is 1/2 of the last full level it will go into powersave modus, before it use the dynamic one.

For speechd look at this topic. I use it for other events, too.

Update:
The boot Script:
Code:

#!/bin/bash
#
# /etc/acpi/on_boot.sh (2004.01.17)
# called on boot to check for AC Adapter
# Christopher Knoerle <cknoerle@gmx.net>
#

# This works with gentoo-sources, ac-sources, mm-sources on my
# HP Compaq nx9000 Laptop. For more information have a look at
# http://cknoerle.homelinux.org/nx9000/

# The latest version is available from
# http://cknoerle.homelinux.org/nx9000/stuff/acpi/

# This should be placed in /etc/acpi/on_boot.sh and should be called
# through /etc/conf.d/local.start
# You can achieve this by doing the following:
# echo "/etc/acpi/on_boot.sh" >> /etc/conf.d/local.start


# lets set some paths
LOGGER="/usr/bin/logger -t ACPID" # logs to syslog - an echo logs to /var/log/acpid
XGAMMA="/usr/X11R6/bin/xgamma"
XSET="/usr/X11R6/bin/xset"
LAPTOPMODE="/sbin/laptopmode"
HDPARM="/sbin/hdparm"
SPEEDFREQ="/usr/bin/speedfreq"
BAT_STATE="/proc/acpi/battery/BAT1/state"
BAT_INFO="/proc/acpi/battery/BAT1/info"


#test for ac
if grep -q 'off-line' /proc/acpi/ac_adapter/ADP1/state
then
   $LOGGER "AC Adapter plugged OUT"

   if ps -A | grep -q X
   then
      $XGAMMA -d 0:0 -gamma 0.7 # set gamma in X to 70%
      $XSET -d 0:0 dpms 0 0 120 # shutdown display after 120s
   fi
   $LAPTOPMODE start # start laptop-mode
   $HDPARM -S 4 /dev/hda > /dev/null 2>&1 # spindown after 20s
   $HDPARM -B 1 /dev/hda > /dev/null 2>&1 # enable drives's APM
   
      BAT_REMAIN=`awk '/remaining/ { print $3 }' $BAT_STATE`
      BAT_FULL=`awk '/last/ { print $4 }' $BAT_INFO`
      let "BAT_HALF=($BAT_FULL / 2 )"
      if (($BAT_REMAIN < $BAT_HALF))
      then
      $LOGGER "Battery under half capacity (powersave mode)"
      $SPEEDFREQ -p powersave
      echo "powersave modus" > /dev/speech
   else
      $LOGGER "Battery over half capacity (dynamic mode)"
      $SPEEDFREQ -p dynamic
      echo "dynamic modus" > /dev/speech
   fi

   # not needed anymore - use powernowd
   #echo -n 1:0 > /proc/acpi/processor/CPU0/limit # set cpu performance state 1, throttling to 0
else
   $SPEEDFREQ -p performance
   exit 0
fi

# EOF


Best regards,
Magnus
Back to top
View user's profile Send private message
Kovid
Apprentice
Apprentice


Joined: 25 Aug 2003
Posts: 217
Location: California, USA

PostPosted: Wed Feb 18, 2004 4:46 pm    Post subject: Reply with quote

I made some modifications to Chris' script, mainly to improve KDE compatibility. It will now cycle through all users till it finds a user running kdesktop and call dcop only for that user.

Also I want to be able to handle the case when the Xserver is started after the ac adapter is unplugged, so I have modified acad_out and put a call to it in the battery state handler. This also removes the neccessity for the on_boot.sh script

Code:

source /etc/profile # for KDEDIR definition
DCOP=$KDEDIR/bin/dcop
KDE_USER="" # The user with a running KDE desktop
if [ -x $DCOP ]; then
  for user in $(users); do
    $DCOP --user $user kdesktop > /dev/null 2>&1
    if [ $? = 0 ]; then
      KDE_USER=$user
    fi
  done
fi

btn_pwr () {
  $LOGGER "Powerbutton pressed" 
  if [ -n $KDE_USER ]; then 
    $DCOP --user $KDE_USER ksmserver ksmserver logout 1 2 0 && exit 0
  else
    $LOGGER "shutdown initiated"
    /sbin/poweroff
  fi
}

# AC Adapter plugged in
AC_OUT=""
acad_in () {
  $LOGGER "AC Adapter plugged IN"
  ps -A | grep -q X
  if [ $? = 0 ]; then
    $XGAMMA -d 0:0 -gamma 1.0 # set gamma in X to 100%
    $XSET -d 0:0 dpms 0 0 600 # shutdown display after 600s
  fi
   $HDPARM -S 240 /dev/hda > /dev/null 2>&1 # spindown after 20min
   $HDPARM -B 255 /dev/hda > /dev/null 2>&1 # disable drive's APM
   AC_OUT=""
}
 
 
# AC Adapter plugged out
# The X part is always called since the X server may be started up after adapter is unplugged
# To handle this a call to acad_out has been placed in the battery even handler
acad_out () {
  ps -A | grep -q X
  if [ $? = 0 ]; then
    $XGAMMA -d 0:0 -gamma 0.6 # set gamma in X to 70%
    $XSET -d 0:0 dpms 0 0 120 # shutdown display after 120s
  fi
  if [ -z AC_OUT ]; then
    $LOGGER "AC Adapter plugged OUT"
    $HDPARM -S 4 /dev/hda > /dev/null 2>&1 # spindown after 20s
    $HDPARM -B 1 /dev/hda > /dev/null 2>&1 # enable drives's APM
    AC_OUT="done"
  fi
}
 
# state of battery changed
# shutdown if battery capacity is low
BAT_LOW=""
BAT_CRIT=""
battery () {
  grep -q discharging $BAT_STATE || grep -q unknown $BAT_STATE
  if [ $? = 0 ]; then
    acad_out
    BAT_REMAIN=$(awk '/remaining/ { print $3 }' $BAT_STATE)
    BAT_WARNING=$(awk '/warning/  { print $4 }' $BAT_INFO)
    BAT_CRITICAL=$(awk '/low/     { print $4 }' $BAT_INFO)
    if [ $BAT_REMAIN -lt $BAT_CRITICAL -a -z $BAT_CRIT ]; then
      BAT_CRIT="notified"
      if [ -n $KDE_USER ]; then
        $DCOP --user $KDE_USER knotify Notify notify notify Me "Battery Critical. Poweroff strongly recommended." nosound nofile 2 0
      else
        $LOGGER "Battery capacity is critical"
      fi
    else
      if [ $BAT_REMAIN -lt $BAT_WARNING -a -z $BAT_LOW ]; then
        BAT_LOW="notified"
        if [ -n $KDE_USER ]; then
          $DCOP --user $KDE_USER knotify Notify notify notify Me "Battery Low. Poweroff recommended." nosound nofile 2 0
        else
          $LOGGER "Battery capacity is critical"
        fi
      fi
    fi
  fi
}
 
Back to top
View user's profile Send private message
kambrian
n00b
n00b


Joined: 09 Feb 2004
Posts: 6

PostPosted: Sat Feb 21, 2004 6:02 pm    Post subject: Reply with quote

I am having a problem with this. If I just close the lid, the monitor stays on. If I push the button to close the lid and then manually check the state of monitor in /proc, the backlight turns off. Here is the log from /var/log/acpid

[Sat Feb 21 11:01:10 2004] received event "button/lid LID 00000080 0000000a"
[Sat Feb 21 11:01:10 2004] executing action "/etc/acpi/default.sh button/lid LID
00000080 0000000a"
[Sat Feb 21 11:01:10 2004] BEGIN HANDLER MESSAGES
[Sat Feb 21 11:01:10 2004] END HANDLER MESSAGES
[Sat Feb 21 11:01:10 2004] action exited with status 0
[Sat Feb 21 11:01:10 2004] executing action "/etc/acpi/actions.sh button/lid LID
00000080 0000000a"
[Sat Feb 21 11:01:10 2004] BEGIN HANDLER MESSAGES
/etc/acpi/actions.sh: line 10: echo####NO ACTION FOR EVENT: : command not found
[Sat Feb 21 11:01:10 2004] END HANDLER MESSAGES
[Sat Feb 21 11:01:10 2004] action exited with status 1
[Sat Feb 21 11:01:10 2004] completed event "button/lid LID 00000080 0000000a"\

Any ideas?
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks All times are GMT
Goto page Previous  1, 2, 3  Next
Page 2 of 3

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum