#!/usr/bin/perl # acadmon.pl - sjb (ottaky@ottaky.com) - 18/07/2002 - nasty, nasty Perl script to monitor ACPI events and # change CPU + LCD settings to suit. Use at your own risk! # Distributed under whichever licence suits your needs. #### make sure these are pointing to the right places ############################# use constant LRUN => '/usr/sbin/longrun'; # longrun executable use constant SPIC => '/usr/sbin/spicctrl'; # spicctrl executable use constant ACPI => '/proc/acpi'; # you shouldn't need to change this ################################################################################### use constant ACAD => ACPI.'/ac_adapter/ACAD'; die "Couldn't find longrun executable at ".LRUN."\n" unless (-x LRUN); die "Couldn't find spicctrl executable at ".SPIC."\n" unless (-x SPIC); my $acadstate = &getACPIInfo(ACAD.'/state') || die "Couldn't get ac-adapter status"; my $acstate = $$acadstate{'state'}; &setLevels($acstate); open (EVENT, ACPI.'/event') || die "Couldn't open ".ACPI."/event\n"; while () { next unless (/^ac_adapter/); my $newstate = &getACPIInfo(ACAD.'/state'); if ($$newstate{'state'} ne $acstate) { &setLevels($$newstate{'state'}); $acstate = $$newstate{'state'}; } } sub setLevels ($) { my ($state) = @_; my $command; if ($state eq 'on-line') { $command = LRUN.' -s 0 100;'.LRUN.' -f performance;'.SPIC.' -b 255'; } elsif ($state eq 'off-line') { $command = LRUN.' -s 0 33;'.LRUN.' -f economy;'.SPIC.' -b 60'; } my $stdout = `$command` if ($command); } sub getACPIInfo ($) { my ($interface) = @_; if (-e $interface) { if (open (INTERFACE, $interface)) { my %info; while () { my ($label,$value) = (m/^([^:]+):\s+(.+)$/); $value =~ s/\D//g if ($value =~ /^\d/); $info{$label} = $value; } close (INTERFACE); return (\%info); } } return undef; }