|
View:
New views
5 Messages
—
Rating Filter:
Alert me
|
|
|
Send IR commands using pronto codes directly with lircHi,
I wrote some... enhancements to lircd last night to allow sending of IR signals using Pronto codes directly, bypassing the configuration file. I attach the patch for review and possible usage by others. It's definitely not clean, but it's a start. I tried making it cleaner, but I failed. The patch is against the Ubuntu 7.10 LIRC sources (0.8.2-0ubuntu8), but chances are it will work with newer sources as well. I tested it with a mceusb2 device and a remote from my 5.1 audio system with no specific encoding (raw codes). After you build a new lircd daemon with these changes, you can send IR signals like this: $ irsend SEND_PRONTO "0000006D0000000C00300011003000110030001100100031003000110010003100300011001000310010003100100031001000310010053a" "" The spaces from the Pronto code have to be removed, because lircd uses spaces as internal argument separators and the code would have been more complex, and the last parameter, the void one, is needed by irsend, and it complains without it. I accomplish this by creating a pseudo-remote (struct ir_remote), one that has just parameters and no codes. This pseudo-remote is created inside the daemon. I started with it in the lircd.conf file, but moved it inside the code so it's always present and to simplify matters from a user point of view. The pseudo-remote is allocated once when the first pronto code is transmitted, and then it's reused. The IR signal (struct ir_ncode) resulted from the Pronto code is allocated dinamically, and its freed upon reuse (I guess this part of code could look better). To clean it up, I tried adding the pseudo-remote in the remote list directly in daemons/config_file.c and moving the pronto parsing into the get_ir_code function in daemons/ir_remote.c. For some reason things stopped working, and being an all nighter, I said I'll give it another try later. In the mean time, enjoy the new functionality. I'm sure there are other people out there wanting this. PS. Let me know if it has already been done, because the closest thing I could find on Google was some intent on writing a program for generating lircd.conf settings from Pronto codes. diff -r 7319c019ca3d -r 056b9ad27208 daemons/lircd.c --- a/daemons/lircd.c Mon Jan 07 23:27:49 2008 +0200 +++ b/daemons/lircd.c Tue Jan 08 03:47:52 2008 +0200 @@ -111,6 +111,7 @@ struct protocol_directive directives[] = {"SEND_STOP",send_stop}, {"VERSION",version}, {"SET_TRANSMITTERS",set_transmitters}, + {"SEND_PRONTO",send_pronto}, {NULL,NULL} /* {"DEBUG",debug}, @@ -1015,10 +1016,69 @@ void dosigalrm(int sig) } } +static struct ir_remote *ProntoIRSenderPseudoRemote() +{ + static struct ir_remote *ProntoRemote=NULL; + + if(ProntoRemote==NULL) + { + ProntoRemote=(struct ir_remote *)malloc(sizeof(struct ir_remote)); + memset(ProntoRemote,0,sizeof(struct ir_remote)); + ProntoRemote->name=strdup("ProntoIRSenderPseudoRemote"); + ProntoRemote->flags=RAW_CODES; + ProntoRemote->eps=30; + ProntoRemote->aeps=100; + ProntoRemote->gap=34937; + ProntoRemote->min_repeat=2; + } + + return ProntoRemote; +} + +static int parse_pronto(char *pronto,struct ir_ncode *code,struct ir_remote *remote) +{ + int length=strlen(pronto); + if(length%4!=0||length<16) + return 0; + + int value; + sscanf(pronto,"%4x",&value); // code type + if(value!=0&&value!=256) + return 0; + sscanf(pronto+4,"%4x",&value); // carrier divider + long int frequency=((41450/value+5)/10)*1000; // carrier frequency in Hz + remote->freq=frequency; + + int single_count, repeat_count; + sscanf(pronto+8,"%4x",&single_count); + sscanf(pronto+12,"%4x",&repeat_count); + + pronto+=16; + code->length=strlen(pronto)/4; + code->signals=(lirc_t*)malloc(code->length*sizeof(lirc_t)); + lirc_t *current_signal=code->signals; + + int i; + for(i=0;i<2*(single_count+repeat_count);++i,pronto+=4,++current_signal) + { + sscanf(pronto,"%4x",&value); + *current_signal=1000000*value/frequency; // pulse/space duration in microseconds + } + return 1; +} + int parse_rc(int fd,char *message,char *arguments,struct ir_remote **remote, struct ir_ncode **code,int *reps,int n) { char *name=NULL,*command=NULL,*repeats,*end_ptr=NULL; + static struct ir_ncode *pronto_code=NULL; + + if (pronto_code!=NULL) + { + free(pronto_code->signals); + free(pronto_code); + pronto_code=NULL; + } *remote=NULL; *code=NULL; @@ -1026,7 +1086,10 @@ int parse_rc(int fd,char *message,char * name=strtok(arguments,WHITE_SPACE); if(name==NULL) return(1); - *remote=get_ir_remote(remotes,name); + if(strcasecmp(name,"ProntoIRSenderPseudoRemote")==0) + *remote=ProntoIRSenderPseudoRemote(); + else + *remote=get_ir_remote(remotes,name); if(*remote==NULL) { return(send_error(fd,message,"unknown remote: \"%s\"\n", @@ -1034,7 +1097,17 @@ int parse_rc(int fd,char *message,char * } command=strtok(NULL,WHITE_SPACE); if(command==NULL) return(1); - *code=get_ir_code(*remote,command); + + if(strcasecmp((*remote)->name,"ProntoIRSenderPseudoRemote")==0) + { + pronto_code=(struct ir_ncode*)malloc(sizeof(struct ir_ncode)); + memset(pronto_code,0,sizeof(struct ir_ncode)); + if(!parse_pronto(command, pronto_code, *remote)) + return(send_error(fd,message,"invalid or unsupported pronto code\n")); + *code=pronto_code; + } + else + *code=get_ir_code(*remote,command); if(*code==NULL) { return(send_error(fd,message,"unknown command: \"%s\"\n", @@ -1474,6 +1547,17 @@ int version(int fd,char *message,char *a write_socket_len(fd,buffer) && write_socket_len(fd,protocol_string[P_END]))) return(0); return(1); +} + +int send_pronto(int fd,char *message,char *arguments) +{ + if (arguments==NULL) + return(send_error(fd,message,"bad send packet\n")); + char *new_arguments=(char*)malloc(strlen(arguments)+strlen("ProntoIRSenderPseudoRemote ") + 1); + sprintf(new_arguments,"ProntoIRSenderPseudoRemote %s",arguments); + int ret=send_core(fd,message,new_arguments,1); + free(new_arguments); + return(ret); } int get_command(int fd) diff -r 7319c019ca3d -r 056b9ad27208 daemons/lircd.h --- a/daemons/lircd.h Mon Jan 07 23:27:49 2008 +0200 +++ b/daemons/lircd.h Tue Jan 08 03:47:52 2008 +0200 @@ -73,6 +73,7 @@ int send_stop(int fd,char *message,char int send_stop(int fd,char *message,char *arguments); int send_core(int fd,char *message,char *arguments,int once); int version(int fd,char *message,char *arguments); +int send_pronto(int fd,char *message,char *arguments); int get_pid(int fd,char *message,char *arguments); int get_command(int fd); void broadcast_message(const char *message); diff -r 7319c019ca3d -r 056b9ad27208 debian/changelog --- a/debian/changelog Mon Jan 07 23:27:49 2008 +0200 +++ b/debian/changelog Tue Jan 08 03:47:52 2008 +0200 @@ -1,3 +1,9 @@ lirc (0.8.2-0ubuntu8) gutsy; urgency=low +lirc (0.8.2-0ubuntu8radu1) gutsy; urgency=low + + * Added Philips Pronto IR code format support + + -- Radu Cristescu <radu.c@...> Mon, 07 Jan 2008 23:30:33 +0200 + lirc (0.8.2-0ubuntu8) gutsy; urgency=low * Add 22_hauppauge_novat_500.dpatch for more complete ------------------------------------------------------------------------- Check out the new SourceForge.net Marketplace. It's the best place to buy or sell services for just about anything Open Source. http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace |
|
|
Re: Send IR commands using pronto codes directly with lircHi!
Uplink "advantis@..." wrote: > I wrote some... enhancements to lircd last night to allow sending of IR > signals using Pronto codes directly, bypassing the configuration file. I [...] > PS. Let me know if it has already been done, because the closest thing I > could find on Google was some intent on writing a program for generating > lircd.conf settings from Pronto codes. Why didn't you try creating such a converter? Would be much cleaner. Christoph ------------------------------------------------------------------------- Check out the new SourceForge.net Marketplace. It's the best place to buy or sell services for just about anything Open Source. http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace |
|
|
Re: Send IR commands using pronto codes directly with lircChristoph Bartelmus wrote:
> PS. Let me know if it has already been done, because the closest thing I >> could find on Google was some intent on writing a program for generating >> lircd.conf settings from Pronto codes. >> > > Why didn't you try creating such a converter? Would be much cleaner. > Sorry for the delay in reply. I find such a lircd.conf generator inefficient. I my case, I have a big database of pronto codes for different devices and putting all of them in lircd.conf would generate a big config file. Then, each time I'd learn a new code, I'd have to regenerate lircd.conf. Now, if I were to go the lircd.conf generation way, I'd still have to account for a noticeable memory usage increase in lircd, right? That's why I made this the way I did, so I can send any pronto code I want, whenever I want, without reconfiguring and reloading lirc. ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ |
|
|
Re: Send IR commands using pronto codes directly with lircHi!
Uplink "advantis@..." wrote: [...] > Christoph Bartelmus wrote: >> PS. Let me know if it has already been done, because the closest thing I >>> could find on Google was some intent on writing a program for generating >>> lircd.conf settings from Pronto codes. >> >> Why didn't you try creating such a converter? Would be much cleaner. > > I find such a lircd.conf generator inefficient. I my case, I have a big > database of pronto codes for different devices and putting all of them > in lircd.conf would generate a big config file. Then, each time I'd > learn a new code, I'd have to regenerate lircd.conf. Now, if I were to > go the lircd.conf generation way, I'd still have to account for a > noticeable memory usage increase in lircd, right? That's why I made this > the way I did, so I can send any pronto code I want, whenever I want, > without reconfiguring and reloading lirc. It seems that your use case is quite uncommon. Of how many devices are we talking? 10, 100, 1000? I wouldn't care much about memory usage for 10. 100 should work too. I can't think of a use case where one would need 1000 devices. I don't know much about the pronto file format, but LIRC has a method to store the codes very efficiently, not having to store the pulse sequence for each key. Christoph ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ |
|
|
Re: Send IR commands using pronto codes directly with lirc Hi Uplink-2,
I'm really interested in your solution since i've been looking for this for a while. Did you make any progress on this since ? I tried patching the Ubuntu 7.10 LIRC sources (0.8.2-0ubuntu8) but i get rejects all over the place. patch -p0 < lirc-pronto.patch patching file a/daemons/lircd.c Hunk #1 FAILED at 111. Hunk #2 FAILED at 1016. Hunk #3 FAILED at 1086. Hunk #4 FAILED at 1097. Hunk #5 FAILED at 1547. 5 out of 5 hunks FAILED -- saving rejects to file a/daemons/lircd.c.rej patching file a/daemons/lircd.h patching file a/debian/changelog Hunk #1 succeeded at 1 with fuzz 1. Could you please help, Best Regards, Rafik
|
| Free embeddable forum powered by Nabble | Forum Help |