Mercurial > mplayer.hg
annotate lirc_mp.c @ 1445:577061920134
ehh. duplicated GL check removed... drinkin' 10l...
author | arpi |
---|---|
date | Mon, 06 Aug 2001 00:11:41 +0000 |
parents | 37d6e98cb645 |
children | 5216f108cb4f |
rev | line source |
---|---|
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; | |
1149
6a0f937b52e6
- new config option -lircconfig (config file for lirc)
acki2
parents:
593
diff
changeset
|
31 char *lirc_configfile = NULL; |
1 | 32 |
33 // setup routine --------------------------------------------------- | |
34 | |
35 void lirc_mp_setup(void){ | |
36 | |
37 int lirc_flags; | |
38 int lirc_sock; | |
39 | |
40 printf("Setting up lirc support...\n"); | |
41 if((lirc_sock=lirc_init("mplayer_lirc",1))==-1){ | |
42 printf("Failed opening lirc support!\n"); | |
43 printf("You won't be able to use your remote control\n"); | |
44 return; | |
45 } | |
46 | |
47 fcntl(lirc_sock,F_SETOWN,getpid()); | |
48 lirc_flags=fcntl(lirc_sock,F_GETFL,0); | |
49 if(lirc_flags!=-1) | |
50 { | |
51 fcntl(lirc_sock,F_SETFL,lirc_flags|O_NONBLOCK); | |
52 }else{ | |
53 lirc_deinit(); | |
54 printf("Something's wrong with the lirc socket: %s\n", | |
55 strerror(errno)); | |
56 printf("You won't be able to use your remote control\n"); | |
57 return; | |
58 } | |
59 | |
60 | |
1149
6a0f937b52e6
- new config option -lircconfig (config file for lirc)
acki2
parents:
593
diff
changeset
|
61 if(lirc_readconfig( lirc_configfile,&lirc_config,NULL )!=0 ){ |
6a0f937b52e6
- new config option -lircconfig (config file for lirc)
acki2
parents:
593
diff
changeset
|
62 printf("Failed to read config file %s !\n", |
6a0f937b52e6
- new config option -lircconfig (config file for lirc)
acki2
parents:
593
diff
changeset
|
63 lirc_configfile == NULL ? "~/.lircrc" : lirc_configfile); |
1 | 64 printf("You won't be able to use your remote control\n"); |
65 lirc_deinit(); | |
66 return; | |
67 } | |
68 printf("LIRC init was successful.\n"); | |
69 lirc_is_setup = 1; | |
70 } | |
71 | |
72 // cleanup routine ------------------------------------------- | |
73 | |
74 void lirc_mp_cleanup(void){ | |
75 if(lirc_is_setup != 0){ | |
76 printf("Cleaning up lirc stuff.\n"); | |
77 lirc_mp_getinput(NULL); | |
78 lirc_freeconfig(lirc_config); | |
79 lirc_deinit(); | |
80 lirc_is_setup = 0; | |
81 } | |
82 } | |
83 | |
84 // get some events ------------------------------------------- | |
85 | |
86 | |
87 struct lirc_cmd { | |
88 unsigned char *lc_lirccmd; | |
89 int mplayer_cmd; | |
90 }; | |
91 | |
92 int lirc_mp_getinput(){ | |
93 | |
94 static struct lirc_cmd lirc_cmd[] = { | |
95 {"QUIT", KEY_ESC}, | |
96 {"FWD" , KEY_RIGHT}, | |
97 {"FFWD" , KEY_UP}, | |
98 {"RWND" , KEY_LEFT}, | |
99 {"FRWND" , KEY_DOWN}, | |
462 | 100 {"PAUSE", 'p'}, |
101 {"INCVOL", '*'}, | |
102 {"DECVOL", '/'}, | |
593 | 103 {"MASTER", 'm'}, |
1167
37d6e98cb645
ASYNC +- patch applied by Olli Sulopuisto <dst@iki.fi>
arpi_esp
parents:
1149
diff
changeset
|
104 {"ASYNC-", '-'}, |
37d6e98cb645
ASYNC +- patch applied by Olli Sulopuisto <dst@iki.fi>
arpi_esp
parents:
1149
diff
changeset
|
105 {"ASYNC+", '+'}, |
593 | 106 {"OSD", 'o'} |
1 | 107 }; |
108 | |
109 char *code; | |
110 char *c; | |
111 int ret; | |
112 int i; | |
113 int retval = 0; | |
114 | |
115 if( lirc_is_setup == 0)return 0; | |
116 | |
117 if(lirc_config == NULL ){ | |
118 // do some cleanupstuff like freeing memory or the like | |
119 // (if we ever should do it the right way and loop over all | |
120 // all strings delivered by lirc_code2char() ) | |
121 }else{ | |
122 | |
123 if(lirc_nextcode(&code)==0){ | |
124 if(code!=NULL){ | |
125 // this should be a while loop | |
126 // but we would have to introduce state since we need to keep | |
127 // code | |
128 if((ret=lirc_code2char(lirc_config,code,&c))==0 && c!=NULL){ | |
129 fprintf(stderr, "LIRC: Got string \"%s\"",c); | |
130 for(i=0; i< (sizeof(lirc_cmd)/sizeof(struct lirc_cmd)); i++){ | |
131 if(!(strcmp(lirc_cmd[i].lc_lirccmd, c))){ | |
132 retval = lirc_cmd[i].mplayer_cmd; | |
133 break; | |
134 } | |
135 | |
136 } | |
137 } | |
138 free(code); | |
139 if(ret==-1){ | |
140 printf("LIRC: lirc_code2char() returned an error!\n"); | |
141 } | |
142 } | |
143 } | |
144 } | |
145 return retval; | |
146 } | |
147 | |
148 // end lirc support | |
149 | |
150 #endif // HAVE_LIRC | |
151 |