* It should be noted that many people bypass the need for LIRC altogether, and simply use a "learning remote control" and a infra-red keyboard receiver. Train the learning remote control to output the appropriate keyboard press for each button/label. Linux and MythTV will see it as a keyboard and you have a simple and straightforward infra-red controller.

* It should be noted that many people bypass the need for LIRC altogether, and simply use a "learning remote control" and a infra-red keyboard receiver. Train the learning remote control to output the appropriate keyboard press for each button/label. Linux and MythTV will see it as a keyboard and you have a simple and straightforward infra-red controller.

−

+

* LIRC is now built into the kernel and may not be required. Many MCE remotes may simply be recognized as a keyboard. This may or may not also require the use of "ir-keytable" based on your distro.

== Basics ==

== Basics ==

=== IR Reception (to MythTV) ===

=== IR Reception (to MythTV) ===

Revision as of 03:12, 21 November 2012

Cleanup: This article or section may require cleanup. Discuss the issue on the talk page

LIRC stands for Linux Infrared Remote Control. It is required to use a generic* Remote Control with MythTV.

LIRC is a software package that gives your computer the ability to send and receive infra-red remote control signals when combined with appropriate hardware. Most distributions include LIRC packages, but you may have to compile it yourself if you wish to use certain features that the distribution 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 infra-red keyboard receiver. Train the learning remote control to output the appropriate keyboard press for each button/label. Linux and MythTV will see it as a keyboard and you have a simple and straightforward infra-red controller.

LIRC is now built into the kernel and may not be required. Many MCE remotes may simply be recognized as a keyboard. This may or may not also require the use of "ir-keytable" based on your distro.

Basics

IR Reception (to MythTV)

In its most basic concept, you press the 'play' button on your remote control which sends an infra-red signal to a receiver connected to your computer. This 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 infra-red receiver, you have two choices about how you set it up to work with MythTV:

The preferred method is to use mythtv native LIRC support, where mythtv reads ~/.mythtv/lircrc for its own key configuration

An alternate approach uses 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)

The receiver may be connected to the computer via a serial port, 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)

You might want to use a transmitter if you want MythTV to control a cable or satellite box so it can record the right shows on the right channels.

This process starts by configuring the video source in the Mythtv-setup program to use an an external channel changing program. More specifically, the channel changing script is a per capture card property that is specified in the Input Connections section of mythtv-setup. If you are using LIRC, this program will be a [LircChannelChanger channel changing script] that invokes LIRC's irsend command, passing it appropriate arguments to send the channel changing IR codes.

Let's say MythTV wishes to tune to channel 2 (either to record a scheduled show or because it was instructed by the user viewing live TV), it invokes the external channel changing program passing it '2' as an argument. The channel changing script turns that into an invocation of irsend, and LIRC transmits the appropriate codes via your infra-red transmitter.

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:

Multiple LIRC Drivers with multiple IR emitters of the same type without having to recompile lirc_serial.

Set up

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 HD-PVR series from Hauppauge sometimes have a receiver.

Migrating to LIRC 0.9.0+

As of 2.6.36, some infrared receiver drivers have been removed from LIRC and into the kernel. The following drivers are no longer available in lirc:

mceusb

streamzap

it8x

ene0100

Other LIRC drivers have been moved to staging. For example, the lirc_i2c driver is in this part of the kernel now. These changes have been backported to the 2.6.35 kernel for Fedora 14, and the 2.6.32 kernel used by RHEL and derivatives.

Gentoo

For me this broke my existing lirc MCE USB setup. As of March 2011, I had to do the following to fix it using 2.6.37 on gentoo:
Note: I recently (Oct 2012) tried this migration again and failed. The version of lirc in portage and from the lirc site no longer work for me as described below (YMMV). I have since stopped using lirc and am migrating to Sapphire.

Loaded the new mceusb driver (reboot or modprobe mceusb) which created /dev/lirc0. The previous non-kernel modules created the device as /dev/lirc so this is different. Therfore I had add -d /dev/lirc0 as an option to lircd when it started (for me this change was in /etc/conf.d/lirc) so the binary knew where to find the driver

lircd ran without error but irw still didn’t show my keypresses on the remote. lircd -v showed 0.8.5 which is not compatible with the new drivers. I removed 0.8.5 then downloaded 0.9.0pre1 from the lirc site and installed it myself (there was no gentoo ebuild at the time). Note that this also installed drivers lirc_dev and lirc_mceusb which are the old drivers. They aren't needed so I deleted them on my system to avoid confusion in the future. After that I restart lircd and irw and could see my keypresses being captured.

My last issue was that when I started mythfrontend, when I pressed up/down twice it would move 4 or 5 times. This was due to the irevents being interpreted as both lirc events and as keypresses in the kernel. This was fixed by running echo lirc > /sys/class/rc/rc0/protocols which forces them to be processed as lirc events only. Note that command needs to be run on every reboot, so it should be added wherever your distro runs such commands (gentoo is /etc/conf.d/local.start)

Here are things I DIDN’T have to do:

update /etc/lirc/lircd.conf

If you have issues

Run lsmod | grep lirc_ to check that the old modules aren't loaded

Check that /dev/lirc0 is being created after mceusb gets loaded. If not look at dmesg after modprobbing mceusb it for clues

run lircd in non deamon mode by using lircd -n <whatever other options you need>. This will keep the output to the console so you can see what’s happening.

Again this all based on my experience on gentoo with 2.6.37 & 2.6.37.2. YMMV based on the distro in use - chances are some of this will be taken care of behind the scenes.

When using the PVR-250 (ivtv) video capture card as the platform to receive IR signals you will want to configure your kernel to support LIRC (CONFIG_LIRC=y), support staging (CONFIG_STAGING=y, CONFIG_LIRC_STAGING=y) and support the LIRC I2C driver as a module(CONFIG_LIRC_I2C=m). Kormoc has ebuilds available for LIRC 0.9.0 that should work sufficiently well with newer kernels. There is a bug filed to get a newer version of LIRC into portage. It has many votes, consider adding your vote there if you would like that or Kormoc's ebuild in portage.

Debian

Starting with Wheezy (testing) in April 2011, kernel 2.6.38 is available as the default linux-image and the required modules are included as modules.

Fedora

In kernel modules are backported to Fedora 14 starting with the kernel 2.6.35,

Ubuntu

Ubuntu 11.04 will ship with 2.6.38 and pre-release reports would indicate it will work.

Setting Up The Devinput Option

The in-kernel drivers support the ir keycodes, however, mythtv cannot currently use the interpreted codes so must use lirc as a bridge. The new drivers will break the configuration of pre 0.9.0 lirc setups. The devinput option uses the same setup for all of the receivers listed above.

This has been tested on Fedora 14 running 2.6.35.11-83 and Debian Wheezy (testing) with kernel 2.6.38-2.

Install ir-keytable either from v4l-utils or the package of the same name (depending on distribution).

Install the lirc-remotes RPM or lirc package to obtain various example lircd.conf files.

Run ir-keytable to verify a driver has been loaded for your IR receiver

Specify the devinput driver in /etc/sysconfig/lirc (LIRC_DRIVER="devinput") or in hardware.conf for Debian based systems.

Determine which /dev/input device is available by looking in /dev/input/by-id.

Specify the /dev/input device in /etc/sysconfig/lirc (LIRC_DEVICE="/dev/input/by-id/foo") or in hardware.conf for Debian based systems.

Restart lirc.

Check that your configuration is working by running irw and pressing some keys.

You may need to change settings in mythtv. Under settings > general menu, look for the lirc setting. The device has moved in to /var/run/lirc/lircd.

Notes on Ubuntu/Mythbuntu 11.10 configuration:

In hardware.conf edit REMOTE_DRIVER and REMOTE_DEVICE instead of LIRC_DRIVER and LIRC_DEVICE.

Set LOAD_MODULES="false" in hardware.conf. For some reason with this set to "true", which is the default, the lirc service will not initialize properly.

LIRCRC

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.

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.

Tip: To find the exact syntax for a key (especially when it does not match QT keys), run the MythTV Frontend and go to Edit Keys. Select the function you want to invoke and look at the up to 4 key assignments at the bottom of the screen. The text displayed there will be what you need to use (for example PgDown).

For example, Setting the (Gray Hauppauge's) Power button to be Qt::CTRL Qt::Key_Escape:

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!

Troubleshooting

irw

Use the 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, driver and lirc.conf is working; all that remains is your application setup. If irw does not generate the expected output though, not all is lost -- see the mode2 command below.

Logging

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.

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 have more than one input device on your system, the numbering may change from one reboot to the next.
You can [use udev] to ensure the input device corresponding to your remote has a name that does not change across reboots.

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:

This makes a symbolic link in /dev/input called "irremote" this will always point to the Hauppauge event.

mode2

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 pulses and is a lower-level lirc testing tool than irw.

Devices

Depending on your setup, lirc may be looking for either /dev/lirc0 or /dev/lirc, and the wrong one will obviously break things. You can use ln -s /dev/lirc0 /dev/lirc or ln -s /dev/lirc /dev/lirc0 to fix this.

LircSocket

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 /var/run/lirc/lircd to /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

Set up /etc/lircd.conf to fit your remote.

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.

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)

Multiple remotes

Distribution-specific notes

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:

Please note that there is a bug which causes duplicate mappings to be generated. This can cause remote input to be processed twice. For instance if you press "down" and the menu selection moves down two items or if you press "pause" and the recording immediately pauses and then starts playing again. For more information please see the the Ubuntu Launchpad bug 779835.

Debian Wheezy amd64 Hauppauge PVR 350

This text is a manual for the configuration. It worked on my machine with the hardware described. Obviously, there is more than one remote out there for the PVR-350, all with slightly different settings. There is also lots of descriptions for older lirc versions. These are almost useless for lirc 0.9.0 as part of the kernel.

Hardware

Software

Debian Wheezy (testing / June 2011)

Kernel: 2.6.38-2-amd64

lirc: 0.9.0-pre1

Files in /etc/lirc

hardware.conf

lircd.conf

hardware.conf:

# /etc/lirc/hardware.conf
#
# Arguments which will be used when launching lircd
LIRCD_ARGS=""
#Don't start lircmd even if there seems to be a good config file
#START_LIRCMD=false
#Don't start irexec, even if a good config file seems to exist.
#START_IREXEC=false
#Try to load appropriate kernel modules
LOAD_MODULES=true
# Run "lircd --driver=help" for a list of supported drivers.
DRIVER="devinput"
# usually /dev/lirc0 is the correct setting for systems using udev
DEVICE="/dev/input/event8"
MODULES="ir-kbd-i2c"
# Default configuration files for your hardware if any
LIRCD_CONF=""
LIRCMD_CONF=""

Now, we have to adjust ~/.lircrc. The name like KEY_CHANNELDOWN has to be attached to the appropiate keyboard key for mythtv.
My .lircrc looks like this (this is an evolved file from other tutorials and howto's):

Hints for trouble shooting

The correct scancodes can be found out using evtest for scancodes:

aptitude install evtest

run evtest and press buttons.
Results on my box (pressing all buttons from top left to lower right row after row) key events come from crappy default keytable, not the right one we've already installed above: