LIRC
So now that your system works we need to focus on how you're going to most often control it. Controlling an entire rack of AV equipment requires either many remotes or a very expensive control system. We are going to control everything and more for about $20.
Linux Infra-Red remote control is for communicating via Infra-Red (Obvious). By communicating this means being able to receive and interpret anything from TCP/IP to decoding TV remotes and sending remote signals to other AV equipment. This is how Linux can interact with a wireless keyboard, mouse, remote control and some joysticks or game pads. It is possible to bind any key or button to a mouse event, keyboard event, or bind it to a program to run. This makes it possible to do almost anything with a remote.
Remote controls can be done 2 ways. Infra-red or radio frequency. Radio frequency is a better choice if you want to go through walls or use outside. (Yes, LIRC also supports RF devices) I personally chose to go with IR because I don't have a reason to control my HTPC outside of that room and because I can find cheaper and better IR remotes. Also, many "home-control" systems use IR and require a receiver in every room. It will cost about $10 per repeater for every room in your home if you want to go that route and build or slightly more to buy. LIRC also supports fewer RF devices so you will have to pick one that is supported.
Building the circuit for most people is probably not worth the time. I built one because I thought it would be cool. I also suggest using a serial IR device as you are less likely to damage a computer if things go wrong (For those that build their own circuits, serial is more forgiving than parallel). After a stop at the local radio shack and $15.00 for parts I went home and in an hour had an IR receiver working on a breadboard. It took another 2 hours to get the parts to fit in the little d-sub box and look nice. It is very simple to do if you have built circuits before. If not, you can buy finished IR receivers for about $15.00 online. They are done by companies or college kids but all will work the same and have about the same quality. I have looked through all the receivers they recommended and would trust any of them. I slightly recommend the one with the IR at the end of the serial cable over others because you can choose any length of cable when buying it and that will save you an extra purchase later (which would probably cost more anyway).
The documentation for the entire LIRC install on Debian is spotty. A simple apt-get install LIRC only gets part of the software. Here is what you really have to do (It's not as simple as it should be)
apt-get install kernel-source--etc-etc
apt-get install lirc
apt-get install lirc-modules-source
The lirc-modules-source tries to compile the LIRC kernel module but no matter what I tried, it would fail. So this is what I did.
cd /usr/src/linux
make pkg...
dpkg -i /usr/src/blah..
depmod -a
Basically what is going on is LIRC needs a kernel module not provided by Linux (Which needs to change). You have to build the module based on your kernel and then install a Debian package that you created for the LIRC kernel module. In my case, I was using the Debian 2.4.20-k7 kernel. When I installed the 2.4.20 source (which was put in /usr/src/linux) it did not have a .config in that directory so I copied the one from the /usr/src/linux/kernel-headers/2.4.20-k7 to /usr/src/linux. (I had to do this because I am not using my own compiled kernel.) After the Debian package was made and placed in /lib/modules/2.4.20/misc/lirc_serial.o, I had to move it to /lib/modules/2.4.20-k7/misc/lirc_serial.o (creating the lirc directory myself). If you have built your own kernel you won't need these extra steps. If you are using a Debian kernel this extra information is not documented. If you have problems, read you /usr/share/doc/lirc* documentation. It had enough information, and then the help of Google'ing for "debian lirc install" I was able to figure this out. The biggest problem I ran into is there isn't much/any documentation stating you have to install the lirc-modules-source in order to get the lirc_serial kernel modules, which is needed for LIRC to work. Another note is that if you test your circuit, it won't look correct until the lirc_serial driver is loaded.
From what I've explained, this is what it takes to get LIRC working if you have good hardware. If you have problems, make sure your serial ports are enabled, or try modprobe'ing the lirc_serial driver with options for IRQ and memory address.
Once loaded, you need to setup Debian's module configuration so it loads the kernel module whenever it is needed.
Run:
echo 'alias char-major-61 lirc_serial' > /etc/modutils/lirc_serial
update-modules
At this point you should test and make sure everything works. Pick up a remote sitting around your house and run the program mode2. Point the remote at your IR receiver and hit some buttons. If you get data it's working, if not, it's time to debug (Check circuit, connection, drivers, kernel, etc) If you are getting data try to then find your remote on www.lirc.org/remotes. Download the config file and place it under /etc/lircd.conf. Start the lircd daemon then the program irw. Hit some buttons on your remote and see if you see something the name of the button you are pressing (pause, play, next, etc). If you do, you're done, that's it. If you couldn't find your remote on the website, get another remote or generate your own config file using irrecord.
Some very useful functionality to look into for remotes is having a button execute a command, using a remote as a mouse, using a remote buttons for keystrokes and much more. Read this lirc page for more information.
I have 3 different "remotes". You only need 1 but I did this as a test of LIRC and to give examples of what can be done.
The first test I did was to use a remote I had. I decided to use my AV Receiver as it had the most buttons. I downloaded the config file and modified it so the tuner buttons were mouse events and the CD buttons controlled XMMS and the TV/DVD buttons controlled MythTV. This worked very well and is all most anyone would want to do.
For a little more "custom" feel I bought a learning remote. I programmed it to control the projector and the power and volume on my AV receiver (The only reason I got a learning remote was for this). I used the rest of the buttons for xmms, MythTV, mouse, scroll scroll, and keyboard. By keyboard I mean that the learning remote has a "secondary" mode that allows more mappings. I setup the config file for LIRC to interpret those secondary IR signals as keystrokes. This is nice as I no longer have to hold a keyboard. Some A,B,C stickers are placed over "Play, Channel up, etc on the remote. It's not qwerty but it works. When I find a small qwerty remote, I'll use that. You can use a palm IR keyboard, but it's too big for me, doesn't fit in my hands.
The last thing I did for fun, and for a keyboard, was to use my Zaurus. Since the Zaurus has an IRDA port, it can send and receive IR. I downloaded a config file for a remote with over 100 buttons. I also downloaded that config file onto my Zaurus. Once the remote emulator and LIRC was setup on both the computer and the Zaurus I could use my Zaurus as the remote. I changed the LIRC config file on the Zaurus to add in more buttons to control my projector and AV receiver power and volume. The keys on the Zaurus don't map into lirc, and it would require a custom emulator that also could map those.
The PDA remote lead me to another thought. If you do have a PDA with a keyboard and a custom application, you could use 802.11 from a PDA/keyboard, write a wireless input LIRC, and control your HTPC that way. If IR range is line of sight, RF is 30', bluetooth is 100', and 802.11 is 1000' feet. You could also use a PDA for VoIP, Internet, security, normal PDA functions, etc. This would fit into more of a "Total Home Control", but that also includes HTPC. I have been designing how I will do a "Total Home Control" for some time, which I'll report on in a few years when I have done this.
So coming back to reality, I use the second remote 90% of the time, the first remote 9% (When I don't see my main one and just want something quick), and my Zaurus when I'm bored and to play around with. Most people will want the first option, and some the second.
You can also use LIRC to send IR signals. This is required if you have an external cable or satellite TV box. MythTV, for example, has to change the channels somehow in order to record programs when you are away. Using LIRC is how this is done. There is a perl script that MythTV calls to change channels that you have to edit and specify what IR signals to send for channel changing. You also need to have a good IR transmitter (Many people use an IR Blaster) for this. I have not done this so if anyone has and wants to write a good howto I'd gladly link to them for this information.
Other uses of IR Transmitters is so your computer can talk to any other device via IR. I could have bypassed needing a learning remote if I had done this (Which I probably will in the next few months). The benefit of this is that your computer can control other devices, such as an AV receiver, projector, lights, etc. My plans are to get an X10 transmitter module for my computer and build an IR transmitter. By using a single IR remote, I could press "Play" and have the lights dim, projector turn on, receiver turn on, MythTV go into DVD mode, and by the time I sat down the movie has started. (All by using a $5 remote). This feature in most home theaters usually has a several thousand dollar price tag.
Learning remotes - The quick fix
After several months of having to keep an extra remote around to control my audio equipment I decided to try a universal remote. One "device" on the remote would be for my audio equipment and another for the HTPC. I ended up being very frustrated because universal remotes usually have a section on them for "VCR" that can control another device without having to push its device button first (Sometimes called punch through). The problem with this is LIRC does not handle receiving codes for 2 different IR remotes well. After 10 hours of trying combinations of codes and hoping to find 2 close enough that LIRC could learn all the IR codes, I was never able to get the main buttons and the lower VCR buttons to work together.
After waiting long enough and going back to my keyboard for some time I finally went and picked up a learning remote. I figured I could take any IR code from any remote and program it as I wanted, wrong. Since I had an IR keyboard I decided the easiest way to get the HTPC working with the remote would be to program the learning remote with the IR keyboard. The RCA Learning remote I bought for $25 from best buy was easy to program, luckily, and it had an LCD display that told me when it had errors and couldn't record the IR code. I was able to record 7 IR codes before I started having errors. After a bit of trial and error it appears that the learning remote tries to learn the type of IR codes, and my luck, the IR keyboard apparently has several different IR code formats since it has so many buttons. Most letters and numbers were in the same IR code length; page up, down, left, up, function, end were all on another length; enter space, and control keys were yet another. In the end I spent several hours determining which IR codes worked with which keys. I found a way to learn 29 commands, which was going to be enough. The learning remote also supported vol up/down and mute from the audio device in "punch through". The end result of this Saturday was the auxiliary mode on the remote controlled the HTPC and I didn't even need to change devices to turn on my receiver (mute button) and adjust the volume - Thanks to punch-through (And programming the Audio mode of the remote to my audio receiver). I used mythweb to change the key bindings for myth to match the letters for play, ffwd, up, numbers, info, and so on, on the remote. For mplayer and xine, I setup the DVD area of the remote to use page up/down and several of the other off IR codes of other programs I use. Myth also supports multiple keys for functions so I can still use left/right and such on my keyboard to navigate, plus s o w and f on the remote to navigate.
I don't know if the limitation of 7 unique IR code lengths to be learned is unique to this remote or not. If anyone finds anything out let me know and I will post the information. Right now though, I am very happy with how things are working. I'm also happy that when I change to a 2.6 kernel I won't have to rebuild LIRC and work through the setup again.
|