Some time ago I got a TV tuner card for my machine, and — not owning a conventional TV — I could watch movies again. But what's a TV without a remote control? The LIRC Project allows applications etc. to be controlled by an infrared remote control. This page chronicles my efforts (on x86 RedHat 8.0) and tells you how to replicate my results.
Most machines don't come with IR receivers, so you have to buy
or make one. The LIRC page has links and designs. You can
buy one
pre-assembled from Alessio Sangalli if you don't want
to solder. (He will send you one for €10 with
€3.20 shipping; about US $13.) I chose to get the ready-made homebrew
serial receiver from Thomas Schmid-Lindner at
zapway.de (which I hope is two guys in a garage). For
€17.80 and €7.40 shipping (about US $27) the simple
serial IR receiver arrived in about a
week. Plugged it in, installed
LIRC and... no, there was no instant gratification.
Here's a summary of what we're going to do. We're going to install the updated Linux kernel (2.4.18-27) with the source, compile and install the kernel; then compile and install lirc, then configure it. (If you didn't install the compilers and other development tools, you'll have a tough time here. If you send me email I may be able to send you executables.)
The kernel packages are available at rpmfind.net: you
need kernel-2.4.18-27
and kernel-source-2.4.18. Get
it and install them. Reboot so you're running the new
kernel. (If you run uname -r it should print something
like 2.4.18-27.) Here's my kernel config file. Save it to
/usr/src/linux-2.4.18-27.8.0/.config and look it
over. (In other words, go to that directory and type make
xconfig and make sure any special drivers etc. you need are
enabled.)
Now you can compile and install the new kernel.
$ make dep
$ make bzImage modules
If everything went well and there were no errors, you can install the new kernel. You need to do this as root.
# make install modules_install
Occasionally something goes wrong with initrd (the
ramdisk that serves as the root disk before the real disks have
been mounted). Check
the size of the initrd that got installed:
$ ls -la /boot/initrd-2.4.18-27.8.0custom.img
-rw-r--r-- 1 root root 127601 Apr 26 17:28 /boot/initrd-2.4.18-27.8.0custom.img
If your file is considerably smaller, some drivers didn't get built into the initrd; if so,
make clean; make bzImage
Then as root, make install. This should build a new
initrd and install it.
Reboot the machine and select linux-2.4.18-27.8.0custom at the
grub (or lilo) prompt. If all went well, uname -r will
report 2.4.18-27.8.0custom. Give your machine a quick
drive around the block and make sure everything that worked
before the upgrade still does.
Ordinarily, to compile a kernel module you only need the headers
of the kernel you're running. I don't know what the problem with
RedHat is (or why they think they're too cool to ship a stock
kernel) but that doesn't work. The supplied 2.4.18-14 configs in
/boot are broken; the only way I found to get
lirc_serial.o compiled correctly was to actually be
running the kernel that you're compiling for. Even this only
worked after I installed the -27 kernel. The -14 kernel that 8.0
installed wouldn't even compile a kernel that would boot. Life
is too short to spend any time figuring this RedHat shit out.
(However I have to say that Mozilla/firebird — used to be
called Phoenix — with Xft and the Bitstream Vera fonts is
spectacular. RedHat did the right thing by making Xft the
default.)
At the time of writing, LIRC was at version 0.6.6. Read the
LIRC documentation. Get the
source and unpack it somewhere, then cd to that directory. Run
./setup.sh and configure it to match your IR receiver.
(For the Schmid-Lindner ready-made homebrew serial receiver, use
COM1 i.e. port 0x03f8, irq 4.) Save the configuration and exit.
Now you can simply make and (as root) make
install — this will install the lirc_serial
kernel module as well as all the helper applications.
Now check that the installation did the right thing. There should be a character special file that represents the device driver:
$ ls -la /dev/lirc
crw-r--r-- 1 root root 61, 4 Apr 27 22:57 /dev/lirc
Installing lirc should have set all this up correctly. If you
see a link to ttyS0 or something, that's bogus. You can
make the correct special file:
# rm /dev/lirc
# mknod /dev/lirc c 61 4
Now we need to tell the kernel module loader that the LIRC
module should be loaded to handle /dev/lirc. We do
this by adding a line to /etc/modules.conf:
alias char-major-61 lirc_serial
(If it already exists you don't need to do anything.)
If all went well, you should be able to test your remote using
mode2 or xmode2: see Testing
your hardware & configuration at the LIRC site.
If you don't see anything and you're sure the IR receiver is
fine, I'm afraid I can't help you; compile LIRC in debug mode and
insert fprintf/kprintf statements in lircd and
the kernel module.
Once you have your receiver talking to the kernel, the rest is
relatively easy. Look for your remote in the LIRC supported remotes
page. If you don't find it, follow the instructions in the irrecord
documentation. The config file representing your remote
should be copied into /etc/lircd.conf. My remote was
not in the list so I had to create one; here's my config for the Sony RMT-V202 remote.
You probably want lircd started at boot time; here's an
init file to save in
/etc/init.d/lircd so you can create links for each
init state.
Once you have the lircd.conf file in place, you can try
starting lircd. There is a Unix-domain socket that lircd listens
on:
$ ls -l /dev/lircd
srw-rw-rw- 1 root root 0 Apr 28 20:35 /dev/lircd
The various client programs in the package (irexec,
irxevent etc.) connect to the lircd daemon through this
socket; as infra-red signals arrive, lirc_serial
gives them to lircd through /dev/lirc, which
parses them according to the lircd.conf file mapping raw signals to
events. A client reads these events from /dev/lircd and
performs the configured action.
My aim was to control the TV functions with the TV remote. The
program irexec is the program that runs commands when
lircd detects an IR signal; it too is a daemon that
runs constantly in the background. I used to run xawtv
but I've since switched to tvtime. Here's my config file ~/.lircrc (here's the xawtv version) that controls
tvtime/xawtv for TV functions and aumix for
volume (since the volume control in xawtv is
broken). Simply start it in the background and
voilà! a working TV. (I use the up/down on the
joystick-like control on the remote for system volume, since the
"volume up/down" buttons control the "line input" volume.)
$ irexec &
Note that my lircrc file has references to other
programs tv and vol —
these are simple shell-scripts I wrote. The "vol" script prints
the current volume; any time the volume is changed, the current
volume is printed on the TV image.
The "tv" script launches tvtime/xawtv and saves/restores any
screensavers, energy conservation etc. that may be going on.
Using the "Power" button on the remote launches and shuts down
tvtime/xawtv. I never turn my monitor on or off manually, but let the
X-server's DPMS turn it off for me. The screensaver and DPMS are
both disabled while tvtime/xawtv is running: you don't want
the monitor to turn off just because you haven't moved the mouse
or typed anything in the last five minutes! If the monitor is
off and you press the "Power" button, the monitor turns on
automatically and tvtime/xawtv is launched; hitting the
"Power" button again shuts down tvtime/xawtv and restores the
DPMS state i.e. the monitor is turned off. If the monitor had
already been on when tvtime/xawtv was launched, it is left on
upon exit.
For completeness, here's my stationlist.xml file and here's .xawtv — which will probably only be useful if
you live in the San Francisco.