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},
|
462
|
98 {"PAUSE", 'p'},
|
|
99 {"INCVOL", '*'},
|
|
100 {"DECVOL", '/'},
|
|
101 {"MASTER", 'm'},
|
|
102 {"PCM", 'c'}
|
1
|
103 };
|
|
104
|
|
105 char *code;
|
|
106 char *c;
|
|
107 int ret;
|
|
108 int i;
|
|
109 int retval = 0;
|
|
110
|
|
111 if( lirc_is_setup == 0)return 0;
|
|
112
|
|
113 if(lirc_config == NULL ){
|
|
114 // do some cleanupstuff like freeing memory or the like
|
|
115 // (if we ever should do it the right way and loop over all
|
|
116 // all strings delivered by lirc_code2char() )
|
|
117 }else{
|
|
118
|
|
119 if(lirc_nextcode(&code)==0){
|
|
120 if(code!=NULL){
|
|
121 // this should be a while loop
|
|
122 // but we would have to introduce state since we need to keep
|
|
123 // code
|
|
124 if((ret=lirc_code2char(lirc_config,code,&c))==0 && c!=NULL){
|
|
125 fprintf(stderr, "LIRC: Got string \"%s\"",c);
|
|
126 for(i=0; i< (sizeof(lirc_cmd)/sizeof(struct lirc_cmd)); i++){
|
|
127 if(!(strcmp(lirc_cmd[i].lc_lirccmd, c))){
|
|
128 retval = lirc_cmd[i].mplayer_cmd;
|
|
129 break;
|
|
130 }
|
|
131
|
|
132 }
|
|
133 }
|
|
134 free(code);
|
|
135 if(ret==-1){
|
|
136 printf("LIRC: lirc_code2char() returned an error!\n");
|
|
137 }
|
|
138 }
|
|
139 }
|
|
140 }
|
|
141 return retval;
|
|
142 }
|
|
143
|
|
144 // end lirc support
|
|
145
|
|
146 #endif // HAVE_LIRC
|
|
147
|