Hello teachers,

 I'm converting a simple perl multimedia script to an event based one, but it 
seems that I'm missing something very basic because I'm unable to make it work.
The script receives commands from Lirc::Client (1.54) via next_codes() which is 
in blocking state whilst no data is available.

Now I think I need AnyEvent::IO but the script halts the event loop waiting for 
next_codes 

#!/usr/bin/perl
 use strict;
 use warnings;
 use 5.010;
 use Lirc::Client;
 use AnyEvent;
  
 my $lirc = Lirc::Client->new( {    
              prog    => 'perl-client',
              rcfile  => "$ENV{HOME}/.lircrc",
              dev     => "/var/run/lirc/lircd",
              debug   => 0,
              fake    => 0,
       } );
 
 my $ready = AnyEvent->condvar;
 my $command ; $command = AnyEvent->io (
   fh   => $lirc->next_codes,
    poll => "r",
    cb   => sub {
       say "key: ".$lirc->nextcode;
    }
 );
 
 while (1){
   system("date");
   sleep 1;
   AnyEvent->condvar->recv;
 };
with the above code I only get the date, but not the pressed key, each time I 
press a button in the remote.

$ ./test-lirc.pl 
 Wed Mar  9 20:53:59 CET 2016
 ^C
 

switching "fh => $lirc->next_codes" by "fh => $lirc->socket" (unprocessed raw 
events) I get only the date one time and the keys pressed in the remote.
 
 $ ./test-lirc4.pl 
 Wed Mar  9 20:51:31 CET 2016
 key: VOLUMEDOWN
 key: VOLUMEUP
 key: VOLUMEUP
 ^C
 
 
 is there any way to make work this? Any clue will be welcome.
 
 
 # ~/.lircrc 
 begin
         prog    = perl-client
         remote  = generic-ir
         button  = KEY_VOLUMEDOWN
         config  = VOLUMEDOWN
         repeat  = 2
 end
 
 begin
         prog    = perl-client
         remote  = generic-ir
         button  = KEY_VOLUMEUP
         config  = VOLUMEUP
         repeat  = 2
 end
 

Reply via email to