ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/RCU/DevLirc/DevLirc.pm
(Generate patch)

Comparing RCU/DevLirc/DevLirc.pm (file contents):
Revision 1.1 by root, Sun Nov 6 17:24:32 2005 UTC vs.
Revision 1.2 by root, Sun Nov 6 18:27:31 2005 UTC

1=head1 NAME 1=head1 NAME
2 2
3RCU::Lirc - RCU interface to linux-infrared-remote-control 3RCU::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
11See L<RCU>. 11See L<RCU>.
12 12
13=over 4 13=over 4
14 14
15=cut 15=cut
16 16
17package RCU::Lirc; 17package RCU::DevLirc;
18 18
19use DynaLoader; 19use DynaLoader;
20use Carp; 20use Carp;
21use POSIX (); 21use POSIX ();
22use Time::HiRes (); 22use Time::HiRes ();
27 27
28use base qw(RCU::Interface DynaLoader); 28use base qw(RCU::Interface DynaLoader);
29 29
30BEGIN { 30BEGIN {
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
37Create an interface to lircd using the configuration for program "progname". 37Create an interface to /dev/lirc.
38 38
39=cut 39=cut
40 40
41sub new { 41sub 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
78sub fd { 54sub fd {
79 fileno $_[0]->{fh}; 55 fileno $_[0]->{fh};
80} 56}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines