1 | =head1 NAME |
1 | =head1 NAME |
2 | |
2 | |
3 | RCU::Lirc - RCU interface to linux-infrared-remote-control |
3 | RCU::DevLirc - RCU interface to the /dev/lirc device. |
4 | |
4 | |
5 | =head1 SYNOPSIS |
5 | =head1 SYNOPSIS |
6 | |
6 | |
7 | use RCU::Lirc; |
7 | use RCU::DevLirc; |
8 | |
8 | |
9 | =head1 DESCRIPTION |
9 | =head1 DESCRIPTION |
10 | |
10 | |
11 | See L<RCU>. |
11 | See L<RCU>. |
12 | |
12 | |
13 | =over 4 |
13 | =over 4 |
14 | |
14 | |
15 | =cut |
15 | =cut |
16 | |
16 | |
17 | package RCU::Lirc; |
17 | package RCU::DevLirc; |
18 | |
18 | |
19 | use DynaLoader; |
19 | use DynaLoader; |
20 | use Carp; |
20 | use Carp; |
21 | use POSIX (); |
21 | use POSIX (); |
22 | use Time::HiRes (); |
22 | use Time::HiRes (); |
… | |
… | |
27 | |
27 | |
28 | use base qw(RCU::Interface DynaLoader); |
28 | use base qw(RCU::Interface DynaLoader); |
29 | |
29 | |
30 | BEGIN { |
30 | BEGIN { |
31 | $VERSION = 0.01; |
31 | $VERSION = 0.01; |
32 | bootstrap RCU::Lirc $VERSION; |
32 | bootstrap RCU::DevLirc $VERSION; |
33 | } |
33 | } |
34 | |
34 | |
35 | =item new progname |
35 | =item new |
36 | |
36 | |
37 | Create an interface to lircd using the configuration for program "progname". |
37 | Create an interface to /dev/lirc. |
38 | |
38 | |
39 | =cut |
39 | =cut |
40 | |
40 | |
41 | sub new { |
41 | sub new { |
42 | my $class = shift; |
42 | my $class = shift; |
43 | my $prog = shift || "perl"; |
|
|
44 | my $self = $class->SUPER::new(); |
43 | my $self = $class->SUPER::new(); |
45 | my $fh = local *LIRC_FH; |
44 | my $fh = local *LIRC_FH; |
46 | |
45 | |
47 | $self->{fh} = $fh; |
46 | $self->{fh} = $fh; |
48 | |
47 | |
49 | $self->{pid} = open $fh, "-|"; |
48 | open $fh, "+<", "/dev/lirc" |
50 | if ($self->{pid} == 0) { |
49 | or die "/dev/lirc: $!"; |
51 | select STDOUT; $|=1; |
|
|
52 | eval { |
|
|
53 | $SIG{HUP} = sub { _exit }; |
|
|
54 | lirc_init($prog) >= 0 or croak "unable to connect to lircd: $!"; |
|
|
55 | lirc_readconfig();# == 0 or croak "unable to read lirc configuration for <$prog>: $!\n"; |
|
|
56 | print "I\x00"; |
|
|
57 | for(;;) { |
|
|
58 | my ($raw, $cooked) = _get_code; |
|
|
59 | print "=".Time::HiRes::time."\x01$raw\x01$cooked\x00"; |
|
|
60 | } |
|
|
61 | }; |
|
|
62 | if ($@) { |
|
|
63 | $@ =~ s/\x00/\x01/g; |
|
|
64 | print "E$@\x00"; |
|
|
65 | } |
|
|
66 | #lirc_freeconfig; |
|
|
67 | #lirc_deinit; |
|
|
68 | POSIX::_exit(0); |
|
|
69 | } elsif (!defined $self->{pid}) { |
|
|
70 | die; |
|
|
71 | } |
|
|
72 | |
|
|
73 | $self->get; # wait for I packet |
|
|
74 | |
50 | |
75 | $self; |
51 | $self |
76 | } |
52 | } |
77 | |
53 | |
78 | sub fd { |
54 | sub fd { |
79 | fileno $_[0]->{fh}; |
55 | fileno $_[0]->{fh}; |
80 | } |
56 | } |