annotate lirc_mp.c @ 480:787f2792beeb

now it accepts monitor_hfreq...
author szabii
date Mon, 16 Apr 2001 22:13:12 +0000
parents 31b9f60a9d9d
children b847d7cba966
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;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
31
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
32 // setup routine ---------------------------------------------------
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
33
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
34 void lirc_mp_setup(void){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
35
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
36 int lirc_flags;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
37 int lirc_sock;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
38
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
39 printf("Setting up lirc support...\n");
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
40 if((lirc_sock=lirc_init("mplayer_lirc",1))==-1){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
41 printf("Failed opening lirc support!\n");
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
42 printf("You won't be able to use your remote control\n");
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
43 return;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
44 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
45
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
46 fcntl(lirc_sock,F_SETOWN,getpid());
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
47 lirc_flags=fcntl(lirc_sock,F_GETFL,0);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
48 if(lirc_flags!=-1)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
49 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
50 fcntl(lirc_sock,F_SETFL,lirc_flags|O_NONBLOCK);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
51 }else{
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
52 lirc_deinit();
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
53 printf("Something's wrong with the lirc socket: %s\n",
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
54 strerror(errno));
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
55 printf("You won't be able to use your remote control\n");
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
56 return;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
57 }
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 if(lirc_readconfig( NULL,&lirc_config,NULL )!=0 ){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
61 printf("Failed to read standard config (~/.lircrc)!\n" );
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
62 printf("You won't be able to use your remote control\n");
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
63 lirc_deinit();
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
64 return;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
65 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
66 printf("LIRC init was successful.\n");
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
67 lirc_is_setup = 1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
68 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
69
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
70 // cleanup routine -------------------------------------------
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
71
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
72 void lirc_mp_cleanup(void){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
73 if(lirc_is_setup != 0){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
74 printf("Cleaning up lirc stuff.\n");
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
75 lirc_mp_getinput(NULL);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
76 lirc_freeconfig(lirc_config);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
77 lirc_deinit();
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
78 lirc_is_setup = 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
79 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
80 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
81
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
82 // get some events -------------------------------------------
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
83
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
84
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
85 struct lirc_cmd {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
86 unsigned char *lc_lirccmd;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
87 int mplayer_cmd;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
88 };
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
89
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
90 int lirc_mp_getinput(){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
91
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
92 static struct lirc_cmd lirc_cmd[] = {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
93 {"QUIT", KEY_ESC},
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
94 {"FWD" , KEY_RIGHT},
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
95 {"FFWD" , KEY_UP},
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
96 {"RWND" , KEY_LEFT},
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
97 {"FRWND" , KEY_DOWN},
462
31b9f60a9d9d add mixer support
pontscho
parents: 448
diff changeset
98 {"PAUSE", 'p'},
31b9f60a9d9d add mixer support
pontscho
parents: 448
diff changeset
99 {"INCVOL", '*'},
31b9f60a9d9d add mixer support
pontscho
parents: 448
diff changeset
100 {"DECVOL", '/'},
31b9f60a9d9d add mixer support
pontscho
parents: 448
diff changeset
101 {"MASTER", 'm'},
31b9f60a9d9d add mixer support
pontscho
parents: 448
diff changeset
102 {"PCM", 'c'}
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
103 };
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
104
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
105 char *code;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
106 char *c;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
107 int ret;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
108 int i;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
109 int retval = 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
110
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
111 if( lirc_is_setup == 0)return 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
112
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
113 if(lirc_config == NULL ){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
114 // do some cleanupstuff like freeing memory or the like
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
115 // (if we ever should do it the right way and loop over all
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
116 // all strings delivered by lirc_code2char() )
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
117 }else{
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
118
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
119 if(lirc_nextcode(&code)==0){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
120 if(code!=NULL){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
121 // this should be a while loop
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
122 // but we would have to introduce state since we need to keep
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
123 // code
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
124 if((ret=lirc_code2char(lirc_config,code,&c))==0 && c!=NULL){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
125 fprintf(stderr, "LIRC: Got string \"%s\"",c);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
126 for(i=0; i< (sizeof(lirc_cmd)/sizeof(struct lirc_cmd)); i++){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
127 if(!(strcmp(lirc_cmd[i].lc_lirccmd, c))){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
128 retval = lirc_cmd[i].mplayer_cmd;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
129 break;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
130 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
131
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
132 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
133 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
134 free(code);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
135 if(ret==-1){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
136 printf("LIRC: lirc_code2char() returned an error!\n");
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
137 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
138 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
139 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
140 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
141 return retval;
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 // end lirc support
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
145
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
146 #endif // HAVE_LIRC
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
147