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>
39 #include <lirc/lirc_client.h>
41 #define LIRC_TEXT N_("Change the lirc configuration file.")
42 #define LIRC_LONGTEXT N_( \
43 "Tell lirc to read this configuration file. By default it " \
44 "searches in the users home directory." )
46 /*****************************************************************************
47 * intf_sys_t: description and status of FB interface
48 *****************************************************************************/
52 struct lirc_config *config;
55 /*****************************************************************************
57 *****************************************************************************/
58 static int Open ( vlc_object_t * );
59 static void Close ( vlc_object_t * );
60 static void Run ( intf_thread_t * );
62 /*****************************************************************************
64 *****************************************************************************/
66 set_shortname( N_("Infrared") );
67 set_category( CAT_INTERFACE );
68 set_subcategory( SUBCAT_INTERFACE_CONTROL );
69 set_description( N_("Infrared remote control interface") );
70 set_capability( "interface", 0 );
71 set_callbacks( Open, Close );
73 add_string( "lirc-file", NULL, NULL,
74 LIRC_TEXT, LIRC_LONGTEXT, true );
77 /*****************************************************************************
78 * Open: initialize interface
79 *****************************************************************************/
80 static int Open( vlc_object_t *p_this )
82 intf_thread_t *p_intf = (intf_thread_t *)p_this;
85 /* Allocate instance and initialize some members */
86 p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
87 if( p_intf->p_sys == NULL )
89 msg_Err( p_intf, "out of memory" );
95 p_intf->p_sys->psz_file = var_CreateGetNonEmptyString( p_intf, "lirc-file" );
97 i_fd = lirc_init( "vlc", 1 );
100 msg_Err( p_intf, "lirc initialisation failed" );
101 free( p_intf->p_sys->psz_file );
102 free( p_intf->p_sys );
106 /* We want polling */
107 fcntl( i_fd, F_SETFL, fcntl( i_fd, F_GETFL ) | O_NONBLOCK );
109 if( lirc_readconfig( p_intf->p_sys->psz_file, &p_intf->p_sys->config, NULL ) != 0 )
111 msg_Err( p_intf, "failure while reading lirc config" );
113 free( p_intf->p_sys->psz_file );
114 free( p_intf->p_sys );
121 /*****************************************************************************
122 * Close: destroy interface
123 *****************************************************************************/
124 static void Close( vlc_object_t *p_this )
126 intf_thread_t *p_intf = (intf_thread_t *)p_this;
128 /* Destroy structure */
129 free( p_intf->p_sys->psz_file );
130 lirc_freeconfig( p_intf->p_sys->config );
132 free( p_intf->p_sys );
135 /*****************************************************************************
137 *****************************************************************************/
138 static void Run( intf_thread_t *p_intf )
142 while( !intf_ShouldDie( p_intf ) )
145 msleep( INTF_IDLE_SLEEP );
147 /* We poll the lircsocket */
148 if( lirc_nextcode(&code) != 0 )
158 while( !intf_ShouldDie( p_intf )
159 && (lirc_code2char( p_intf->p_sys->config, code, &c ) == 0)
164 if( !strncmp( "key-", c, 4 ) )
166 keyval.i_int = config_GetInt( p_intf, c );
167 var_Set( p_intf->p_libvlc, "key-pressed", keyval );
169 else if( !strncmp( "menu ", c, 5) )
171 if( !strncmp( c, "menu on", 7 ) ||
172 !strncmp( c, "menu show", 9 ))
173 osd_MenuShow( VLC_OBJECT(p_intf) );
174 else if( !strncmp( c, "menu off", 8 ) ||
175 !strncmp( c, "menu hide", 9 ) )
176 osd_MenuHide( VLC_OBJECT(p_intf) );
177 else if( !strncmp( c, "menu up", 7 ) )
178 osd_MenuUp( VLC_OBJECT(p_intf) );
179 else if( !strncmp( c, "menu down", 9 ) )
180 osd_MenuDown( VLC_OBJECT(p_intf) );
181 else if( !strncmp( c, "menu left", 9 ) )
182 osd_MenuPrev( VLC_OBJECT(p_intf) );
183 else if( !strncmp( c, "menu right", 10 ) )
184 osd_MenuNext( VLC_OBJECT(p_intf) );
185 else if( !strncmp( c, "menu select", 11 ) )
186 osd_MenuActivate( VLC_OBJECT(p_intf) );
189 msg_Err( p_intf, _("Please provide one of the following parameters:") );
190 msg_Err( p_intf, "[on|off|up|down|left|right|select]" );
196 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" );