Saturday, April 26, 2008

Setting up Apple Remote Control with F9

I wanted to set this up for a while now, but it wouldn't work for me under F8, because of an older version of lirc. Well, it's working perfectly in Fedora 9, so here's how I did it (partly for my own reference, in case I have to do it again). This is on an i686 Mac Mini, but I'm pretty sure other Minis will have a similar configuration. Not so sure about Macbooks, but feel free to try it.

First of all, a note of warning of what to expect and what not to expect. Even though you'll get your Apple Remote Control working under Linux, this won't be Front Row. In Front Row, the remote functions differently depending on the context -- e.g. in DVD menus pressing forward/back will navigate the options, while "play/pause" will work as "select." With LIRC, you can only configure each button to have one function, so your Apple Remote will be nothing more than a 6-button remote control.

With that in mind, it's still quite nice to be able to pause the movie or adjust volume without getting off the couch, so here's how to do it.

Get the stuff

First, get all the necessary bits:
# yum install lirc pulseaudio-module-lirc totem-lirc
Setting up LIRC

LIRC works like this -- a daemon listens to the HID device (builtin IR receiver) and maps events to its list of recognized buttons. There is a couple of contributed configurations, but they wouldn't work for me, so we'll generate our own. Run:
irrecord -H macmini -d /dev/hiddev0 /etc/lircd.conf
Read carefully the instructions, it's important! I labeled the buttons as follows:
menu, volume_up, volume_down, backward, forward, play_pause
Once you are done, you should have everything you need to make the remote work. Now, edit /etc/sysconfig/lirc and set:
LIRCD_OPTIONS="-H macmini -d /dev/hiddev0"
Now start lircd up:
chkconfig lirc on
service lirc start
You can test it to make sure that it's working by running:
irw /dev/lircd
Press a few buttons and you should see events show up on the console. If something is not working, troubleshoot the previous steps. For your reference, my lircd configuration is available here: my /etc/lircd.conf.

Now you have to set up the "client" side of lirc, by setting up an /etc/lircrc. The format is really quite verbose -- I'd hate to do this for remotes that have more than 6 buttons. Here's mine, which is configured for pulseaudio and for Totem: my /etc/lircrc.

Setting up PulseAudio

Edit /etc/pulse/ and add the following:
load-module module-lirc config=/etc/lircrc
Note, that if you have more than one audio device, you'll need to list the sink here. To find out what sink you should use, run "pacmd" and then, at the prompt, "list-sinks". Look for the device that you want to control with your remote and copy the "name" without the angle brackets. You'll need to add it to the load-module command, e.g. like so (for me):
load-module module-lirc config=/etc/lircrc sink=alsa_output.pci_8086_27d8_sound_card_0_alsa_playback_0
You'll need to restart pulseaudio to take effect -- you can just log out and log back in for that. If all went well, pressing volume buttons on the remote should now change volume on your mac mini.


That's easy -- just load it up and make sure the lirc plugin is enabled (Edit->plugins).

Other apps

I'm planning on setting it up with Exaile, but I haven't yet had a chance to get around to that. I can see from the packages available that several other apps have lirc capabilities, e.g. rhythmbox and xmms, but I don't use either of these, so I didn't bother setting them up.

I just wish Miro supported it, but currently it doesn't. In fact, Miro is having issues under F9 at the moment, so I didn't even get a chance to try.

Hope this was helpful to others.


Jeremy said...

This should really all just be set up and work out of the box by default. If they're hid devices, then they should be detectable via hal. And once that's the case, it should be possible to use FDI files to describe the various models and set up "reasonable" defaults. Sure you don't want to work on it for F10? ;-)

stephdau said...

Without mentioning the rather system-heavy MythTV, I heard Elisa and XMBC make great FrontRow replacements on Linux: