#!/usr/bin/perl -w # # IRBOX, an Ivy driver for infra-red remote controls # # Copyright 1998-1999 # Centre d'Etudes de la Navigation Aerienne # # Authors: Johnny Accot # Stephane Chatty # # A utility for creating code tables from an RCA programmable remote # # $Id$ # # Please refer to file version.h for the # copyright notice regarding this software # $SIG{HUP} = $SIG{INT} = $SIG{KILL} = 'Quit'; use strict; use Ivy; use File::Basename; $| = 1; my @vcrkeys = ('power', 'channel up', 'channel down', 'rew', 'play', 'ff', 'rec', 'stop', 'pause'); my @tvkeys = ('mute', 'power', 'volume up', 'volume down', 'channel up', 'channel down'); my @cablekeys = ('power', 'channel up', 'channel down'); my %typekeys = ('VCR', \@vcrkeys, 'TV', \@tvkeys, 'CABLE', \@cablekeys); my $me = basename ($0); die ("Usage: $me [] [RCA mode number]\n") unless @ARGV < 3; # retrieve various IR control identification items my ($id, $mode) = @ARGV; if (!defined $id) { print "ID of the IR remote control (eg: Sony:VCR:1)? "; chop ($id = <>); } my ($brand, $type, $num) = split (':', $id, 3); if (!defined ($brand) || !defined ($type)) { die "Brand and type must be defined"; } my $comment; $comment = "# obtained on an RCA SystemLink 3 in $type mode $mode" if (defined $mode); # we only handle types we know if (!defined ($typekeys{$type})) { die "Type $type unknown\n"; } # # OK, let's go # # first, prepare to receive key presses from Ivy bus my $host = 'nebul'; Ivy::bindRegexp ("[a-z]*\.IRBOX unknown code ([0-9]+ [0-9]+ [0-9]+ [0-9]+ [0-9]+ [0-9]+)", [\&ReceiveCode]); Ivy::bindRegexp ("[a-z]*\.IRBOX Down (.*)", [\&PrintCode]); Ivy::start (-loopMode => 'LOCAL', -appName => 'IR Remote Control Map dumper', -broadcastPort => 2019); # then create list of keys the user will have to press, # and ask for the first one my @keylist = @{$typekeys{$type}}; my %table; my $key = shift @keylist; print "Please press on '$key'..."; # then loop Ivy::mainLoop (); &Dump(); exit 1; my $lastcode = "000"; sub ReceiveCode { my $code = $_[1]; if (defined $lastcode and $code eq $lastcode) { print "(mmm... previous key had autorepeat!) ..."; return; } $lastcode = $code; print "ok, code = $code\n"; $table{$key} = $code; $key = shift @keylist; if (defined $key) { print "Please press on '$key'..."; } else { print "Done, thank you\n"; # should exit loop, but Ivy does not allow that # Ivy::stop (); # So, let's be brutal! Dump (); exit 1; } } sub PrintCode { my $name = $_[1]; print "$name\n"; } sub Quit { Ivy::stop (); exit 1; } sub Dump { my $lowbrand = $brand; $lowbrand =~ tr/[A-Z]/[a-z]/; my $brandnum; if (defined ($num)) { $brandnum = "$brand $num"; } else { $brandnum = $brand; $num = ""; } my $filename = "$lowbrand$type$num.ir"; print "Saving table $filename\n"; if (-s "$filename") { my $choice; print "File $filename exists... Overwrite? (y/[n]) "; chop ($choice = <>); until ($choice eq 'y' or $choice eq 'n') { print "Please answer by 'y' or 'n': "; chop ($choice = <>); } die ("Aborting.\n") if $choice eq 'n'; } open Table, ">$filename"; print Table "name $brand$type$num\n"; print Table "type: $type\n"; print Table "\n"; print Table "brand: $brandnum\n"; print Table "brand: RCA SystemLink 3 [mode $mode]\n" if defined $mode; print Table "\n$comment\n" if defined $comment; print Table "\n"; foreach my $key (@{$typekeys{$type}}) { print Table "$key:\t$table{$key}\n"; } close Table; exit; }