View difference between Paste ID: 3fHSEvCu and CXSu4Lcd
SHOW: | | - or go back to the newest paste.
1
#!/usr/bin/perl
2
3
# make sure to set this string to
4
# the corresponding remote in /etc/lircd.conf
5
$remote_name = "RCA";
6
7
# Let's assume you don't need to press enter after you punch in a
8
# channel number. Change this to 1 if your cable box expects you press
9
# enter after each command
10
$needs_enter = 0;
11
12
# Change this to point to your rc executable
13
$rc_command = "/usr/bin/irsend";
14
15
# This outputs debugging info to a file.  Change path to suit your needs.
16-
my $debugfile = "/tmp/debugchannelchange.txt"
16+
$debugfile = "/tmp/debugchannelchange.txt";
17
18
# This subroutine actually sends the signal to the cable box
19
sub change_SIGNAL {
20
    my($SIGNAL) = @_;
21
    system ("$rc_command SEND_ONCE $remote_name $SIGNAL");
22
}
23
24
$SIGNAL=$ARGV[0];
25
open F, ">> /var/log/channel.log";
26
print F "channel changing $SIGNAL\n";
27
close F;
28
print "channel changing $SIGNAL\n";
29
30
# Checks if $SIGNAL begins with a digit
31
# If it detects that the string is made up of digits, then it puts
32
# spaces between the digits.  Ex. 1234 becomes 1 2 3 4
33
if ( $SIGNAL =~ /^\d+$/ )
34
{
35
    my $length = length($SIGNAL);
36
    my $counter = 0;
37
    my $temp;
38
39
    while( $counter < $length )
40
    {
41
	$temp .= substr($SIGNAL,$counter,1) ." ";
42
	$counter++;
43
    }
44
45
    # write out contents of $temp variable to a file for debugging
46
    # this has not been tested but should be close
47
    open (DEBUGCHANSCPT, ">>" . $debugfile); #open for write, append
48
    print DEBUGCHANSCPT "Timestamp: ";
49
    print DEBUGCHANSCPT &timestamp();
50
    print DEBUGCHANSCPT "\n";
51
    print DEBUGCHANSCPT "Channel String: ";
52
    print DEBUGCHANSCPT "$temp\n";
53
54
    change_SIGNAL($temp);
55
}
56
else
57
{
58
    # argument we passed was not made up of digits, so it must be a
59
    # command that does something other than channel changing on the
60
    # cable box
61
    change_SIGNAL($SIGNAL);
62
}
63
64
# Do we need to send enter
65
if ( $needs_enter )
66
{
67
    system ("$rc_command SEND_ONCE $remote_name ENTER");
68
}