Advertisment

Remote Control Linux

author-image
PCQ Bureau
New Update

The Lirc (Linux Infrared Remote Control) project provides tools to use IR (infrared) remote controls on Linux. That is, the remote can be used to move your mouse in X and launch applications. we used the remote that comes with Pinnacle’s PCTV tuner card. Remotes with other popular TV tuner cards, like AverMedia and PixelView, are also supported. The procedure for other remotes remains the same after seleting the right

drivers.

Advertisment

Set up Lirc

Create directory



Log in as root. Copy the file lirc-0.6.4.tar.bz2 from /cdrom/ linux/lirc directory from this month’s CD to /opt. Change to /opt directory (cd /opt) and uncompress and untar the archive as:

tar -Ixvf lirc-0.6.4.tar.bz2

Advertisment

This will produce a directory named lirc-0.6.4 within /opt. Change to this directory and issue the command:

./setup.sh

Select drivers



In the menu interface select option 1 (Driver configuration). Here you select the drivers for your remote. In our case we select option 3 (Other serial port devices) and then option 9 (Pinnacle Systems PCTV (pro) receiver). Select the serial port to which the remote’s receiver is connected. Next, select option 3 (Save configuration and run configure) and issue the commands:

Advertisment

make

make install



Copy the file named lirc.redhat found in the ‘contrib’ subdirectory to /etc/rc.d/init.d/lirc as:

cp contrib/lirc.redhat /etc/rc.d/init.d/lirc









Run the Lirc daemon named lircd (a program that decodes IR signals) as:





/etc/rc.d/init.d/lirc start

Advertisment

Ignore any errors shown related to lircmd-0.6.4.

Move the mouse



Here we configure Lirc to move the mouse pointer in X Window using the remote. The lirc package comes with a program called ‘lircmd’ which provides this facility.

Set remote buttons 



Decide which buttons on the remote will correspond to the movement of the mouse pointer in north, south, east, west directions and left-right clicks. Select the buttons as shown in the picture on the next page. Also select a button to activate the remote for mouse movement. For this, use the button labeled ‘off’ on the Pinnacle remote. Next, determine the code for each of these buttons. For this, use ‘irw’ program a part of Lirc package. Run the program as:

Advertisment

irw

Pressing a button on the remote will reveal its corresponding code. On pressing the buttons corresponding to the north, south, east, west, right click, left click and ‘off’, you’ll get the following output.

000000000000003f 00 Chan+Play PinnacleSysPCTVRemote



000000000000003e 00 Chan-Stop...

Advertisment

Make a note of the first 16 digit codes.

Create lircd.conf



Construct a file named lircd.conf in /etc directory, which is the configuration file, used by lircd. In this file the codes are written in the following form:

Advertisment

You can find our customized lircd.conf (applicable only for the Pinnacle remote we used) on this month’s CD in the cdrom/ linux/lirc directory. Note that we have entered the codes between the ‘begin code’ and ‘end code’ lines in the file. There is a pre-existing lircd.conf file in /etc directory that contains the code for all the buttons. The irw program that we used above made use of this file to give us the codes. So make a backup of this file by renaming it to lircd.conf.orig (mv /etc/lircd. conf /etc/lircd.conf. orig). You’ll need this for launching applications. Now copy the lircd.conf from the CD to the /etc directory.

Create lircmd.conf



Create another text file named lircmd.conf in /etc directory. In this file, assign a mouse action to the unique names defined in lircd.conf, enter the following lines.

PROTOCOL IMPS/2



ACCELERATOR 2 30 5


TOGGLE_ACTIVATE * r_activate


MOVE_N * r_north


MOVE_S * r_south


MOVE_E * r_east


MOVE_W * r_west


BUTTON1_CLICK * r_lclick


BUTTON2_CLICK * r_rtclick






The ACCELERATOR defines the speed of movement of the mouse pointer. The default works fine. For more on this read the configure.html file in the doc/html subdirectory in lirc-0.6.4. The following lines are in the format:

*

Using the unique name r_activate you assign the ‘off’ button to the action TOGGLE_ACTIVATE. This means when in X window you press the ‘off’ button for the first time, mouse control through the remote is activated. Pressing it the second time, deactivates the control. In the subsequent lines you assign a button for mouse moves in different directions and mouse clicks. You can also assign buttons for diagonal moves, like MOVE_NW (north-west), MOVE_SE (south-east). (For more, refer to the example file lircmd.conf in the subdirectory

‘contrib’.)

Modify the X configuration file



You need to now add lines to the file ‘XF86Config-4’ found in /etc/X11 directory. This file is divided into sections. In the ‘ServerLayout’ section (the first section in the file) add the following line before ‘EndSection’ of the ‘Server Layout’ section.

InputDevice Mouse1

Add the following lines after the ‘EndSection’.

Section “InputDevice”



Identifier “Mouse1”


Driver “mouse”


Option “Protocol” “ImPS/2”


Option “Device” “/dev/lircm”


Option “AlwaysCore”


EndSection




Restart Lirc programs



All done. Now restart the lircd and lircmd programs as:

/etc/rc.d/init.d/lirc restart

If you want these programs to start automatically on subsequent reboots, issue the command ‘ntsysv’ and from the list of services select ‘lirc’. Now start X Window by issuing the ‘startx’ command and control the mouse pointer through the remote.

Launch application



You can launch a Linux application using the irexec program (a part of the Lirc package). If you want to launch ‘xmms’ (an MP3 player) by pressing the button labeled ‘1’ on the remote, first determine the code for that 



button.

Determine the code for ‘1’



Stop Lirc as:

/etc/rc.d/init.d/lirc stop

Issue the following command.

lircd /etc/lircd. conf.org

Use the irw program to determine the code by pressing 1 and add the following line to the lircd.conf file before the ‘end code’ line as:

xmms

Create .lircrc file



Create a text file named .lircrc in your home directory (/root if you use the root account). Add:

begin



remote = PCQ


button = xmms


prog = irexec


config = xmms &


end



Here for ‘button’ specify the unique name for the button. For ‘prog’, specify the name of the program to be to used and for config, pass a parameter to the program. irexec accepts the name of the program to be launched as the parameter.

Start Lirc and irexec



Now start Lirc again as:

/etc/rc.d/init.d/lirc restart

and launch irexec as:

irexec &

Make sure that you have the DISPLAY environment variable set by setting it as:

export DISPLAY=:0

If you have X running, press the ‘1’ button on the remote to launch the MP3 player. You can append similar lines to .lircrc file to launch different applications but use a different remote button.

Advertisment