summaryrefslogtreecommitdiff
path: root/src/irdumptable
blob: c564f943cd81002d6a542f919922f9f6f010259c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#!/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 <accot@cena.dgac.fr>
#		Stephane Chatty <chatty@cena.dgac.fr>
#
#	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 [<brand:class:id>] [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;

}