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