LIRC
From Gentoo Linux Wiki
[edit] Introduction
LIRC stands for Linux Infrared Remote Control. It allows you to receive and send infrared signals. With LIRC and an IR receiver you can control your computer with almost any infrared remote control (e.g. a TV remote control). You may for instance control DVD or music playback with your remote control.
| Linux Kernel Configuration: Linux Kernel Configuration: Kernel 2.6 |
Loadable module support --->
[*] Module unloading
Device Drivers --->
Input device support --->
[*] Event interface
|
[edit] Install
You need to set an environmental variable prior to compiling LIRC in order to install the appropriate drivers for your tv capture card. That means you will need to determine which of the following drivers is suitable for your card. For a list of all supported devices, run:Unfortunately, it is not necessarily straightforward which driver to use in all cases, as neither the LIRC project website nor the installed documentation seem to provide this information. In most cases, however, the product name should be one of the drivers. You should decide what type of receiver you are using. If not, only support for the homebrew serial receiver will be compiled.
Homebrew receiver drivers:
That is a lot of options. For those of you with a homebrew serial receiver, your option will be "serial". If you received a remote with your video card or TV tuner, you will need to choose the most appropriate driver from the list above. You can get some idea of whether your hardware is supported or not by checking the sidebar of the official LIRC website. For using the tvcard integrated controllers like Hauppauge, do not forget to compile your kernel with i2c support.
Once you have selected your driver, you need to set the LIRC_DEVICES environmental variable, or simply edit /etc/make.conf as follows:
LIRC_DEVICES="driver"
If you have a serial IR device, set:
LIRC_DEVICES="serial sir"
If your device is supported by the kernel, (uses /dev/input/eventX) you will need to use the dev/input driver instead. This works particually well for these devices:
- X10/Medion/ATI remote controls (needs ati_remote kernel module)
- Hauppage NOVA-T
LIRC_DEVICES="devinput"
Or, if you don't mind the extra compile time, you can just tell it to compile all of them and let the kernel autoloader figure out which one to use:
LIRC_DEVICES="all"
Now you are ready to (re-)compile LIRC:
It is useful to set the global USE flag lirc so that all applications are built with LIRC-support. Then recompile all applications whose USE flags have changed:
Older versions of LIRC apply their sources to the kernel sources. By default configuration, it is not possible for an ebuild to overwrite kernel source files. In case that you are using such an ebuild, you can fix the issue with the following command:
If the driver you selected is only available in kernel space, LIRC will compile it on installation. All LIRC kernel drivers require lirc_dev. You do not have to load it manually. It is sufficient to only load the LIRC kernel driver module since it has lirc_dev as dependency. If you do not know the exact name, go to /lib/modules/$(uname -r)/misc/.
Depending on your mix of kernel and LIRC versions, you can run into incompatibility issues. Especially the warning "Unknown symbol class_simple_device_add" indicates that you might have to switch versions. Try to get a more recent LIRC ebuild:
If that does not help, upgrade your kernel and recompile LIRC.
[edit] Configuration
LIRC needs to know how to interpret the output from your remote. Codes from the remote are mapped to buttons in /etc/lircd.conf. There are two means of obtaining a lircd.conf file suited to your remote. For many (probably most) remotes you can simply copy the configuration file from the LIRC project website. However, if a prepared lircd.conf file is not available from the LIRC site, you will need to use the irrecord utility that is installed with lirc to capture the signals generated by your remote for each button.
[edit] Modules
If you want to use your remote control using an input device, add the module name to /etc/modules.autoload.d/kernel-2.6 (e.g. ati_remote) and skip this section.
Before starting LIRC, it is important load the necessary kernel modules.
Be sure you have unloaded all kernel modules that allows you to access the signals of your IR device in /dev/input. Use the LIRC modules instead. If you have a ATI/Medion/X10 remote control, you probably have the kernel drivers already loaded. Unload them with:You may need to use an appropriate kernel module for your hardware to work properly. If so, you will have to add "lirc_driver" to your /etc/modules.autoload.d/kernel-2.6 file so the module can load during boot. Substitute "driver" in "lirc_driver" to the actual driver you are using, which was defined in the LIRC_DEVICES variable in your make.conf above. To enable serial support for instance, you would add "lirc_serial".
The appropriate modules will now be autoloaded when booting, but you should also activate them now:
[edit] Recording the IR-codes
You need to have a configuration file for your remote control that tells LIRC how to interpret the IR codes transmitted by your remote. If the key codes were already correct, you can move on with the next section. The easiest way to configure the IR codes is to use an existing config file, try finding your remote in this listing. If your remote is not listed you can try using irrecord to create the file. Or, if you are using a universal remote you can just program it to control for example a Sony TV set and then try any of the files listed under Sony. When you have found a config file save it to /etc/lircd.conf.
You can try to use a pre-configured IR-codes file. They are stored in /usr/share/lirc/remotes and copy the setup you want to try out over to /etc/lircd.conf.
If you do not have any success with this, you can create your own file. Use this command:
This might not work for you if you only compiled LIRC with devinput support. In this case you first have to find out the path for your remote control. It is best to write a command that find it out dynamically because it is very likely that these paths change. For X10, try this:
Now execute it like this instead:
If this will not work for you, try out if your command detected the path correctly by pressing some buttons on your remote control after running:
This should produce output as the buttons are pressed.
Then type in the names for each button (e.g. VOL_DOWN, CHAN_UP, MUTE, etc.). You need them later when running irexec.
If you are done, replace your /etc/lircd.conf with your just-created configuration file:
[edit] Testing the receiver
Now it is time to check your configuration.
[edit] Stop any running lircd
Ensure that the daemon is not running before starting a new one.
or
[edit] Run lircd
For devinput start lircd, as follows:
Otherwise, just run:
If it does not work, try to set the correct path to your device ():
Please make sure that you use with the correct device above, otherwise you may experience "Connect: Connection refused" errors when trying to access the LIRC device. For example /dev/lirc0 rather than /dev/lirc/0.
[edit] Test setup
If lircd did not print any error messages, you can run either of these 2 methods to test your setup:
[edit] Method 1
If everything is correct this will connect to the lirc device and echo the buttons you have pressed. Press all buttons to check whether all events are triggered properly. It should print your out the codes you set in your lircd.conf.
[edit] Method 2
Verify that you have a new device node:
[edit] Save setup
Then edit /etc/conf.d/lircd with these parameters. For devices using the input-layer it might look like:
EV="/dev/input/"$( cd "/sys/class/input" && grep -l 'X10' event*/device/manufacturer | sed -e 's,/.*,,' ) LIRCD_OPTS="-H dev/input -d $EV"
[edit] Restart lircd in normal mode
Now start up LIRC and add it to the default runlevel so it starts on the system's start:
[edit] Configuring ~/.lircrc and irexec
~/.lircrc is the config file used by programs with native LIRC support (mplayer, xine-ui, ... with USE="lirc") and by irexec for the other applications (tvtime, xmms, ...) to execute commands in response to data captured from the remote. It is your personal button configuration file which maps buttons to commands.
With programs with native LIRC support and without this file, you will generally get only a few working buttons, and that when they can do a lot more. As example, with MPlayer, you can get a list that contains commands than you can use with LIRC:
You can use all the command from this list with LIRC. You just have to add them into ~/.lircrc. It is not necessary to run irexec for applications with native LIRC support.
For the other programs, no button will work and you will have to use irexec.
Before it can do that, however, you will need to create ~/.lircrc and fill it with application specific commands for each button on the remote. Now setup your ~/.lircrc file and you should be able to use LIRC with every applications that supports it. If so, congratulations! Your receiver is working, and you can now start adding support for you remote control. The file follows this format:
begin prog = ... remote = ... button = ... repeat = ... delay = ... config = ... mode = ... flags = ... end
There is sufficient document concerning the specifics of this file at the LIRC project site.
Some developers have gone through the trouble for you and put together the necessary information for their applications. For example, the tvtime website has a ~/.lircrc file available.
Some example configurations can be found on the french ubuntu forum and in How to configure and use LIRC.
Now run:
If it generates an error "connection error: Could not connect to the socket" this generally means that one of the LIRC drivers (lirc_dev lirc_gpio or lircd_modulename) isn't loaded properly, or that you permission problems with the lirc device node. First ensure that /etc/init.d/lircd is loaded without errors. Note that this service tends to not stop well, and may need to be zapped then started again. Then ensure that /dev/lirc0 exists and is receiving data as explained above.
Once you have irexec working, you will want to have it start up with each log in. Be sure to use this command to have irexec fork into the background:
[edit] Setserial
If you are using the serial driver and run into problems on module load, sys-apps/setserial will probably help you.
[edit] Install setserial
[edit] Enable the serial port
[edit] Add setserial to the default runlevel
For setserial to load the module it will need to be added to your startup scripts. First, you need to add a line to /etc/serial.conf:
/dev/ttyS0 uart none
Now you can set it to run at boot:
[edit] Alternate startup method
| Fix me: Move these instructions to instructions below, merge with hardware specific drivers and Troubleshooting. |
Update: You can simply edit /etc/modprobe.d/lirc and add the following line to lirc-enable the port(s) before loading the lirc_serial module:
pre-install lirc_serial setserial /dev/ttyS0 uart none
You can also set options for the lirc_serial module there like this:
options lirc_serial irq=4 io=0x3f8 type=0 sense=1
Finally run:
[edit] Using Multiple Devices Simultaneously
The only hardware to natively support multiple blasters on Linux is the CommandIR Mini multi-transceiver. Many other LIRC devices will have both an IR blaster and receiver unified into one - but LIRC may not support this feature (ala lirc_mceusb2). The solution is to get a simple serial IR blaster but this can be difficult to set up via LIRC.
In order to accomplish this, you must make sure that you have compiled support for both devices. Currently the LIRC_DEVICES environment variable only supports doing one device - to work around this change edit your /etc/make.conf:LIRC_DEVICES="all"
The second step is to run two concurrent processes of LIRC for both devices and have them interact with each other. This can be tricky so I have taken the liberty of posting my own /etc/init.d/lircd:
start() {
ebegin "Starting lircd"
start-stop-daemon --start --pidfile /var/run/lircd1.pid --quiet --exec /usr/sbin/lircd -- --driver=default --device=/dev/lirc/1 --output=/dev/lircd1 --pidfile=/var/run/lircd1.pid --listen
start-stop-daemon --start --pidfile /var/run/lircd.pid --quiet --exec /usr/sbin/lircd -- --driver=default --device=/dev/lirc/0 --output=/dev/lircd --pidfile=/var/run/lircd.pid --connect=localhost:8765
eend $?
}
stop() {
ebegin "Stopping lircd"
start-stop-daemon --stop --quiet --pidfile /var/run/lircd1.pid --exec /usr/sbin/lircd -- --pidfile=/var/run/lircd1.pid
start-stop-daemon --stop --quiet --pidfile /var/run/lircd.pid --exec /usr/sbin/lircd -- --pidfile=/var/run/lircd.pid
eend $?
}
Essentially what this does is it creates two instances of lircd, one running at /dev/lircd/0 and the other at /dev/lircd/1. Edit the --device=/dev/lirc* line to suit whatever devices you have in your system in whatever order. Since my transmitter is /dev/lirc/1 and my reciever is /dev/lirc/0, /dev/lircd corresponds to my reciever and /dev/lircd1 corresponds to transmitter. This is optimal as some applications may have problems dealing with a non /dev/lircd LIRC device.
Both instances should start when you run:
[edit] Hardware specific instructions
- iguanaIR
- UIRT2
- ATI All-in-Wonder and X10 Remote Controls (atiusb)
- ATI Remote Wonder II
- USB-IR-Boy
- Creative Sound Blaster Audigy 4 (with USB Receiver)
- Creative Labs Sound Blaster Audigy 2 Platinum
- Pinnacle PCTV
- DViCO FusionHDTV DVB-T
[edit] CommandIR Mini - USB Multi-Transceiver
CommandIR can control up to four devices independently using emitters and contains a built-in universal receiver to integrate all inbound and outbound IR control into a single Linux-native device. Installation instructions for Gentoo can be found in the manufacturers support site.
[edit] ALSA audio
First read about the hardware and the LIRC driver for ALSA. Now you have to tell LIRC what audio device to capture. In order to do it you simply edit the /etc/conf.d/lircd file. Virtually everyone wants to have:# Options to pass to the lircd process LIRCD_OPTS="-d hw:0,0"
Note: For the lirc_mceusb2 module you need to have the /etc/conf.d/lircd file this this order! Note 2: -> also notice that i am using /dev/lirc/0 not dev/lirc0 -> the latter did not work for me but the former did.
# Options to pass to the lircd process LIRCD_OPTS="-d hw:0,0" LIRCD_OPTS="-d /dev/lirc/0"
[edit] Homebrew Serial Transmitter (serial)
Serial transmitter is smooth sailing, the only tricky thing to know is that kernel support for the serial port will conflict the driver. The way to fix this is to emerge the setserial utility, and then add "setserial /dev/ttyS0 uart none" (ttyS0 is COM1, ttyS1 is COM2, etc.) to /etc/conf.d/local.start. You will then have to add "modprobe lirc_serial" into /etc/conf.d/local.start afterwards because the script is executed after modules.autoload.d.
Alternatively you may try to add "/dev/ttyS0 uart none" to /etc/serial.conf (after emerging setserial) and run serial at boot "rc-update add serial boot". And have lirc_serial module loaded by adding it to /etc/modules.autoload.d/kernel-2.6 (don't forget to run update-modules afterwards).
If you are using receiver wired in "Igor" way, i.e. like the following one - made for "Grider" with "Igor" plugin, make sure to add type=4 option while loading lirc_serial kernel module:
The whole module loading command may then look like this:
Alternatively you can emerge lirc with serial_igor_cesko module, then putting type=4 in modprobe call is unnecessary.
[edit] Enabling software support
Start by adding the lirc USE flag to make.conf. You can then re-emerge your installed packages with remote control support. This will work with:
- xine-ui
- MPlayer
- MythTV
- Totem
- Rhythmbox
- Audacious
- VLC
- KDE
and others.
[edit] Tips
For multiple remotes you can always concatenate them to one lircd.conf file:
Note that the names for each remote configuration must be different:
begin remote name Remote1 ... end remote begin remote name Remote2 ... end remote
.lircrc configurations for programs including MythTV, Xine, Mplayer, VLC and more can be configured for any remote control and any hardware can be found here.
[edit] Troubleshooting
[edit] Module does not load
If the kernel modules does not load, there could be a few reasons. If the serial driver in the kernel is being loaded before the LIRC driver, LIRC will fail and complain that the port is already in use.
| Code: dmesg output |
lirc_dev: IR Remote Control driver registered, at major 61 lirc_serial: port 03f8 already in use lirc_serial: use 'setserial /dev/ttySX uart none' lirc_serial: or compile the serial port driver as module and lirc_serial: make sure this module is loaded first |
If this happens you have a couple of options.
[edit] Prevent the kernel module from configuring the port
The ideal solution is to run:[edit] Use setserial to de-configure the port
You can follow the instructions and run the setserial /dev/ttySX uart none command, making sure you have already run emerge setserial. You may need to set this up to run at boot so that it can always take effect.
[edit] Use modules configuration to load the LIRC module first
If the above does not work as it didn't for me, you could configure the module loading by the following: Modify /etc/modprobe.d/lirc and uncomment the lines that match your serial port, this will enable the lirc_serial module to be loaded before the kernel modules if built or disable the serial port. No init-script for serial is then required.
[edit] Load serial support as a kernel module
Still another option is to compile serial support for your kernel as a module, and the Gentoo boot scripts will take care of things for you during boot, but not necessarilly once the system is already up and running. The following may be useful if the /etc/serial.conf update for preventing the kernel from configuring the port doesn't solve the problem.
Tell the serial module that the lirc_driver module (replace lirc_driver with your particular driver, e.g. lirc_sir) is a dependency so that the lirc_driver module captures the I/O port first. Once the lirc_driver is loaded and attached to the port, the regular serial driver takes whatever is left over.
For example, my serial ports use the 8250 module, so the following works:
[edit] Disable serial support in the kernel
Another other option is to disable serial port support in the kernel altogether, as the LIRC driver will take care of things for you. Obviously this will be an impractical solution if you have any other serial devices, but if you don't have any, this will also work.
[edit] Device /dev/lirc/0 isn't being created
If LIRC seems to compile, and modprobeing the lirc_<driver> works without errors but you aren't seeing a /dev/lirc/0 being created it is likely because udev is unable to complete the creation of the device. If running:
returns an error about udev being unable to read/write from the database becuase there is no such file or directory, re-emerging udev may fix the problem:
After the emerge, udev should re-start and /dev/lirc/0 should now show up.
[edit] LIRC will not compile
The following flags may become important if LIRC does not work straight as described in the basic configuration.
- --with-port=port (port number for the lirc device.)
- --with-irq=irq (irq line for the lirc device.)
- --with-timer=value (timer value for the parallel driver)
- --with-tty=file (tty to use (Irman, RemoteMaster, etc.))
- --without-soft-carrier (if your serial hw generates carrier)
- --with-transmitter (if you use a transmitter diode)
If any of these options apply to you, you will have to add them with the appropriate values to your LIRC_OPTS variable in /etc/make.conf.
[edit] Emerge gives you access violations
There is a bug in gcc that causes problems with sandbox. if the emerge returns you an error of access violation for /usr/src/linux-..../null.gcda Try emerging with the following command:
[edit] udev-rules
As of the date of this edit (November 11, 2005) there is a minor problem with the default gentoo install of lirc. Emerging LIRC will install a set of udev rules to /etc/udev/rules.d/10-lirc.rules that create the device node /dev/lirc/0. However the file /etc/conf.d/lircd starts the lirc daemon with an option that is not compatible with that udev rule. Accordingly, you may need to edit that files as follows:
# Options to pass to the lircd process #LIRCD_OPTS="-d /dev/lirc0" LIRCD_OPTS="-d /dev/lirc/0"
As of the date of this edit (October 28, 2009) the ebuild won't install udev specific rules if there is no module to load (as far as i know for "lirc_devices_asusdh") so here is what i did. First, get the info from the command line udevadm:
Where "X" is your device number, see dmesg. What you need to get is:
ATTRS{idVendor}=="xxxx"
ATTRS{idProduct}=="xxxx"
Now, add this rules:
SUBSYSTEM=="usb", ATTRS{idVendor}=="xxxx", ATTRS{idProduct}=="xxxx", SYMLINK+="the_name_you_want"
Finnaly, edit the file /etc/conf.d/lircd as follows:
Options to pass to the lircd process # for devices with lirc-kernel-module #LIRCD_OPTS="-d /dev/lirc0" LIRCD_OPTS="--device=/dev/the_name_you_want"
