1 /*****************************************************************************
2 * lirc.c : lirc module for vlc
3 *****************************************************************************
4 * Copyright (C) 2003-2005 the VideoLAN team
7 * Author: Sigmund Augdal Helberg <dnumgis@videolan.org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
34 #include <vlc_common.h>
35 #include <vlc_plugin.h>
36 #include <vlc_interface.h>
43 #include <lirc/lirc_client.h>
45 #define LIRC_TEXT N_("Change the lirc configuration file.")
46 #define LIRC_LONGTEXT N_( \
47 "Tell lirc to read this configuration file. By default it " \
48 "searches in the users home directory." )
50 /*****************************************************************************
52 *****************************************************************************/
53 static int Open ( vlc_object_t * );
54 static void Close ( vlc_object_t * );
57 set_shortname( N_("Infrared") );
58 set_category( CAT_INTERFACE );
59 set_subcategory( SUBCAT_INTERFACE_CONTROL );
60 set_description( N_("Infrared remote control interface") );
61 set_capability( "interface", 0 );
62 set_callbacks( Open, Close );
64 add_string( "lirc-file", NULL, NULL,
65 LIRC_TEXT, LIRC_LONGTEXT, true );
68 /*****************************************************************************
69 * intf_sys_t: description and status of FB interface
70 *****************************************************************************/
74 struct lirc_config *config;
79 /*****************************************************************************
81 *****************************************************************************/
82 static void Run( intf_thread_t * );
84 static int Process( intf_thread_t * );
86 /*****************************************************************************
87 * Open: initialize interface
88 *****************************************************************************/
89 static int Open( vlc_object_t *p_this )
91 intf_thread_t *p_intf = (intf_thread_t *)p_this;
94 /* Allocate instance and initialize some members */
95 p_intf->p_sys = p_sys = malloc( sizeof( intf_sys_t ) );
101 p_sys->psz_file = var_CreateGetNonEmptyString( p_intf, "lirc-file" );
102 p_sys->i_fd = lirc_init( "vlc", 1 );
103 if( p_sys->i_fd == -1 )
105 msg_Err( p_intf, "lirc initialisation failed" );
109 /* We want polling */
110 fcntl( p_sys->i_fd, F_SETFL, fcntl( p_sys->i_fd, F_GETFL ) | O_NONBLOCK );
113 if( lirc_readconfig( p_sys->psz_file, &p_sys->config, NULL ) != 0 )
115 msg_Err( p_intf, "failure while reading lirc config" );
122 if( p_sys->i_fd != -1 )
124 free( p_sys->psz_file );
129 /*****************************************************************************
130 * Close: destroy interface
131 *****************************************************************************/
132 static void Close( vlc_object_t *p_this )
134 intf_thread_t *p_intf = (intf_thread_t *)p_this;
135 intf_sys_t *p_sys = p_intf->p_sys;
137 /* Destroy structure */
138 lirc_freeconfig( p_sys->config );
140 free( p_sys->psz_file );
144 /*****************************************************************************
146 *****************************************************************************/
147 static void Run( intf_thread_t *p_intf )
149 intf_sys_t *p_sys = p_intf->p_sys;
154 struct pollfd ufd = { .fd = p_sys->i_fd, .events = POLLIN, .revents = 0 };
155 if( poll( &ufd, 1, -1 ) == -1 )
159 int canc = vlc_savecancel();
161 vlc_restorecancel(canc);
165 static int Process( intf_thread_t *p_intf )
170 int i_ret = lirc_nextcode( &code );
178 while( !intf_ShouldDie( p_intf )
179 && (lirc_code2char( p_intf->p_sys->config, code, &c ) == 0)
184 if( !strncmp( "key-", c, 4 ) )
186 keyval.i_int = config_GetInt( p_intf, c );
187 var_Set( p_intf->p_libvlc, "key-pressed", keyval );
189 else if( !strncmp( "menu ", c, 5) )
191 if( !strncmp( c, "menu on", 7 ) ||
192 !strncmp( c, "menu show", 9 ))
193 osd_MenuShow( VLC_OBJECT(p_intf) );
194 else if( !strncmp( c, "menu off", 8 ) ||
195 !strncmp( c, "menu hide", 9 ) )
196 osd_MenuHide( VLC_OBJECT(p_intf) );
197 else if( !strncmp( c, "menu up", 7 ) )
198 osd_MenuUp( VLC_OBJECT(p_intf) );
199 else if( !strncmp( c, "menu down", 9 ) )
200 osd_MenuDown( VLC_OBJECT(p_intf) );
201 else if( !strncmp( c, "menu left", 9 ) )
202 osd_MenuPrev( VLC_OBJECT(p_intf) );
203 else if( !strncmp( c, "menu right", 10 ) )
204 osd_MenuNext( VLC_OBJECT(p_intf) );
205 else if( !strncmp( c, "menu select", 11 ) )
206 osd_MenuActivate( VLC_OBJECT(p_intf) );
209 msg_Err( p_intf, "Please provide one of the following parameters:" );
210 msg_Err( p_intf, "[on|off|up|down|left|right|select]" );
216 msg_Err( p_intf, "this doesn't appear to be a valid keycombo lirc sent us. Please look at the doc/lirc/example.lirc file in VLC" );