#!/usr/bin/perl -w # Asus Eee PC peripheral power utility. # Copyright (C) 2008 Tomaz Solc # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA use strict; my $asus_acpi_dir = "/proc/acpi/asus"; my %descriptions = ( "wlan" => "Wireless LAN", "cardr" => "SD/MMC reader", "camera" => "Camera" ); sub control { my ($name, $state) = @_; if(defined($state)) { open(CTRL, ">$asus_acpi_dir/$name") or die("Can't open $asus_acpi_dir/$name: $! (is asus_acpi.ko loaded?)"); if($state) { print(CTRL "1"); } else { print(CTRL "0"); } close(CTRL); } else { open(CTRL, "<$asus_acpi_dir/$name") or die("Can't open $asus_acpi_dir/$name: $! (is asus_acpi.ko loaded?)"); $state = ; chop($state); if($state) { return 1; } else { return 0; } close(CTRL); } } sub print_state { my ($name) = @_; my $state; if(&control($name)) { $state = "on"; } else { $state = "off"; } printf("%15s %s\n", $descriptions{$name}, $state); } if(not defined($ARGV[0])) { print("Asus Eee PC peripheral power utility. Copyright (c) Tomaz Solc. Under GPL.\n\n"); for my $name (keys(%descriptions)) { &print_state($name); } } else { if(not defined($descriptions{$ARGV[0]})) { print("USAGE: eeepower [ device ] [ on | off ]\n\n"); print("Available devices:\n"); for my $name (keys(%descriptions)) { printf(" %10s %s\n", $name, $descriptions{$name}); } print("\n"); die("Unknown device $ARGV[0]"); } if(defined($ARGV[1])) { if($ARGV[1] eq "on") { &control($ARGV[0], 1); } elsif($ARGV[1] eq "off") { &control($ARGV[0], 0); } else { die("Use on or off (not $ARGV[1])"); } } else { &print_state($ARGV[0]); } }