Carlos Santos

iOS Dev

Apple Remote A1156 + Intel NUC + Kodibuntu 14 (Helix) + ir-keytables

2015-01-25 4 mintech

Apple Remote A1156 + Intel NUC + Kodibuntu 14 (Helix) + ir-keytables unsplash-logoCarlos Irineu da Costa

Since I’ve spent a lot of time studying how the hell could I reuse my dumped white Apple Remote again, I had to write a tutorial for NO ONE ever waste that amount of time again.

Since I tried several approaches, I advice you to don’t touch any LIRC stuff, or inputlirc. Stay with ir-keytables! It’s very simple!


Installing ir-keytable

sudo apt-get install ir-keytable

List your IR receiver with the following command:

sudo ir-keytable

And you’ll see something like this:

Found /sys/class/rc/rc0/ (/dev/input/event4) with:
 Driver ite-cir, table rc-rc6-mce
 Supported protocols: NEC RC-5 RC-6 JVC SONY SANYO LIRC other
 Enabled protocols: NEC RC-6
 Name: ITE8713 CIR transceiver
 bus: 25, vendor/product: 1283:0000, version: 0x0000
 Repeat delay = 500 ms, repeat period = 125 ms

With that info we can get the driver’s name (itecir), supported protocols and even the transceiver name,(ITE8713) that we’ll need later.


So we need to translate the keystrokes into actions, so we can test keystrokes with the following command:

sudo ir-keytable -p NEC,RC6 -t

Click on some keys on your remote and take notes of each hexadecimal code output that is shown on the console, like the following:

1422203031.291478: event type EV_MSC(0x04): scancode = 0x77e190e6
1422203032.349079: event type EV_MSC(0x04): scancode = 0x77e130e6

Those two, will be your addresses to the keys. So let’s create a mapping file. Actually we’ll need 2: one for ir-keytables, another for KODI (to be able to be translated to its internal commands). So let’s start with the ir-keytables mapping file:

sudo vim /etc/rc_keymaps/apple_remote

And insert the keys you want (as these are my addresses, yours could be different, so pay attention to the previous test where I asked you to note down the hex addresses). Add keys like these:

==> apple_remote <==
# Apple Remote
0x77e150e6 KEY_UP
0x77e130e6 KEY_DOWN
0x77e190e6 KEY_LEFT
0x77e160e6 KEY_RIGHT
0x77e1a0e6 KEY_ENTER
0x77e1c0e6 KEY_ESC

Now we’ll create the KODI key mapping file:

vim ~/.kodi/userdata/Lircmap.xml

And add the following:

 <remote device="Apple_Remote_A1156">

Startup script

Now we just need to add a little startup script that will set the keymaps at startup. I used a service, but you can use whatever you want as long as it runs on startup:

Pay attention to your device id, you must have noted earlier: my NUC’s receiver is ITE8713.

If you opt for a /etc/init.d/ script, please enter the following commands:

sudo vim /etc/init.d/make-ir-work

Add the following text:

#!/usr/bin/env bash
echo 'Modprobing...'
modprobe -r nuvoton_cir
sleep 1
echo 'Echoing...'
echo "auto" > /sys/bus/acpi/devices/ITE8713:00/physical_node/resources
#sleep 1
echo 'Modprobing...'
modprobe nuvoton-cir
sleep 1
echo 'Clearing the old keytable...'
ir-keytable -c
sleep 1
echo 'Injecting the new keytable...'
ir-keytable -p NEC,RC6 -w /etc/rc_keymaps/apple_remote
echo 'Done.'

Check that with that command we’re enabling NEC/RC6 modules and applying the apple_remote keymap.

Now just make it executable:

sudo chmod a+x /etc/init.d/make-ir-work

And add it to the startup:

sudo update-rc.d make-ir-work defaults 99

The 99 means make-ir-work gets sequence number 99 at boot, the range starts on 1 and goes till 99, most boot scripts have smaller numbers, this ensures this script has all its dependencies ready.

And now it’s reboot time!

Smoke test

Make a smoke test, ensure that when running:

sudo ir-keytable -p NEC,RC6 -w /etc/rc_keymaps/apple_remote # adds a new mapping

You’ll see something like:

> Wrote 8 keycode(s) to driver

Have fun with your Apple Remote! The bad thing is… the remote hasn’t that much keys to play with KODI, but it saves an electronic piece from trash.