annotate lirc_mp.c @ 5405:c7455d4079ae

using interleaveBytes() for G200 draw_slice
author arpi
date Sat, 30 Mar 2002 17:40:22 +0000
parents d25b898c4c44
children
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"
1990
7858bc1b360d fixed (thx,. Dirk Vornheder)
arpi
parents: 1973
diff changeset
15
4823
d25b898c4c44 Make old and new lirc support independant from each other
albeu
parents: 2122
diff changeset
16 #if defined(HAVE_LIRC) && ! defined (HAVE_NEW_INPUT)
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
17
1990
7858bc1b360d fixed (thx,. Dirk Vornheder)
arpi
parents: 1973
diff changeset
18 #include "mp_msg.h"
7858bc1b360d fixed (thx,. Dirk Vornheder)
arpi
parents: 1973
diff changeset
19 #include "help_mp.h"
7858bc1b360d fixed (thx,. Dirk Vornheder)
arpi
parents: 1973
diff changeset
20
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
21 // start of LIRC support
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
22
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
23 #include <lirc/lirc_client.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
24 #include <errno.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
25 #include <stdio.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
26 #include <sys/ioctl.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
27 #include <string.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
28 #include <fcntl.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
29 #include "linux/keycodes.h"
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
30
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
31 // global stuff ----------------------------------------------------
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
32
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
33 static struct lirc_config *lirc_config;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
34 static int lirc_is_setup = 0;
1149
6a0f937b52e6 - new config option -lircconfig (config file for lirc)
acki2
parents: 593
diff changeset
35 char *lirc_configfile = NULL;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
36
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
37 // setup routine ---------------------------------------------------
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
38
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
39 void lirc_mp_setup(void){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
40
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
41 int lirc_flags;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
42 int lirc_sock;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
43
1973
5216f108cb4f all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents: 1167
diff changeset
44 mp_msg(MSGT_LIRC,MSGL_INFO,MSGTR_SettingUpLIRC);
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
45 if((lirc_sock=lirc_init("mplayer_lirc",1))==-1){
1973
5216f108cb4f all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents: 1167
diff changeset
46 mp_msg(MSGT_LIRC,MSGL_ERR,MSGTR_LIRCopenfailed MSGTR_LIRCdisabled);
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
47 return;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
48 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
49
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
50 fcntl(lirc_sock,F_SETOWN,getpid());
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
51 lirc_flags=fcntl(lirc_sock,F_GETFL,0);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
52 if(lirc_flags!=-1)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
53 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
54 fcntl(lirc_sock,F_SETFL,lirc_flags|O_NONBLOCK);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
55 }else{
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
56 lirc_deinit();
1973
5216f108cb4f all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents: 1167
diff changeset
57 mp_msg(MSGT_LIRC,MSGL_ERR,MSGTR_LIRCsocketerr MSGTR_LIRCdisabled,strerror(errno));
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
58 return;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
59 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
60
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
61
1149
6a0f937b52e6 - new config option -lircconfig (config file for lirc)
acki2
parents: 593
diff changeset
62 if(lirc_readconfig( lirc_configfile,&lirc_config,NULL )!=0 ){
1973
5216f108cb4f all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents: 1167
diff changeset
63 mp_msg(MSGT_LIRC,MSGL_ERR,MSGTR_LIRCcfgerr MSGTR_LIRCdisabled,
1149
6a0f937b52e6 - new config option -lircconfig (config file for lirc)
acki2
parents: 593
diff changeset
64 lirc_configfile == NULL ? "~/.lircrc" : lirc_configfile);
1
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 }
1973
5216f108cb4f all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents: 1167
diff changeset
68 mp_msg(MSGT_LIRC,MSGL_V,"LIRC init was successful.\n");
1
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){
1973
5216f108cb4f all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents: 1167
diff changeset
76 mp_msg(MSGT_LIRC,MSGL_V,"Cleaning up lirc stuff.\n");
1
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 }
2122
cc9d4e489a0d keypress fix by M.Hunold@t-online.de (Michael Hunold)
arpi
parents: 1990
diff changeset
138 // the lirc support is "broken by design": (see mailing list discussion)
cc9d4e489a0d keypress fix by M.Hunold@t-online.de (Michael Hunold)
arpi
parents: 1990
diff changeset
139 // we only accept one command at each call of this subroutine, but the
cc9d4e489a0d keypress fix by M.Hunold@t-online.de (Michael Hunold)
arpi
parents: 1990
diff changeset
140 // "lirc_code2char()" function should be called in a loop
cc9d4e489a0d keypress fix by M.Hunold@t-online.de (Michael Hunold)
arpi
parents: 1990
diff changeset
141 // until it reports "empty"... (see lirc documentation)
cc9d4e489a0d keypress fix by M.Hunold@t-online.de (Michael Hunold)
arpi
parents: 1990
diff changeset
142 // so we need to flush the lirc command queue after we processed one
cc9d4e489a0d keypress fix by M.Hunold@t-online.de (Michael Hunold)
arpi
parents: 1990
diff changeset
143 // command. of course we report if we really lose a message.
cc9d4e489a0d keypress fix by M.Hunold@t-online.de (Michael Hunold)
arpi
parents: 1990
diff changeset
144 while((ret=lirc_code2char(lirc_config,code,&c))==0 && c!=NULL){
cc9d4e489a0d keypress fix by M.Hunold@t-online.de (Michael Hunold)
arpi
parents: 1990
diff changeset
145 fprintf(stderr, "LIRC: lost command \"%s\"",c);
cc9d4e489a0d keypress fix by M.Hunold@t-online.de (Michael Hunold)
arpi
parents: 1990
diff changeset
146 }
cc9d4e489a0d keypress fix by M.Hunold@t-online.de (Michael Hunold)
arpi
parents: 1990
diff changeset
147
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
148 free(code);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
149 if(ret==-1){
1973
5216f108cb4f all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents: 1167
diff changeset
150 mp_msg(MSGT_LIRC,MSGL_V,"LIRC: lirc_code2char() returned an error!\n");
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
151 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
152 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
153 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
154 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
155 return retval;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
156 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
157
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
158 // end lirc support
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
159
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
160 #endif // HAVE_LIRC
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
161