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 *****************************************************************************/
35 #include <vlc_interface.h>
38 #include <lirc/lirc_client.h>
40 #define LIRC_TEXT N_("Change the lirc configuration file.")
41 #define LIRC_LONGTEXT N_( \
42 "Tell lirc to read this configuration file. By default it " \
43 "searches in the users home directory." )
45 /*****************************************************************************
46 * intf_sys_t: description and status of FB interface
47 *****************************************************************************/
51 struct lirc_config *config;
54 /*****************************************************************************
56 *****************************************************************************/
57 static int Open ( vlc_object_t * );
58 static void Close ( vlc_object_t * );
59 static void Run ( intf_thread_t * );
61 /*****************************************************************************
63 *****************************************************************************/
65 set_shortname( _("Infrared") );
66 set_category( CAT_INTERFACE );
67 set_subcategory( SUBCAT_INTERFACE_CONTROL );
68 set_description( _("Infrared remote control interface") );
69 set_capability( "interface", 0 );
70 set_callbacks( Open, Close );
72 add_string( "lirc-file", NULL, NULL,
73 LIRC_TEXT, LIRC_LONGTEXT, VLC_TRUE );
76 /*****************************************************************************
77 * Open: initialize interface
78 *****************************************************************************/
79 static int Open( vlc_object_t *p_this )
81 intf_thread_t *p_intf = (intf_thread_t *)p_this;
84 /* Allocate instance and initialize some members */
85 p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
86 if( p_intf->p_sys == NULL )
88 msg_Err( p_intf, "out of memory" );
94 p_intf->p_sys->psz_file = var_CreateGetNonEmptyString( p_intf, "lirc-file" );
96 i_fd = lirc_init( "vlc", 1 );
99 msg_Err( p_intf, "lirc initialisation failed" );
100 free( p_intf->p_sys );
104 /* We want polling */
105 fcntl( i_fd, F_SETFL, fcntl( i_fd, F_GETFL ) | O_NONBLOCK );
107 if( lirc_readconfig( p_intf->p_sys->psz_file, &p_intf->p_sys->config, NULL ) != 0 )
109 msg_Err( p_intf, "failure while reading lirc config" );
111 free( p_intf->p_sys );
118 /*****************************************************************************
119 * Close: destroy interface
120 *****************************************************************************/
121 static void Close( vlc_object_t *p_this )
123 intf_thread_t *p_intf = (intf_thread_t *)p_this;
125 /* Destroy structure */
126 if( p_intf->p_sys->psz_file )
127 free( p_intf->p_sys->psz_file );
128 lirc_freeconfig( p_intf->p_sys->config );
130 free( p_intf->p_sys );
133 /*****************************************************************************
135 *****************************************************************************/
136 static void Run( intf_thread_t *p_intf )
140 while( !intf_ShouldDie( p_intf ) )
143 msleep( INTF_IDLE_SLEEP );
145 /* We poll the lircsocket */
146 if( lirc_nextcode(&code) != 0 )
156 while( !intf_ShouldDie( p_intf )
157 && (lirc_code2char( p_intf->p_sys->config, code, &c ) == 0)
162 if( !strncmp( "key-", c, 4 ) )
164 keyval.i_int = config_GetInt( p_intf, c );
165 var_Set( p_intf->p_libvlc, "key-pressed", keyval );
167 else if( !strncmp( "menu ", c, 5) )
169 if( !strncmp( c, "menu on", 7 ) ||
170 !strncmp( c, "menu show", 9 ))
171 osd_MenuShow( VLC_OBJECT(p_intf) );
172 else if( !strncmp( c, "menu off", 8 ) ||
173 !strncmp( c, "menu hide", 9 ) )
174 osd_MenuHide( VLC_OBJECT(p_intf) );
175 else if( !strncmp( c, "menu up", 7 ) )
176 osd_MenuUp( VLC_OBJECT(p_intf) );
177 else if( !strncmp( c, "menu down", 9 ) )
178 osd_MenuDown( VLC_OBJECT(p_intf) );
179 else if( !strncmp( c, "menu left", 9 ) )
180 osd_MenuPrev( VLC_OBJECT(p_intf) );
181 else if( !strncmp( c, "menu right", 10 ) )
182 osd_MenuNext( VLC_OBJECT(p_intf) );
183 else if( !strncmp( c, "menu select", 11 ) )
184 osd_MenuActivate( VLC_OBJECT(p_intf) );
187 msg_Err( p_intf, _("Please provide one of the following parameters:") );
188 msg_Err( p_intf, "[on|off|up|down|left|right|select]" );
194 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" );