#!/usr/bin/perl

#	Created:	Matt Shannon
#	Date:		20090831
#	Email:		Matthew dot Shannon at Comcast dot Net

# 	Custom change-channel-lirc.pl perl script to allow for switching 
#	between raw and 'ideal' hex IR codes.  Meant to address some issue
#	with iguanaIR(?), lirc 0.8.5, and the Motorola 0 (zero) IR codes not working.
#	Meant to be used with my custom lircd.conf definition file.
#	This combination of change-channel-lirc.pl and lircd.conf is to fix a
#	very specific, and appearently rare issue with lircd, IguanaIR (maybe
#	just USB IR), Motorola codes, and MythTV.  I never found the root cause.
#	I just decided to code around it.  I hope this helps someone else out on 
#	the internets.

$remote_name = "DCT2000";				# var to hold name of ideal remote
$remote_name_raw = "DCT2000_RAW";		# var to hold name of raw remote

sub change_channel {
        my($channel_digit) = @_;
		
		if ($channel_digit != 0) {
			system ("irsend SEND_ONCE $remote_name $channel_digit");
			}
		else {
			system ("irsend SEND_ONCE $remote_name_raw $channel_digit");
		}
		
        sleep 1;
}

$channel=$ARGV[0];						# set $channel = to parameter passed


for ($i = 0; $i <= length($channel); $i++) {		# Lets loop the length of the channels
        change_channel(substr($channel,$i,1));
}

system ("irsend SEND_ONCE $remote_name OK");			# Polish it off with an OK

#end of line.
