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>
36 #include <lirc/lirc_client.h>
38 /*****************************************************************************
39 * intf_sys_t: description and status of FB interface
40 *****************************************************************************/
43 struct lirc_config *config;
46 /*****************************************************************************
48 *****************************************************************************/
49 static int Open ( vlc_object_t * );
50 static void Close ( vlc_object_t * );
51 static void Run ( intf_thread_t * );
53 /*****************************************************************************
55 *****************************************************************************/
57 set_shortname( _("Infrared") );
58 set_category( CAT_INTERFACE );
59 set_subcategory( SUBCAT_INTERFACE_CONTROL );
60 set_description( _("Infrared remote control interface") );
61 set_capability( "interface", 0 );
62 set_callbacks( Open, Close );
65 /*****************************************************************************
66 * Open: initialize interface
67 *****************************************************************************/
68 static int Open( vlc_object_t *p_this )
70 intf_thread_t *p_intf = (intf_thread_t *)p_this;
73 /* Allocate instance and initialize some members */
74 p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
75 if( p_intf->p_sys == NULL )
77 msg_Err( p_intf, "out of memory" );
83 i_fd = lirc_init( "vlc", 1 );
86 msg_Err( p_intf, "lirc initialisation failed" );
87 free( p_intf->p_sys );
92 fcntl( i_fd, F_SETFL, fcntl( i_fd, F_GETFL ) | O_NONBLOCK );
94 if( lirc_readconfig( NULL, &p_intf->p_sys->config, NULL ) != 0 )
96 msg_Err( p_intf, "failure while reading lirc config" );
98 free( p_intf->p_sys );
105 /*****************************************************************************
106 * Close: destroy interface
107 *****************************************************************************/
108 static void Close( vlc_object_t *p_this )
110 intf_thread_t *p_intf = (intf_thread_t *)p_this;
112 /* Destroy structure */
113 lirc_freeconfig( p_intf->p_sys->config );
115 free( p_intf->p_sys );
118 /*****************************************************************************
120 *****************************************************************************/
121 static void Run( intf_thread_t *p_intf )
125 while( !intf_ShouldDie( p_intf ) )
128 msleep( INTF_IDLE_SLEEP );
130 /* We poll the lircsocket */
131 if( lirc_nextcode(&code) != 0 )
141 while( !intf_ShouldDie( p_intf )
142 && (lirc_code2char( p_intf->p_sys->config, code, &c ) == 0)
147 if( !strncmp( "key-", c, 4 ) )
149 keyval.i_int = config_GetInt( p_intf, c );
150 var_Set( p_intf->p_libvlc, "key-pressed", keyval );
152 else if( !strncmp( "menu ", c, 5) )
154 if( !strncmp( c, "menu on", 7 ) ||
155 !strncmp( c, "menu show", 9 ))
156 osd_MenuShow( VLC_OBJECT(p_intf) );
157 else if( !strncmp( c, "menu off", 8 ) ||
158 !strncmp( c, "menu hide", 9 ) )
159 osd_MenuHide( VLC_OBJECT(p_intf) );
160 else if( !strncmp( c, "menu up", 7 ) )
161 osd_MenuUp( VLC_OBJECT(p_intf) );
162 else if( !strncmp( c, "menu down", 9 ) )
163 osd_MenuDown( VLC_OBJECT(p_intf) );
164 else if( !stnrcmp( c, "menu left", 9 ) )
165 osd_MenuPrev( VLC_OBJECT(p_intf) );
166 else if( !strncmp( c, "menu right", 10 ) )
167 osd_MenuNext( VLC_OBJECT(p_intf) );
168 else if( !strncmp( c, "menu select", 11 ) )
169 osd_MenuActivate( VLC_OBJECT(p_intf) );
172 msg_Err( p_intf, _("Please provide one of the following parameters:") );
173 msg_Err( p_intf, "[on|off|up|down|left|right|select]" );
179 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" );