1
|
1 /*
|
|
2
|
|
3 lirc support for MPLayer (see www.lirc.org)
|
|
4
|
|
5 v0.1
|
|
6
|
|
7 written 15/2/2001 by Andreas Ackermann (acki@acki-netz.de)
|
|
8
|
|
9 file comes without warranty and all
|
|
10
|
|
11 */
|
|
12
|
|
13 // hack, will be remove later when ./configure fixed...
|
|
14 #include "config.h"
|
|
15 #ifdef HAVE_LIRC
|
|
16
|
|
17 // start of LIRC support
|
|
18
|
|
19 #include <lirc/lirc_client.h>
|
|
20 #include <errno.h>
|
|
21 #include <stdio.h>
|
|
22 #include <sys/ioctl.h>
|
|
23 #include <string.h>
|
|
24 #include <fcntl.h>
|
|
25 #include "linux/keycodes.h"
|
|
26
|
|
27 // global stuff ----------------------------------------------------
|
|
28
|
|
29 static struct lirc_config *lirc_config;
|
|
30 static int lirc_is_setup = 0;
|
|
31
|
|
32 // setup routine ---------------------------------------------------
|
|
33
|
|
34 void lirc_mp_setup(void){
|
|
35
|
|
36 int lirc_flags;
|
|
37 int lirc_sock;
|
|
38
|
|
39 printf("Setting up lirc support...\n");
|
|
40 if((lirc_sock=lirc_init("mplayer_lirc",1))==-1){
|
|
41 printf("Failed opening lirc support!\n");
|
|
42 printf("You won't be able to use your remote control\n");
|
|
43 return;
|
|
44 }
|
|
45
|
|
46 fcntl(lirc_sock,F_SETOWN,getpid());
|
|
47 lirc_flags=fcntl(lirc_sock,F_GETFL,0);
|
|
48 if(lirc_flags!=-1)
|
|
49 {
|
|
50 fcntl(lirc_sock,F_SETFL,lirc_flags|O_NONBLOCK);
|
|
51 }else{
|
|
52 lirc_deinit();
|
|
53 printf("Something's wrong with the lirc socket: %s\n",
|
|
54 strerror(errno));
|
|
55 printf("You won't be able to use your remote control\n");
|
|
56 return;
|
|
57 }
|
|
58
|
|
59
|
|
60 if(lirc_readconfig( NULL,&lirc_config,NULL )!=0 ){
|
|
61 printf("Failed to read standard config (~/.lircrc)!\n" );
|
|
62 printf("You won't be able to use your remote control\n");
|
|
63 lirc_deinit();
|
|
64 return;
|
|
65 }
|
|
66 printf("LIRC init was successful.\n");
|
|
67 lirc_is_setup = 1;
|
|
68 }
|
|
69
|
|
70 // cleanup routine -------------------------------------------
|
|
71
|
|
72 void lirc_mp_cleanup(void){
|
|
73 if(lirc_is_setup != 0){
|
|
74 printf("Cleaning up lirc stuff.\n");
|
|
75 lirc_mp_getinput(NULL);
|
|
76 lirc_freeconfig(lirc_config);
|
|
77 lirc_deinit();
|
|
78 lirc_is_setup = 0;
|
|
79 }
|
|
80 }
|
|
81
|
|
82 // get some events -------------------------------------------
|
|
83
|
|
84
|
|
85 struct lirc_cmd {
|
|
86 unsigned char *lc_lirccmd;
|
|
87 int mplayer_cmd;
|
|
88 };
|
|
89
|
|
90 int lirc_mp_getinput(){
|
|
91
|
|
92 static struct lirc_cmd lirc_cmd[] = {
|
|
93 {"QUIT", KEY_ESC},
|
|
94 {"FWD" , KEY_RIGHT},
|
|
95 {"FFWD" , KEY_UP},
|
|
96 {"RWND" , KEY_LEFT},
|
|
97 {"FRWND" , KEY_DOWN},
|
|
98 {"PAUSE", 'p'}
|
|
99 };
|
|
100
|
|
101 char *code;
|
|
102 char *c;
|
|
103 int ret;
|
|
104 int i;
|
|
105 int retval = 0;
|
|
106
|
|
107 if( lirc_is_setup == 0)return 0;
|
|
108
|
|
109 if(lirc_config == NULL ){
|
|
110 // do some cleanupstuff like freeing memory or the like
|
|
111 // (if we ever should do it the right way and loop over all
|
|
112 // all strings delivered by lirc_code2char() )
|
|
113 }else{
|
|
114
|
|
115 if(lirc_nextcode(&code)==0){
|
|
116 if(code!=NULL){
|
|
117 // this should be a while loop
|
|
118 // but we would have to introduce state since we need to keep
|
|
119 // code
|
|
120 if((ret=lirc_code2char(lirc_config,code,&c))==0 && c!=NULL){
|
|
121 fprintf(stderr, "LIRC: Got string \"%s\"",c);
|
|
122 for(i=0; i< (sizeof(lirc_cmd)/sizeof(struct lirc_cmd)); i++){
|
|
123 if(!(strcmp(lirc_cmd[i].lc_lirccmd, c))){
|
|
124 retval = lirc_cmd[i].mplayer_cmd;
|
|
125 break;
|
|
126 }
|
|
127
|
|
128 }
|
|
129 }
|
|
130 free(code);
|
|
131 if(ret==-1){
|
|
132 printf("LIRC: lirc_code2char() returned an error!\n");
|
|
133 }
|
|
134 }
|
|
135 }
|
|
136 }
|
|
137 return retval;
|
|
138 }
|
|
139
|
|
140 // end lirc support
|
|
141
|
|
142 #endif // HAVE_LIRC
|
|
143
|