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 Mandrake 9.1, 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.

NOTE: If you wish to use the remote control that comes with the Hauppauge PVR-250/350 cards, you will need to run the lirc 0.7.0pre2 code. See the example installation in the "Hauppauge PVR-250 remote and MythTV's native LIRC support" section.
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 Mandrake 9.0

lircd has two prerequisites: dialog, available in Mandrake through the "cdialog" RPM, and the kernel source. Mandrake 9.0 is using the 2.4.19 kernel, so either install the kernel sources from the installation CD or go to http://www.kernel.org and download the full 2.4.19 tar file from http://www.kernel.org/pub/linux/kernel/v2.4/.

Obtaining the kernel

Install using urpmi.

$ su
# urpmi kernel-source

8.3 Red Hat Linux/Fedora Core

You should already have the source from the "Kernel Development" package you installed in section 3.2. Ensure that a symlink has been created:

$ cd /usr/src
$ su
# ln -s linux-2.4 /usr/src/linux
# exit

8.4 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 2002-11-07, the version available is 0.6.6. Grab the remotes.tgz file as well.

$ tar -xjf lirc-0.6.6.tar.bz2
$ cd lirc-0.6.6
$ ./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.

Recompiling your kernel on Red Hat Linux/Fedora Core

Don't Panic! Red Hat makes a kernel recompile very easy. They provide configuration files that make it so you can recompile your kernel with Red Hat defaults. And as a side benefit, your kernel will be compiled specifically for your architecture. For a more detailed description (or if you run into trouble) of how to do this go to http://www.redhat.com/docs/manuals/linux/RHL-8.0-Manual/custom-guide/ch-custom-kernel.html

NOTE: Suitable Red Hat kernels for MythTV (i2c update, v4l2 API, CONFIG_SERIAL modularized) are available from ATrpms: http://ATrpms.net/name/kernel/. You will also find suitable kernel modules for ALSA, lirc, bttv, ivtv, saa7134 etc. there. See also the main Red Hat/Fedora Core section.
For the impatient: Make sure you have an emergency floppy boot disk available!
$ cd /usr/src/linux
$ su
# make mrproper
# cd configs
# ls

at this point you must look at the file names and determine which config file is right for you. For instance if you have an Athlon XP you should choose "kernel-2.4.18-athlon.config" but if you have a dual processor P4 you might choose "kernel-2.4.18-i686-smp.config"

# cp yourconfig.config ../.config
# cd ../
# make xconfig

At this point you will get a graphical configuration utility. All that you must do to make lirc work is go to the "character devices" section and change "Standard/generic (8250/16550 and compatible UARTs) serial support" from "y" to "m". Now if you want you can have a look around. For instance, you might wish to turn off ham radio support, or perhaps turn off PCMCIA support if you are not on a laptop. But be careful! Only change things you know you can change. If you are not sure, just stick to the one required change. Click "save and exit". Next:

# make dep
# make clean
# make bzImage modules
# make modules_install
# make install

if you are using grub, that should be it, reboot and select your custom kernel upon boot. If you are using lilo, change your lilo configuration according to http://www.redhat.com/docs/manuals/linux/RHL-8.0-Manual/custom-guide/ s1-custom-kernel-bootloader.html Remember, if you have any custom kernel modules (ALSA, etc) you will have to recompile/reinstall those.

8.5 Completing the lirc install

NOTE to Mandrake 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. Mandrake 9.1 users, type: # /etc/rc.d/init.d/lircd start instead of:

# /usr/local/sbin/lircd

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/. Mandrake 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. Mandrake 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.18/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.6 Additional information for lirc

Take a look at the lircrc.example files in the 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 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.7 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 mythbackend 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