Next Previous Contents

8. Setting up a remote control.

MythTV does not have native remote control receiver and decoder software built-in. Instead, remote control functions are implemented by cooperating with lirc, the Linux Infrared Remote Control program. lirc handles the IR hardware and passes keystrokes to MythTV, which then acts as if the user had pressed the keys on the keyboard. The file keys.txt describes the keys used to control MythTV.

NOTE: If you are running Mandriva, you may install lirc by executing: # urpmi lirc lirc-remotes and bypass the manual compilation steps described below by jumping to the Completing the lirc install section. See the contrib/mandrake91.etc.sysconfig.lircd file for an example of how to configure lircd.

Some IR devices require a kernel recompile, and some don't. However, all at least require having the kernel source available as a resource for the lirc build process.

8.1 Gentoo

To install lirc on Gentoo, all you need to do is:

# emerge lirc

8.2 Obtaining and compiling lirc

You're going to need to download and compile lircd. Go to http://www.lirc.org and download lirc; as of 2006-01-21, the version available is 0.8.0. Grab the remotes.tar.bz2 file as well.

$ tar -xjf lirc-0.8.0.tar.bz2
$ cd lirc-0.8.0
$ ./setup.sh
You're going to need to know what sort of receiver you have and where it's connected. In the case of the Pinnacle Studio TV card, with the IR receiver connected to COM1 (/dev/ttys0), once the configuration menu comes up, perform the configuration by going to Driver Configuration->Other Serial Port Devices->Pinnacle Systems Receiver->OK and on the next page select COM1->OK.

Each remote is different; some remote receivers connect directly to your capture card and not to a serial port, so make sure that you've got the correct one.

You then click "Save Configuration and run configure" to continue.

Make sure you read the last text generated by the configure step. It will tell you if you require a kernel recompile, and what the name of your kernel module will be (if necessary). For instance a home-built receiver may require a kernel recompile, so you would be notified that you will have to load the lirc_serial module. If you did not get any such messages skip the kernel recompile steps below and go directly to making and installing the lirc driver.

Once the configuration step is complete:

$ make
$ su
# make install
# chmod 666 /dev/lircd

At this point, if you're using a serial receiver, check that there's a lirc device in /dev:

$ ls -l /dev/li*
lr-xr-xr-x    1 root     root            5 Jan 27 09:00 /dev/lirc -> ttyS0
srw-rw-rw-    1 root     root            0 Jan 27 15:01 /dev/lircd=
prw-r--r--    1 root     root            0 Jan 27 09:00 /dev/lircm|

As you can see, there's a link from /dev/lirc to ttyS0, a.k.a. "COM1", which is appropriate for the Pinnacle Systems PCTV Pro. However, you may notice something like this:

crw-------    1 root     root      61,   0 Dec 31  1969 lirc
Some IR receivers (including some homebrew units) use a character device as their data interface as opposed to a link to a serial port. If the make install step has created a character device for you, don't replace it with a link to a COM port.

So, if the link or character device was not created (but should have been), ensure that you ran the make install step as root. If it still doesn't work, then there are three options. The first option is to re-read the lirc documentation to determine whether your IR receiver is a character device or should be a link to a serial port and to create the link/character device manually. In this example, the IR device is connected to ttyS0. If it were connected to "COM2", then use ttyS1, etc.

$ su
# cd /dev
# ln -sf ttyS0 lirc
# exit
$

NOTE: The above example assumes that your receiver uses the standard serial driver. Some receivers do not, including receivers that plug into a TV capture card. Check the lirc documentation, but it may be necessary to replace the link created above with a character pipe:
# mknod /dev/lirc c 61 0

See the lirc documentation for additional information. The lirc installation should create this for you, so manually creating it indicates that your lirc installation may have other issues.

The second option is to post your issue to the lirc list, not the mythtv-users list. The lirc programmers will be the ones that can assist you best.

The third option is to dispense with lirc altogether by purchasing an IR keyboard (various options exist, although Chicony appears to work for some people) and a learning remote control. The IR keyboard receiver plugs into the PS/2 keyboard port on your PC and you would train your learning remote to emulate the various keystrokes from keys.txt of your IR keyboard. Using this method removes lirc entirely from the picture - your remote will be sending keypresses that your PC "sees" on the keyboard port.

8.3 Completing the lirc install

NOTE to Mandriva 9.1 users: skip to the manual start paragraph below.

If the lirc configure program / compile did not mention anything about a kernel module, then you are finished. If it did mention a kernel module, you must edit the /etc/modules.conf file. Add this line as the first thing in the file. It must come first, or it may not work.

alias char-major-61 XXX

replace XXX with the name which you determined earlier, which in this example was "lirc_serial"

$ su
# modprobe lirc_serial
# /sbin/ldconfig

Next, we're going to manually start lircd the first time. Mandriva 9.1 users, type: # /etc/rc.d/init.d/lircd start instead of:

# /usr/local/sbin/lircd

NOTE: Read this next section if you're not familiar with how lirc works!

There are two separate files used by lirc, and both are required for your remote control to do anything useful. First is the lircd.conf file. lircd.conf tells the lirc daemon how to interpret the IR pulses that it receives from a remote control and what name to assign to each sequence of pulses. Without getting too involved, a particular series of pulses may correlate to "Channel Up". The lircd.conf file will then contain a line that looks something like this:

          ChannelUp                0x0000000000001020

The lircd.conf file can have multiple remote controls defined.

The second file is lircrc, which takes the name of the button which was pressed ("ChannelUp") in the above example, and correlates that to an action to be performed by a program using the remote control. So in MythTV, ChannelUp means one thing, while in mplayer it means something different. lircrc gives you the flexibility of taking the name of the button and having it perform different actions depending on which program you're using at the time.

NOTE: The definitions in lircd.conf come from the user community, and there is no standard for the common button names. One lircd.conf file may contain a definition for a button called "ChannelUp", while another may contain a definition for "Chan+". Your lircrc file must therefore be configured appropriately, or it won't work.

If this fails, complaining of a missing lircd.conf file, then you must find or make one. First look for a pre-made configuration file at http://lirc.sourceforge.net/remotes/. Mandriva 9.1 users, look in /usr/share/lirc-remotes. If you find one your remotes either on the website or in /usr/share, download or copy the file, name it lircd.conf and put it in your /etc directory. If you couldn't find your remote, you must make your own lircd.conf file.

To make your own lircd.conf file

$ irrecord myremote

Follow the on-screen directions to train your remote and define keys. If your remote ends up working well, you should consider submitting your lircd.conf file back to the lirc developers. Once finished:

$ su
# cp myremote /etc/lircd.conf

now try to start lircd again:

# /usr/local/sbin/lircd

Now, we're going to add the commands necessary for lircd to run each time we boot. Mandriva 9.1 users, you can execute:

$ su
# chkconfig --level 35 lircd on
# exit

All other distributions:

# cd /etc/rc.d
# cat >> rc.local
echo "Starting lircd"
/usr/local/sbin/lircd
^D
# exit
$ 

This takes care of the lircd portion, which "listens" for the IR signals. If everything went well, the install script for lircd put an appropriate configuration file for your remote into /etc/lircd.conf This file maps the buttons on the remote control to the IR pulses coming from the receiver.

The next step is to convert those signals into something that can be used to control MythTV. MythTV now includes native support for lirc and can interact directly with

$ cd ~/mythtv-0.21/contrib/configfiles
$ cp lircrc.example ~/.lircrc
or
$ cp lircrc.example.pinnaclestudiopctv ~/.lircrc
if you've got a Pinnacle Studio PCTV remote.
$ irw
Start pressing the keys on your remote; irw will print the name of the button as it is defined in your /etc/lircd.conf. If you don't see anything at this point, you need to troubleshoot further by going back to the lirc home page and investigating from there.

If it is working, then press CTRL-C to abort the program. Once you know that your remote is working, you can either recompile MythTV with native lirc support by enabling it in configure or you need to run the irxevent program, which takes the key presses and sends them to MythTV. If you use native lirc support, you don't need to run irxevent. If you are going to use irxevent, then you need to run it like this:

$ irxevent &
If irxevent isn't running, then MythTV will not respond to your remote control unless you're using native lirc support.

8.4 Additional information for lirc

Take a look at the lircrc.example files in the contrib/configfiles/ directory. In my case, (Pinnacle Studio card) the channel up and down functions weren't working, due to the fact that the button names were different than the default lircrc.example file that came with MythTV.

The lircrc.example file has this:

begin
    prog = irxevent
    button = ChannelUp
    config = Key Up CurrentWindow
end

begin
    prog = irxevent
    button = ChannelDown
    config = Key Down CurrentWindow
end
but the /etc/lircd.conf that comes in the lircd package defines the buttons for the Pinnacle Studio PCTV as:
          channel+                 0x0000000000000017
          channel-                 0x000000000000001C
rather than "ChannelUp" and "ChannelDown". I added the following to my /home/[yourusername]/.lircrc file:
begin
    prog = irxevent
    button = channel+
    repeat = 3
    config = Key Up CurrentWindow
end

begin
    prog = irxevent
    button = channel-
    repeat = 3
    config = Key Down CurrentWindow
end
which took care of basic functionality. Because the PCTV Studio remote has additional buttons, look at the contrib/configfiles/lircrc.example.pinnaclestudiopctv for an example of how to define additional buttons, and how to debug potential button name conflicts between the lircrc.example file and how your remote defines the button names.

By examining the button names defined in /etc/lircd.conf and using the irw program to make sure that your remote is working, you can create the appropriate mappings in .lircrc to get excellent remote functionality with MythTV.

Note the repeat = parameter. This informs the irxevent program to pass through every third keypress. By default, lirc will only send one keypress to the application, even if you're holding down the key. The actual repeat = number will vary from system to system, so experiment and see which value works best for you.

8.5 Configuring lirc for use with an IR blaster

Lirc has support for various IR transmitters. A popular model is the Actisys IR-200L http://store.snapstreamstore.com/accessories.html. It was originally designed for IRDA communication, but can be used to transmit A/V remote control codes. By using the lirc SIR driver, this device can easily be integrated with MythTV. I have tested this device with an AT&T DCT2000 digital cable box but the instructions can be used to configure other IRDA devices and A/V remotes.

Follow the steps in the previous section. When you run setup.sh, select option 1, driver configuration. From here select option 6, IrDA hardware. Select your appropriate device and the corresponding serial port, then Save configuration & run configure from the main menu. Once configure is done type:

$ make

Please note: unlike the Pinnacle receiver above you will be compiling lircd in addition to a kernel module for the SIR transmitter. Depending on whether you have your serial port driver configured as a kernel module you might see the following message during make:

lirc_sir.c:56:2: warning: #warning
"******************************************"

lirc_sir.c:57:2: warning: #warning "Your serial port driver is compiled into "

lirc_sir.c:58:2: warning: #warning "the kernel. You will have to release the "

lirc_sir.c:59:2: warning: #warning "port you want to use for LIRC with:"

lirc_sir.c:60:2: warning: #warning "setserial /dev/ttySx uart none"

lirc_sir.c:61:2: warning: #warning
"******************************************"

If you do receive this statement make sure to run the setserial command before you load the lirc_sir module. Follow this with the install:

$ su
# make install

You will notice that lirc installs the kernel module in /lib/modules/uname -a/misc.

The configuration for starting lircd differs if you're going to be sending and receiving IR versus just receiving.

 
# cd /etc/rc.d
# cat >> rc.local
echo "Starting lircd"
setserial /dev/ttySx uart none        # (if required)
modprobe lirc_sir
/usr/local/sbin/lircd
^D
# exit
$ 

At this point you have to populate the /etc/lircd.conf file with the proper codes for your A/V remote. You should be able to find your remote within the lirc remote tar file located at http://www.lirc.org/remotes.tar.bz2. In my case I extracted the file from remotes/motorola/DCT2000 (gi-motorola-dct2000)

To test the lirc_sir module you can run irw to verify the codes are being received. If everything is configured correctly you should see something similar to the following:

$ irw
0000000000007ff0 00 1 gi-motorola-dct2000
000000000000bff8 00 2 gi-motorola-dct2000
000000000000f7f0 00 ENTER gi-motorola-dct2000

Once you've verified lirc is working you can press CTRL-C to exit irw and configure the channel changing script.

The path to the channel changing script will need to be entered on the mythtv-setup screen for Input Connections.

This csh script will be called each time MythTV needs to change the channel. Below is a copy of the script followed by the corresponding perl script. Make sure both are in your path. Also make sure you leave the #!/bin/csh setting and not change it to Bourne or bash. This will create a frustrating symptom to diagnose where MythTV cannot open /dev/device. Unlike Bourne or bash, csh scripts automatically close parent file descriptors before they start.

$ cd /usr/local/bin
# su
# cat > change_channel.csh
#!/bin/csh
echo "changing to $1"
/usr/local/bin/channel.pl $1 &
^D
# chmod a+x change_channel.csh
# exit
$ exit

See contrib/channel.pl for the actual file. Copy it to /usr/local/bin/

The last statement within the perl script is the lirc rc command. This is the command that transmits the code to your cable/DSS box. Make sure to have the IRDA device within a few feet of the box.


Next Previous Contents