# $Id: BottleRocket.pm,v 1.10 2006/12/28 01:54:26 peterw Exp peterw $ # SlimServer Copyright (c) 2001-2005 Sean Adams, Slim Devices Inc. # BottleRocket.pm Copyright (c) 2006 Peter Watkins # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License, # version 2. # # 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. # package Plugins::BottleRocket; # ----------------- USER SETTINGS ------------------- # # This plugin depends on the BottleRocket command-line app, which # can be found at http://www.linuxha.com/bottlerocket/ # # command line args for the 'br' bottlerocket utility # each argument should be in a separate element; see # http://www.perl.com/doc/manual/html/pod/perlfunc/system.html # # -x /dev/ttyS0 - use device /dev/ttyS0 # -r 3 - send the code 3 times (more reliable) my @brCommandArgs = ( '/usr/local/bin/br','-x','/dev/ttyS0','-r','3' ); # the device code (A through P) for your X10 setup my $houseCode = 'A'; # map your Squeezebox device names to their X10 device numbers # with key => value pairs my %playerX10DeviceNumber = ( #'My Squeezebox' => 2, #'My Squeezebox2' => 4, ); # ----------------- USER SETTINGS ------------------- sub strings { return ' PLUGIN_BOTTLEROCKET EN BottleRocket plugin PLUGIN_BOTTLEROCKET_NOT_IMPLEMENTED EN No player UI available '}; use vars qw($VERSION); $VERSION = &rcsVersion(); use Slim::Control::Command; use Slim::Player::Client; use Slim::Utils::Strings qw (string); use vars qw($VERSION); $VERSION = substr(q$Revision: 1.10 $,10); sub rcsVersion() { my $rcsVersion = '$Revision: 1.10 $'; $rcsVersion =~ s/.*:\s*([0-9\.]*).*$/$1/; return $rcsVersion; } my %client_context = (); my %playerStatus; my $pluginEnabled = 0; my $callbackSet = 0; sub getDisplayName { return 'PLUGIN_BOTTLEROCKET'; } sub enabled { # use a newer version with SlimServer 6.5! return ( ($::VERSION ge '6.0') && ($::VERSION lt '6.5') ); } sub initPlugin { if ( $callbackSet != 1 ) { Slim::Control::Command::setExecuteCallback(\&_BottleRocketCallback); $callbackSet = 1; } $pluginEnabled = 1; } sub shutdownPlugin { # we should not act $pluginEnabled = 0; } sub _BottleRocketCallback { # do nothing if not enabled if ( $pluginEnabled != 1 ) { return; } # thanks to Richard Purdie (webwide@rpsys.net) for AutoVolume.pm my $client = shift; my $paramsRef = shift; my $p0 = @$paramsRef[0]; my $p1 = @$paramsRef[1]; if ( ((defined($p1) && $p1 eq "power_toggle")) || ((defined($p0) && $p0 eq "power")) ) { # from RPC.pm: # get a list of all the players my @players = Slim::Player::Client::clients(); # consider them one by one for my $player (@players) { # get the player's name and power status (power status # as of SlimServer 6.2.2 is the power status *after* # completing the current command, i.e. "off" means we # should turn the amplifier off) my $name = $player->name(); my $power = $player->power(); # only really look at players listed as having X10 numbers if ( defined($playerX10DeviceNumber{$name}) ) { # if we don't remember the player's status or # it has changed, we need to act if ( (!defined($playerStatus{$name})) || ($playerStatus{$name} != $power) ) { # decide to turn ON or OFF my $powerArg = '-n'; if ( $power == 0 ) { $powerArg = '-f'; } # make a new command line array my @cmdArgs = @brCommandArgs; # need to specify house code first push @cmdArgs, '-c', $houseCode; # finally, on/off and device # push @cmdArgs, $powerArg, $playerX10DeviceNumber{$name}; #print "command: \"".join(' ',@cmdArgs)."\"\n"; # execute the command system(@cmdArgs); # note the status so we won't run the # command again when another player's # power status changes $playerStatus{$name} = $power; } } } } } our %configFunctions = ( 'up' => sub { my $client = shift; $client->bumpUp($client); }, 'down' => sub { my $client = shift; $client->bumpDown($client); }, 'left' => sub { my $client = shift; Slim::Buttons::Common::popModeRight($client); }, 'right' => sub { my $client = shift; $client->bumpRight($client); }, ); sub configLines { my $client = shift; my ($line1, $line2); $line1 = string('PLUGIN_BOTTLEROCKET'); $line2 = string('PLUGIN_BOTTLEROCKET_NOT_IMPLEMENTED'); return ($line1, $line2); } sub getFunctions { return \%configFunctions; } sub setMode { my $client = shift; $client->lines(\&configLines); } 1;