My favorites | Sign in
Project Logo
             
Search
for
Updated May 04, 2008 by sdavilla
UpdateIRDriver  

Update the IR driver

The Apple IR controller is a USB device similar to that of the MacMini but the device ID is different. So to enable IR device support we have to patch and rebuild a kernel module. Apple IR remote can actually generate any of 256 6 button sets. The IR receiver on the AppleTV is physcially able to recognize and distingusih all 6x256 codes, and no others.

The sequences are all of the form 0x87EEXXYY, where XX is the ID code (UID) and YY is the key code. This info comes from the JP1 remote project The UID is used for paring IR remotes to IR controllers under OS X. When you pare a IR remote to the computer what you are doing is telling OS X to only listen to an Apple IR remote with this UID. A certain key press on the Apple IR remote will increment the UID. For example, the "menu" button on my remote has this for the IR code

0x87EE4A03

The pre-data is "0x87EE", the UID is "0x4A" and the key is "0x03". If I increment the UID code, now I get this for the "menu" button

0x87EE4B03

There are 256 possible UID codes. So 256 x 6 possible combinations that the AppleTV IR controller (actually all Apple IR receivers) will decode. This means that you can use a learning remote instead of the Apple IR remote to gain access to more than six buttons. To do this, use the learning remote to learn six buttons from the Apple IR remote. Then increment the UID by pressing "Menu" and "Play/Pause", then learn another set of six buttons. rinse, repeat until you have enough buttons defined.

Now use irrecord to create your lirc.conf from the learning remote. Then you have the AppleTV IR controller responding to the learning remote which has more than six buttons.


For a raw analysis of the Apple IR remote protocol. And web page that mentions handling the repeat in a different method (I do not think this is relevant anymore due to the lirc repeat patch).


There are other possibilities than using the AppleTV IR remote. As mentioned above, the AppleTV IR receiver is only capable of receiving IR sequences from an Apple IR remote. The IR receiver pre-processes the raw IR data and ignores any other. That leaves three methods for gaining more IR commands. a) use a learning remote and exploit the mutiple UID (as mentioned previously), b) replace the IR controller with a USB based IR receiver or c) use a programmable remote to emulate an Apple IR remote with multiple UIDs. This link describes using other IR remotes with the AppleTV.


Contributed by Ben Firshman, here's an alternate to using "~/.mythtv/lircrc". This is a python script that enables greater functionality using the Apple IR Remote. It completely replaces using lircrc for control of a MythFrontEnd so make sure "~/.mythtv/lircrc" is removed before installing. Thanks Ben.


Enable usbhid

There are two methods for fixing this, an older method which involves patching appleir.c and the preferred method which involves patching usbhid.c. While patching appleir.c is easier, I choose the preferred method as it moves IR control out of the kernel and into userspace. This update is in two parts, first patch/rebuild "drivers/hid/usbhid/usbhid.c", then patch/rebuild lirc. Just to remind users of lirc, lircd.conf assigns symbols to the signals from the remote and ~/.lircrc associates those symbols to actions in programs.

Note: there is way to alter usbhid without rebuilding the module but it only works with 2.6.22 and above kernel versions.
This has the form;

modprobe usbhid quirks=0x<vendor_id>:0x<product_id>:<quirk value>

So for the Apple IR receiver IDs and HID_QUIRK_HIDDEV it would be;

options usbhid quirks=0x05AC:0x8241:0x10

This would go into modprobe.conf or modules.d/usbhid, or modprobe.d/usbhid then
do a "modules-update".

another method is to add this to the kernel boot params

usbhid.quirks=0x05AC:0x8241:0x10

Patch/rebuild usbhid.ko. The IR controller is a USB HID device but the usbhid kernel module does not know about the AppleTV IR device, so we need to add the device ID. We are also going to shortcut the normal dpkg build as it takes forever to build and just build what we need to make a new usbhid.ko. Then we copy this into "/lib/modules/2.6.22-14-generic/kernel/drivers/hid/usbhid/" and rebuild the initramfs.

sudo apt-get install  kernel-package libncurses-dev ncurses-dev  unzip
sudo apt-get source linux-image-2.6.22-14-generic

cd /usr/src/linux-source-2.6.22-2.6.22/drivers/hid/usbhid/

sudo wget http://atv-bootloader.googlecode.com/files/atv-hid-quirks-enable-ir-r2-2.6.22-14-generic.patch

# test the patch (this should complete without errors)
sudo patch --dry-run < atv-hid-quirks-enable-ir-r2-2.6.22-14-generic.patch

# apply the patch
sudo patch  < atv-hid-quirks-enable-ir-r2-2.6.22-14-generic.patch

# cd back to the root of linux source
cd ../../../

# copy the current kernel config into the kernel source tree
sudo cp /boot/config-2.6.22-14-generic ./config
sudo make oldconfig
# this will take some time
sudo make modules

# copy the rebuild usbhid module into runtime location
sudo cp drivers/hid/usbhid/usbhid.ko /lib/modules/2.6.22-14-generic/kernel/drivers/hid/usbhid/usbhid.ko

# rebuild the initramfs
sudo update-initramfs -u

reboot

# /dev/usb/hiddev0 should now be present

Setup LIRC

Patch/rebuild lirc. lirc versions <= 0.8.2 do not flag repeat events for an apple hiddev device. This part will fix this and rebuild lirc.

# install lirc package and choose Apple Mac Mini if asked
sudo apt-get install lirc

# get the source and source dependencies
sudo apt-get build-dep lirc
apt-get source lirc
# get the lirc patch
wget http://atv-bootloader.googlecode.com/files/lirc-0.8.2-macmini-repeat.patch

cd lirc-0.8.2
# test the patch
patch --dry-run -p1 < ../lirc-0.8.2-macmini-repeat.patch
# apply the patch
patch -p1 < ../lirc-0.8.2-macmini-repeat.patch

# rebuild the lirc package
sudo dpkg-buildpackage

# install the package and choose Apple Mac Mini if asked
sudo dpkg -i ../lirc*deb

Create the lirc files to support the Apple IR controller. This is going to be highly dependent on install distribution so you might have to do some google search to find the correct conf. This procedure outlines creating the lirc files from scratch. Remember lircd.conf assigns symbols to the signals from the remote, and ~/.lircrc associates those symbols to actions in programs

sudo /etc/init.d/lirc stop

sudo nano /etc/lirc/hardware.conf
#replace DEVICE="" with
#DEVICE="/dev/usb/hiddev0"

You can generate an /etc/lirc/lircd.conf from scratch

#use PLUS, MINUS, PREV, NEXT, MENU and PLAY for the button
#names for the Apple remote and follow the instructions from irrecord
sudo irrecord -H macmini -d /dev/usb/hiddev0 /etc/lirc/lircd.conf

Or use this one, but watch out, the AppleIR "pre_data" is different when the remote is paired with the AppleTV so you might have to change "pre_data" to match your Apple IR remote.

begin remote
  name  Apple_IR
  bits            8
  eps            30
  aeps          100

  one             0     0
  zero            0     0
  pre_data_bits   24
  pre_data       0x87EE4A
  gap          211995

      begin codes
          PREV                     0x09
          NEXT                     0x06
          PLUS                     0x0A
          MINUS                    0x0C
          PLAY                     0x05
          MENU                     0x03
      end codes
end remote

Here's another variant

begin remote
 name  Apple_IR
 bits            8
 eps            30
 aeps          100

 one             0     0
 zero            0     0
 pre_data_bits   24
 pre_data       0x87EEA3
 gap          211995

     begin codes
         PLUS                     0x0B
         PREV                     0x08
         PLAY                     0x04
         NEXT                     0x07
         MINUS                    0x0D
         MENU                     0x02
     end codes
end remote

Append this to your ~/.mythtv/lircrc or use Ben's python script

#nano ~/.mythtv/lircrc and append
begin
    remote = Apple_IR
    prog = mythtv
    button = PLUS
    config = Up
    repeat = 2
    delay = 0
end

begin
    remote = Apple_IR
    prog = mythtv
    button = MINUS
    config = Down
    repeat = 2
    delay = 0
end

begin
    remote = Apple_IR
    prog = mythtv
    button = MENU
    config = Escape
    repeat = 2
    delay = 0
end

begin
    remote = Apple_IR
    prog = mythtv
    button = PLAY
    config = Space
    repeat = 2
    delay = 0
end

begin
    remote = Apple_IR
    prog = mythtv
    button = NEXT
    config = Right
    repeat = 2
    delay = 0
end

begin
    remote = Apple_IR
    prog = mythtv
    button = PREV
    config = Left
    repeat = 2
    delay = 0
end

Restart lirc and test

# restart lirc
sudo /etc/init.d/lirc restart

# test your configuration by running the following app and pressing the IR buttons
irw /dev/lircd

Comment by DaveHard, Apr 01, 2008

For me the lircd.conf file shown here did not work. When I tried the irrecord program the first two sections ("hold one button" and "name and push buttons") worked but the last ("repeatedly press one button") did not. No "dots" appeared with rapid or slow repetitive pushing. When I pushed different buttons the dots began to appear and the program terminated correctly. Then I took the predata code, 0x87EEA3, from the file it created and modified the config file shown on this page. My remote is now working!

Comment by vvadim, Apr 27, 2008

For days I tried to follow this guide to get lirc to work with the source from ubuntu and it just would not work, kept complaining about un-supported hardware. I did have the module patched and loaded and the lsusb would list the device, and I could see it getting detected in dmesges but it still would die as soon as irw would run. I mean I could record everything using irrecord but could never use any of it. I have checked out lirc from cvs and compiled it as is, selected macmini as the device and it worked pretty much out of the box. I did go one step further and created a device upgrade for any JP1 remote (hifi-remote.com) and created an lircd.conf as well as lircrc file that I would like to share for those that use JP1 remotes. Please let me know how I can upload these files.

For those that are running into the same problem that gives you an error similar to this "this device driver does not support the new LIRC interface" when lircd is run with the -n option, just checkout the latest CVS and compile it.

Comment by sdavilla, Apr 27, 2008

Sorry about your problems with lircd. I can't explain why you had problems while other did not. Mystery time.

Are these binary or text files?

Comment by vvadim, Apr 28, 2008

text files.

Comment by chrisbook, Apr 30, 2008

I had the same problem as DaveHard? in that the repeat section did not show any dots until I alternated buttons (which is says NOT to do). I toggled between MINUE and PLAY just to get the script to complete. Once it generated the config file most buttons worked except two (PLAY acted the same as MINUS and MENU acted the same as PLUS). The script generated a "toggle_bit_mask 0x9" entry in my lircd.conf file. I tried removing this line but it caused no button presses to show up in irw. I found that if I changed the value to 0x0 it now works perfectly, but I have no idea why.

Comment by martin.gschwandtner, May 25, 2008

Lirc works just fine for Mythtv, but not for MythVideo? (mplayer). How can I enable the IR for mplayer as well? BR Martin

Comment by sdavilla, May 25, 2008

need to add a mplayer config info to lircrc. Something like this

# mplayer codes
begin
        prog = mplayer
        button = PLAY
        config = pause
        repeat = 3
end
begin
        prog = mplayer
        button = PLUS
        config = volume +1
        repeat = 1
end
begin
        prog = mplayer
        button = MINUS
        config = volume -1
        repeat = 1
end
begin
        prog = mplayer
        button = NEXT
        config = pt_step 1
        repeat = 0
end
begin
        prog = mplayer
        button = PREV
        config = pt_step -1
        repeat = 0
end
begin
        prog = mplayer
        button = MENU
        config = mute
end
Comment by elliot.foster, Aug 02, 2008

For the record, I have the same problem as vvadim above. This is on a clean Hardy Heron install. The lirc package version is: 0.8.3~pre1-0ubuntu7.1

The one item of note is that I did not patch lirc, as it looks like 0.8.3 already has a version of the patch applied (probably why the wiki says the patch is necessary for <= 0.8.2.)

from the log:

Aug  2 01:13:05 qbert lircd-0.8.3pre1[21709]: accepted new client on /dev/lircd
Aug  2 01:13:05 qbert lircd-0.8.3pre1[21709]: could not get hardware features
Aug  2 01:13:05 qbert lircd-0.8.3pre1[21709]: this device driver does not support the new LIRC interface
Aug  2 01:13:05 qbert lircd-0.8.3pre1[21709]: major number of /dev/usb/hiddev0 is 180
Aug  2 01:13:05 qbert lircd-0.8.3pre1[21709]: LIRC major number is 61
Aug  2 01:13:05 qbert lircd-0.8.3pre1[21709]: check if /dev/usb/hiddev0 is a LIRC device
Aug  2 01:13:05 qbert lircd-0.8.3pre1[21709]: caught signal
Comment by elliot.foster, Aug 02, 2008

Ah, the solution was to use the hardware.conf that came with ubuntu instead of the hardware.conf that I whacked together:

REMOTE="Apple Mac mini USB IR Receiver"
REMOTE_MODULES=""
REMOTE_DRIVER="macmini"
REMOTE_DEVICE=""
REMOTE_LIRCD_CONF="apple/lircd.conf.macmini"
REMOTE_LIRCD_ARGS=""

irw now works.

Comment by daniel.silva, Dec 21, 2008

wadim above mentioned using a JP1 remote with the appletv. Does that require programming the remote with a special cable and software from hifi-remote.com or can a JP1 remote be setup for the appletv using just the remote's own keypad?

Comment by k...@hudat.com, Feb 20, 2009

Happy Day for Harmony Remote users!

Looks like the Plex fork of XBMC has given us a little gift. If you own a harmony remote you don't have to painstakingly learn any commands anymore. You can now configure a device which has a ton of commands. The idea is detailed here:

http://wiki.plexapp.com/index.php/Harmony_Support

Basically you add a device to your Harmony Remote, a Media Center PC, manufacturer "Plex" and the model "Plex Player". That's basically it. The codes all work by default with the AppleTV and provides quite a TON of keys. Yay :-)

You can use irrecord on the AppleTV (as detailed above) to learn the keys into a .conf file, or you can download the lirc plex.conf I'll be attaching via the mailing list. Just search the discussion/forum for lirc plex.conf.

Comment by oliver.bode, Mar 25, 2009

I've been battling with lirc version 0.8.3~pre1 for a couple of hours. irrecord could not complete the last step and irw didn't work, as others reported.

I decided to remove the package and then downloaded lirc version 0.8.4a, I compiled it for use with the macmini and was finally able to create the file in /etc/lirc/lircd.conf using irrecord I then created ~/.mythtv/lircrc based on the examples above and needed to create symbolic links for /usr/sbin/lircd and /user/sbin/lircmd from the files which were now sitting /usr/local/sbin to get /etc/init.d/lirc to work. At last I've got a fully functioning mythtv on my atv using the apple remote - Hooray.

Comment by wck555, Apr 24, 2009

I've also battled for several hours with lirc, but it's now working :) I am using intrepid ibex (8.10).

When I got the lirc source using "apt-get source lirc" I received version 0.8.3-0ubuntu2. I didn't patch it (the 0.8.2 patch doesn't work and I think the repeat bug is fixed in 0.8.3). I built and installed lirc using the original instructions.

To get irrecord to work I had to do several things.

  • Reboot. The /dev/usb/hiddev0 didn't show up until I rebooted
  • Delete the existing /etc/lirc/lircd.conf. irrecord first complained "irrecord: file "/etc/lirc/lircd.conf" does not contain valid data". Then I added a apple remote block to lircd.conf. irrecord ran, but never wrote anything into the file. Finally deleting lircd.conf worked. irrecord created a new lircd.conf file from scratch
  • I followed chrisbook's advice on the repeat section

Then I had problems running lirc. When I tried to start lirc, nothing happened:

sudo /etc/init.d/lirc restart

running irw gave me a "connect: No such file or directory" error

I noticed that START_LIRCD was set to "false" in /etc/lirc/hardware.conf. I set this flag to true

#Enable lircd
START_LIRCD="true"

I also made the following changes to hardware.conf based on elliot.foster's comment

#Chosen Remote Control
REMOTE="Apple Mac mini USB IR Receiver"
REMOTE_MODULES=""
REMOTE_DRIVER="macmini"
REMOTE_DEVICE="/dev/usb/hiddev0"
REMOTE_LIRCD_CONF=""
REMOTE_LIRCD_ARGS=""

Then lirc started up. After that irw worked, and the remote worked in MythTV!

sudo /etc/init.d/lirc start
 * Loading LIRC modules
   ...done.
 * Starting remote control daemon(s) : LIRC 
   ...done.

Whew! I think that's everything.


Sign in to add a comment
Hosted by Google Code