mwolson.org Blog - /Personal

Fri, 20 Oct 2006

Apple Remote fun

My Mac Mini came with a small remote control device which is called the "Apple Remote" according to the majority of the sites that I have consulted. Some neat things can be done with it in OS X, so I wanted GNU/Linux to be able to recognize it as well.

I tracked down a kernel patch for it, but I wanted it to be a stand-alone module instead for convenience. So I made a Ubuntu/Debian package for it at http://kilobyte.rcac.purdue.edu/ubuntu, calling it apple-remote-source. It did not seem to recognize my remote, so I made a slight change to the driver, adding an extra device ID — I'm still not completely sure in retrospect whether this is necessary. The original driver was version 1.1, so I called this version 1.2.

N.B.
As of Ubuntu's 2.6.20 kernel package, this package is not needed, because Ubuntu has included the driver into their kernel. I have not yet (Feb. 11, 2007) tested it due to some unfortunate LVM issues with the way they have packaged that kernel.

To install this, just download the apple-remote-source package, install it, install module-assistant, and run m-a ai apple-remote. You'll also need to add the following rules to the file of your choice in /etc/modprobe.d (I made a new file called options-local for this, myself).

# Load Apple Remote driver before other USB input devices
install usbhid /sbin/modprobe appleir && sleep 2 && /sbin/modprobe --ignore-install usbhid $CMDLINE_OPTS
N.B.
See the first comment to this blog post for a better way to do this.

I'm not sure yet what I want to do with this package, other than mentioning it here. The driver has an annoying bug where you have to restart the computer in order to use it for the first time — you can't just modprobe it immediately after building it. I suspect this may be due to (apparently) hard-coding /dev/input/event0 as its device name.

The version of xine-ui that I was using did not seem to have lirc support built-in, oddly enough, so I went with gxine for the moment. Here's the ~/.lircrc file that I used. Instructions for setting up lircd can be found here. Instead of compiling modules for lirc, I installed the inputlirc package, which seems to take care of this for devices that appear as USB input. The "#! lircrcd" line causes the lircrcd settings daemon to be started automatically whenever some program activates lirc support. This at least lets you have a metric for determining whether some program has been able to activate lirc support, which was useful in determining that xine-ui was buggy.

#! lircrcd

##
# gxine key bindings.
##

# jump to Title Menu
begin
	remote = APPLE_REMOTE
	button = KEY_MENU
	prog   = gxine
	repeat = 0
	config = input_menu1();
end

# menu navigate up
begin
	remote = APPLE_REMOTE
	button = KEY_VOLUMEUP
	prog   = gxine
	repeat = 0
	config = input_up();
end

# menu navigate down
begin
	remote = APPLE_REMOTE
	button = KEY_VOLUMEDOWN
	prog   = gxine
	repeat = 0
	config = input_down();
end

# menu navigate left
begin
	remote = APPLE_REMOTE
	button = KEY_PREVIOUSSONG
	prog   = gxine
	repeat = 0
        config = input_left();
end

# menu navigate right
begin
	remote = APPLE_REMOTE
	button = KEY_NEXTSONG
	prog   = gxine
	repeat = 0
	config = input_right();
end

# menu select
begin
	remote = APPLE_REMOTE
	button = KEY_PLAYPAUSE
	prog   = gxine
	repeat = 0
	config = input_select();
end

##
# End of gxine key bindings.
##

And for completeness, here is my /etc/lirc/lircd.conf file, so that you can see what each of the buttons stand for. It would probably be better to follow the instructions in the link I mentioned earlier, so that you can get a more customized setup.

# Please make this file available to others
# by sending it to <lirc@bartelmus.de>
#
# this config file was automatically generated
# using lirc-0.8.0(userspace) on Fri Oct 20 01:12:42 2006
#
# contributed by Michael Olson
#
# brand:                       APPLE_REMOTE
# model no. of remote control:
# devices being controlled by this remote: 1
#

begin remote

  name  APPLE_REMOTE
  bits            8
  eps            30
  aeps          100

  one             0     0
  zero            0     0
  pre_data_bits   24
  pre_data       0x800100
  gap          135863
  toggle_bit      0


      begin codes
          KEY_MENU                 0x8B
          KEY_PLAYPAUSE            0xA4
          KEY_NEXTSONG             0xA3
          KEY_PREVIOUSSONG         0xA5
          KEY_VOLUMEUP             0x73
          KEY_VOLUMEDOWN           0x72
      end codes

end remote

Posted by Mark at Sat Feb 10 19:36:32 2007

The first time after building and you tried to modprobe it, usbhid had probably already bound to the device.

You can work around this by looking at the output of 'lsusb', locating the 05ac:8240 line (which is the IR receiver), note the bus and device, and then (on my mac mini where it is on bus 4 device 2) you can release the receiver by:

# echo -n "4-2:1.0" > /sys/bus/usb/drivers/usbhid/unbind

Note - this even works on kernels that aren't using modules for usbhid, and your modprobe.conf trick doesn't work (eg, Fedora 6).  Once unbound, when you modprobe appleir, it should find the reciever.  You can use a similar trick if the IR receiver isn't bound, but wasn't automatically found:

# echo -n "4-2:1.0" > /sys/bus/usb/drivers/appleir/bind

Cheers,

Mark

Add a comment

Name: 
Your email address: 
Your website: 
 
Comment: