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 *****************************************************************************/
27 #include <stdlib.h> /* malloc(), free() */
33 #include <vlc_interface.h>
35 #include <lirc/lirc_client.h>
37 /*****************************************************************************
38 * intf_sys_t: description and status of FB interface
39 *****************************************************************************/
42 struct lirc_config *config;
45 /*****************************************************************************
47 *****************************************************************************/
48 static int Open ( vlc_object_t * );
49 static void Close ( vlc_object_t * );
50 static void Run ( intf_thread_t * );
52 /*****************************************************************************
54 *****************************************************************************/
56 set_category( CAT_INTERFACE );
57 set_subcategory( SUBCAT_INTERFACE_CONTROL );
58 set_description( _("Infrared remote control interface") );
59 set_capability( "interface", 0 );
60 set_callbacks( Open, Close );
63 /*****************************************************************************
64 * Open: initialize interface
65 *****************************************************************************/
66 static int Open( vlc_object_t *p_this )
68 intf_thread_t *p_intf = (intf_thread_t *)p_this;
71 /* Allocate instance and initialize some members */
72 p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
73 if( p_intf->p_sys == NULL )
75 msg_Err( p_intf, "out of memory" );
81 i_fd = lirc_init( "vlc", 1 );
84 msg_Err( p_intf, "lirc initialisation failed" );
85 free( p_intf->p_sys );
90 fcntl( i_fd, F_SETFL, fcntl( i_fd, F_GETFL ) | O_NONBLOCK );
92 if( lirc_readconfig( NULL, &p_intf->p_sys->config, NULL ) != 0 )
94 msg_Err( p_intf, "failure while reading lirc config" );
96 free( p_intf->p_sys );
103 /*****************************************************************************
104 * Close: destroy interface
105 *****************************************************************************/
106 static void Close( vlc_object_t *p_this )
108 intf_thread_t *p_intf = (intf_thread_t *)p_this;
110 /* Destroy structure */
111 lirc_freeconfig( p_intf->p_sys->config );
113 free( p_intf->p_sys );
116 /*****************************************************************************
118 *****************************************************************************/
119 static void Run( intf_thread_t *p_intf )
123 while( !intf_ShouldDie( p_intf ) )
126 msleep( INTF_IDLE_SLEEP );
128 /* We poll the lircsocket */
129 if( lirc_nextcode(&code) != 0 )
139 while( !intf_ShouldDie( p_intf )
140 && lirc_code2char( p_intf->p_sys->config, code, &c ) == 0
145 if( strncmp( "key-", c, 4 ) )
147 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" );
150 keyval.i_int = config_GetInt( p_intf, c );
151 var_Set( p_intf->p_libvlc, "key-pressed", keyval );