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>
44 #include <lirc/lirc_client.h>
46 #define LIRC_TEXT N_("Change the lirc configuration file")
47 #define LIRC_LONGTEXT N_( \
48 "Tell lirc to read this configuration file. By default it " \
49 "searches in the users home directory." )
51 /*****************************************************************************
53 *****************************************************************************/
54 static int Open ( vlc_object_t * );
55 static void Close ( vlc_object_t * );
58 set_shortname( N_("Infrared") )
59 set_category( CAT_INTERFACE )
60 set_subcategory( SUBCAT_INTERFACE_CONTROL )
61 set_description( N_("Infrared remote control interface") )
62 set_capability( "interface", 0 )
63 set_callbacks( Open, Close )
65 add_string( "lirc-file", NULL, NULL,
66 LIRC_TEXT, LIRC_LONGTEXT, true )
69 /*****************************************************************************
70 * intf_sys_t: description and status of FB interface
71 *****************************************************************************/
74 struct lirc_config *config;
79 /*****************************************************************************
81 *****************************************************************************/
82 static void Run( intf_thread_t * );
84 static void 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;
95 /* Allocate instance and initialize some members */
96 p_intf->p_sys = p_sys = malloc( sizeof( intf_sys_t ) );
100 p_intf->pf_run = Run;
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 );
112 /* Read the configuration file */
113 psz_file = var_CreateGetNonEmptyString( p_intf, "lirc-file" );
114 if( lirc_readconfig( psz_file, &p_sys->config, NULL ) != 0 )
116 msg_Err( p_intf, "failure while reading lirc config" );
125 if( p_sys->i_fd != -1 )
131 /*****************************************************************************
132 * Close: destroy interface
133 *****************************************************************************/
134 static void Close( vlc_object_t *p_this )
136 intf_thread_t *p_intf = (intf_thread_t *)p_this;
137 intf_sys_t *p_sys = p_intf->p_sys;
139 /* Destroy structure */
140 lirc_freeconfig( p_sys->config );
145 /*****************************************************************************
147 *****************************************************************************/
148 static void Run( intf_thread_t *p_intf )
150 intf_sys_t *p_sys = p_intf->p_sys;
155 struct pollfd ufd = { .fd = p_sys->i_fd, .events = POLLIN, .revents = 0 };
156 if( poll( &ufd, 1, -1 ) == -1 )
160 int canc = vlc_savecancel();
162 vlc_restorecancel(canc);
166 static void Process( intf_thread_t *p_intf )
171 if( lirc_nextcode( &code ) )
177 while( vlc_object_alive( p_intf )
178 && (lirc_code2char( p_intf->p_sys->config, code, &c ) == 0)
181 if( !strncmp( "key-", c, 4 ) )
183 vlc_key_t i_key = vlc_GetActionId( c );
185 var_SetInteger( p_intf->p_libvlc, "key-action", i_key );
187 msg_Err( p_intf, "Unknown hotkey '%s'", c );
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 "
217 "lirc sent us. Please look at the "
218 "doc/lirc/example.lirc file in VLC" );