Difference between revisions of "LIRC"
m (→Ubuntu/Mythbuntu lircrc generation)
|Line 194:||Line 194:|
Restart mythfrontend. Your remote should now work with Mythtv!
Restart mythfrontend. Your remote should now work with Mythtv!
Revision as of 06:05, 5 February 2010
LIRC stands for Linux Infrared Remote Control.
So you want to control MythTV with your remote from the couch, eh? Well LIRC will help...
LIRC is a program that gives your computer the ability to send and receive infrared remote signals. Most distributions include LIRC packages, but you may have to compile your own version of the program to use certain features that the packagers did not include.
It should be noted that many people bypass the need for lirc altogether, and simply use a "learning remote control" and a infrared keyboard receiver. Train the learning remote control to output the appropriate keyboard press for each button/label. Linux and MythTV will not know any better and you have a simple and staightforward infrared controller.
Why would you use LIRC with MythTV? To utilise a generic non-learning remote control with MythTV and/or to enable MythTV to receive commands from a remote control and then use that information to control other bits of equipment (via IR, WIFI, LAN, Bluetooth, RS232 or whatever)...
In many installations the MythTV backend/frontend server is hidden in a cupboard. Often just the IR receiver is in the same room as the TV display and all the AV equipment is in a nearby closet. In this scenario the IR receiver must pickup a command in the living room from a proprietary tv tuner card remote control and IR receiver (a command such as volume-up) LIRC understands this but the volume is not controlled by the computer, but by a high quality amplifier. LIRC must then be configured to transmit a (different) IR code (to that which was received and to equipment within the closet) to control the amplifier and increase the volume.
- 1 Basics
- 2 Set up
- 3 LIRCRC
- 4 lirc + 2.6.16 kernel
- 5 Troubleshooting
- 6 Key things to remember
- 7 Multiple remotes
- 8 LIRC 2.6
- 9 Ubuntu/Mythbuntu lircrc generation
IR Reception (to MythTV)
In its most basic concept, you press the 'play' button on your remote control which sends an infrared signal to an infrared receiver connected to your computer. This infrared receiver sends a signal to LIRC, which identifies that you hit the 'play' key on your remote and then generates a keystroke on your computer that instructs MythTV to play.
For the infrared receiver, you have 2 choices about how you set it up to work with mythtv:
- Using irxevent which is an external program that can send key presses to Mythtv as if you were pressing keys on the keyboard. irxevent reads ~/.lircrc (note the dot at the start of the filename)
- Use mythtv native LIRC support, where mythtv reads ~/.mythtv/lircrc for its own key configuration (note no dot at the start of the filename) (Note: As of 0.21 Mythtv will read ~/.lircrc if ~/.mythtv/lircrc does not exist). This is vastly preferable.
In simple terms, this is what happens to the infrared (IR) signal and how it gets to mythtv:
- A remote control (A) emits pulses of infra-red light signals that are seen by an IR receiver (B) that is connected to your computer. The receiver may be connected to the computer via a serial port, over USB, or by a dedicated chip built into a TV tuner card. Each different type of physical IR receiver has its own type of kernel module.
- The kernel module (C) uses /dev/lirc (typically) to emit the pulse-length information, which is then parsed by the lircd process. The LIRC daemon (D) then uses the information from /etc/lircd.conf (E) to convert the pulse-lengths into button press information.
- Lastly, all programs that use LIRC need a second configuration file which tells liblirc_client.so what button presses are to be translated into which commands for each client program using LIRC, including MythTV. Once the button presses have been converted into instructions by liblirc_client.so using the lircrc (F) file (~/.mythtv/lircrc in 0.20, but 0.21 will read ~/.lircrc as well), then they are ready to be used by MythTV. (G)
- Note that the button names in /etc/lircd.conf must match the "button" configuration names you use in your lircrc file, but are otherwise completely up to you. The translations between the button names and the mythtv's internal names is done in the .lircrc or lircrc file, in the "config" line for a button. The "config" names must match what mythtv is expecting, and for the mythtv native LIRC support the "prog" line must say "prog = mythtv". This can be debugged with ircat (invoked as `ircat mythtv`).
IR Transmission (from MythTV)
The concept of a transmitter is a little more complex. You might want to use a transmitter if, for instance, you want MythTV to control a cable/satellite box so it can record the right shows on the right channels. Let's say LIRC just sent 'Channel +' keystroke to MythTV (like detailed above). MythTV then sends a signal back to LIRC instructing it to transmit a 'Channel +' command to the cable box. The infrared transmitter on your computer then emits an infrared signal to your cable box instructing it to change the channel + (just as if you had pressed the channel + key on the original cable remote).
The transmitter and receiver mentioned above are two separate devices (sometimes packaged into a single box). You cannot transmit through a receiver or receive through a transmitter.
LIRC with Multiple External Tuners
If you are using a system with multiple external tuners, you can use LIRC to control each one independently. The proper irsend command for each tuner can be placed in a separate channel changing script, and then specified as an external channel changing program for the appropriate video source in the Mythtv-setup program.
Normally, only a single LIRC transmitter is required as long as each of the tuners have mutually exclusive remote codes, and the LIRC transmitter can placed in the line of sight of all tuners' IR receivers. In this configuration, each tuner will need a "Remote Block" setting in the lircd.conf file and irsend simply needs the correct
REMOTE argument. This is probably the simplest solution to most multiple tuner systems.
However, there are some instances where unique control codes aren't possible, or simultaneous line of sight to the two receivers is not possible. In these cases, there are some options available:
- Build a Multi-Transmitter Homebrew Parallel Port Device and use irsend's
- Load multiple LIRC drivers using irsend's
--deviceoption. For some drivers, including lirc_serial (IR Blaster, etc.), this method won't work with multiple transmitters of the same type.
- Modify the source tree to support multiple instances of the LIRC driver and use 2 separate copies of irsend compiled.
- Use multiple IR emitters independently controlled by CommandIR Mini, a USB TX/RX combo device, with irsend's
Setting up LIRC can range from very easy to incredibly difficult. The difficulty level is likely related to what hardware you end up using for LIRC. There are several different hardware pieces for receiving and sending LIRC commands. A few are:
- The receiver that comes with your TV card. For example, the PVR series from Hauppauge sometimes have a receiver.
- A Serial Port receiver you can make yourself or buy for a small fee (Often called a homebrew receiver) I have made a list of homebrew lirc receiver parts that are readily available at RadioShack.
- A Serial Port transmitter you can make yourself or buy for a small fee (called a homebrew transmitter)
- A commercially available USB receiver (e.g. Microsoft MCE remote control).
- A USB receiver you can make yourself.
- A Parallel Port transmitter and/or receiver you can make yourself.
- The built in receiver with HDHomerun that works over UDP. HDhomerun instructions
It should be noted also that some people bypass the need for lirc altogether, and simply 'train' infrared codes from an infrared keyboard to their universal remote control. This way, pressing a key on your universal remote control would be picked up by the infrared keyboard's sensor, and pass the keystroke directly to MythTV as if you had been using an actual keyboard and not a remote at all.
For Help Setting up LIRC on your computer, follow some of these excellent resources:
- Official FAQ 8
- The Lirc section in Jarod's Guide
- Gentoo:HOWTO Setup LIRC for MythTV
- The Lirc website
- Online LIRC Configuration Tool for remotes and A/V blasting
- iMON SoundGraph HOWTO (Silverstone)
- DISH Network IR Blaster (mirror)
- DISH Network /etc/lircd.conf with all buttons, discrete power, and 16 codesets
The lircrc file defines the mapping between the buttons on your own remote (as defined in the lircd.conf) and the functions you actually want it to perform. Note that most installations of the myth frontend also use mplayer or xine to play external video files, so you also need to define what the buttons do inside it.
Keybindings has a list of all the keys used, which can be used in your lircrc file.
With native lirc support, MythTV can use Qt keys, removing the prefix Qt::Key_. Not all of MythTV's key names match their Qt counterparts, however. Instead of Period and Comma, for example, use the symbols (. and ,) themselves. Instead of PageUp and PageDown, use PgUp and PgDown.
Keys can also have a modifier applied. These are case sensitive.
For example, Setting the (Gray Hauppauge's) Power button to be Qt::CTRL Qt::Key_Escape:
begin prog = mythtv remote = Hauppauge_Gray button = Power config = CTRL+Escape end
"remote" is optional, but if you have multiple remotes configured in your lircd.conf e.g. for IR Blasting, you can use this line to make sure that only commands from the correct remote are used.
To configure the TV button to jump to Live TV by using the key sequence Qt::ALT Qt::Key_L,
- Add or modify your lircrc to contain
begin prog = mythtv remote = Hauppauge_Gray button = TV repeat = 3 config = ALT+L end
- Restart mythfrontend
- Go to Setup/Edit Keys/JumpPoints
- Select Live TV
- Press enter (until you see a dialog appear, that says it is waiting for a keypress)
- Press the TV button on your remote
Hopefully, you will now see Alt-L listed!
lirc + 2.6.16 kernel
As of 5/10/06 you must patch lirc-0.8 to work with the 2.6.16 kernel. Patch can be found here:
I have built several homebrew receivers, and it is a fun project. If you are faint-of-heart when around soldering irons and little resistors, then you might want to check out some of these sites that offer pre-built models:
- http://www.irblaster.info/index.html IRBlaster.info
-- Dave Hofstra
irw program to see whether LIRC and your remote are working before going any further. It shows what events are generated by your remote. This is very helpful!
The irw tool connects to the lircd socket and displays any recognized IR signals detected by the driver. If this works, then your hardware and driver is working. All that remains is your application setup.
You can enable logging for lircd with the -L option. Use this to see the results of clients connecting to lircd daemon. Compiling lircd with debugging enabled (-D option) allows you to see much more including parsing of the remote definitions.
# /usr/local/sbin/lircd --device=/dev/lirc/0 /etc/lirc/lircd.conf -L ~/lircd.log -D7
- The log file showing "accepted new client" immediately followed by "removed client" can indicate a a ~/.lircrc or ~/.mythtv/lircrc parsing error. Check the formatting.
Make the lirc device static
If you follow this http://parker1.co.uk/mythtv_tips.php Tip to make the lirc device static, you may notice that it only works if you have only one card with the same vendor ID. If you have more than one card from the same vendor, but with a different name, you can use the following line to create the /dev/input symlink:
ln -fs /dev/input/`cat /proc/bus/input/devices|grep -A 3 "Hauppauge Nova-S-Plus"|grep event|cut -d ' ' -f3` /dev/input/irremote
You should run this line before running lirc, for example add it to /etc/init.d/lirc here:
echo -n "Starting lirc daemon:" ln -fs /dev/input/`cat /proc/bus/input/devices|grep -A 3 "Hauppauge Nova-S-Plus"|grep event|cut -d ' ' -f3` /dev/input/irremote if $START_LIRCD; then
Using an udev rule may be more elegant, but I found this one liner to be more reliable.
The above failed for me for two reasons - one, my device is not an S-plus, and two, I have more than one of the same card. My small modification of the above one-liner should work for everyone:
ln -fs /dev/input/`cat /proc/bus/input/devices | grep -A 3 "Hauppauge" | grep event | cut -d ' ' -f3 | head -n1` /dev/input/irremote
The command mode2 will give each separate pulse for button pushes. Some buttons have different pulses for pushing the button than for releasing the button. Using mode2 will show all of pulses.
If you know lirc is working, and mapped correctly in the lircrc file, but is not doing anything in MythTV, you may want to check your LircSocket (frontend settings). This was a problem for me with MythTV 0.22 installed via atrpms on Centos 5.4. After installing lirc manually, I had to change the LircSocket setting from
/dev/lircd to get it to work. The frontend log should contain clues that it was not able to connect to the lircd socket.
/var/run/lirc/lircd is the default location for the lircd socket for lirc 0.8.6 and higher.
Key things to remember
- If you're using a PVR-350, at least, it won't work with stock LIRC. You need 0.7.0 (as mentioned in Jarod's Guide)
- If you're using a PVR-500MCE, please read this page: MCE_Remote
- Set up
/etc/lircd.confto fit your remote.
- Set up
~/.mythtv/lircrcwith the keys that are needed for MythTV and MPlayer
- Ensure MPlayer knows about LIRC (assuming you use it as the default player). If LIRC was installed AFTER MPlayer, you need to tell mplayer where to find the lircrc file in either the global config file
/etc/mplayer/mplayer.conf, the local user override file
~/.mplayer/config, or on the command line in
mythfrontend -> Utilities/Setup -> Setup -> Media Settings -> Video Settings -> Player Settings -> Default Playerby adding
-lircconf /path/to/lircrc. Note that when using all the default video players etc in myth, native control of MPlayer is only required when playing video files (like AVI's etc..) under "Watch Videos".
~/.lircrcfor Xine. I have the
~/.mythtv/lircrcbe a softlink to
~/.lircrcsee Lirc on Ubuntu Dapper as the basis for your own file.
- Don't try to use a lircrc file written for irxevent if you are trying to use mythtv native lirc support, see Lirc on Ubuntu Dapper as the basis for your own file. Or search for mythtv/configfiles/hauppauge-lircrc-nativelirc to use it as a template.
-- Orginal by Peter Morch
I use KnoppMyth and it worked out of the box for me with a Homebrew transmitter & receiver.
I use this SKY channel changer script with Sky in the UK - my sky box doesn't always change channels so it does it twice :) It also has 'locking' and works with the SKY dog remover script. I the ideas for this from a website somewhere.
See MultiLIRC for my mods to the standard Debian Lenny lirc installation for running multiple lirc remotes and keeping everything separate.
LIRC26 is how I installed Lirc (well, the lirc_serial driver) under 2.6.4 and 2.6.6
Lirc on Ubuntu Dapper is how I installed Lirc under a Ubuntu Dapper system with kernel 2.6.15
Ubuntu/Mythbuntu lircrc generation
Mythbuntu provides a package that will intelligently parse your lircd.conf file and attempt to create valid button mappings for use in MythTV and other media player applications. Note that the use of this package is contingent on your remote being properly installed and working. You can install and invoke this package as follows:
sudo apt-get install lirc mythbuntu-lirc-generator mythbuntu-lirc-generator
Restart mythfrontend. Your remote should now work with Mythtv!