Denon RC-1146 remote with LibreELEC 9

In LibreELEC 9, the IR driver was changed from lircd to in-kernel decoding with ir-keytable.

I'm still using the GPIO IR receiver from this tutorial on my Raspberry Pi.

To activate it, I need to add a dtoverlay.

# mount -o remount,rw /flash
# echo dtoverlay=gpio-ir >> /flash/config.txt
# mount -o remount,ro /flash

I then proceeded along this tutorial.

# systemctl stop kodi
# systemctl stop eventlircd

I get from ir-keytable:

# ir-keytable
Found /sys/class/rc/rc0/ (/dev/input/event2) with:
 Name: gpio_ir_recv
 Driver: gpio_ir_recv, table: rc-rc6-mce
 lirc device: /dev/lirc0
 Supported protocols: other lirc rc-5 rc-5-sz jvc sony nec sanyo mce_kbd rc-6 sharp xmp
 Enabled protocols: lirc nec rc-6
 bus: 25, vendor/product: 0001:0001, version: 0x0100
 Repeat delay = 500 ms, repeat period = 125 ms

After some trial and error with different protocols, I finally found:

# ir-keytable --protocol sharp --test
Protocols changed to sharp
Testing events. Please, press CTRL-C to abort.
1009.423304: lirc protocol(sharp): scancode = 0x8ac
1009.423341: event type EV_MSC(0x04): scancode = 0x8ac
1009.423341: event type EV_SYN(0x00).

As with all things Linux, documentation is notoriously difficult to come by. According to ir-keytable --version, LibreELEC-9.0.1 uses v4l-utils-1.14.2. This is an important detail since v4l-utils have since changed their keytable format to toml!

I could not find any documentation for the old keytable format, so I had a look at the source code of keytable.c.

Apparently, a # in the first line can be followed by table and type keywords specifying the name of the table and what is otherwise known as the protocol, separated by various combinations of whitespace, equal signs, colons and commas. Otherwise, lines beginning with # are ignored. The remaining lines may start with an optional keyword "scancode", followed by whitespace, equals sign or colon. This is followed by the scancode (in a format understood by strtoul(3)) and terminated by whitespace, equals sign or colon. Finally, there should be a keycode terminated by whitespace, equals sign, colon or an open parenthesis(!). The keycodes can be ones listed by irrecord --list or, better yet, ones from the devinput section of /usr/share/kodi/system/Lircmap.xml to make sure they are assigned the desired function in Kodi, or in a format suitable for strtol(3). The rest of the line is ignored and can thus be used for comments.

Since Kodi is connected to the DVD input of my amp, I used the remote's default DVD profile. Eventually, I ended up with the following /storage/.config/rc_keymaps/denon1146dvd:

# table denon1146dvd, type: sharp
0x6c0 KEY_POWER
0x881 KEY_0
0x882 KEY_1
0x883 KEY_2
0x884 KEY_3
0x885 KEY_4
0x886 KEY_5
0x887 KEY_6
0x888 KEY_7
0x889 KEY_8
0x88a KEY_9
0x88c KEY_SUBTITLE 10+
0x891 KEY_INFO menu
0x892 KEY_BACK
0x898 KEY_NEXT
0x899 KEY_PREVIOUS
0x89a KEY_FASTFORWARD
0x89b KEY_REWIND
0x89d KEY_PAUSE
0x8a0 KEY_PLAY
0x8a1 KEY_STOP
0x8ac KEY_UP
0x8ad KEY_DOWN
0x8ae KEY_RIGHT
0x8af KEY_LEFT
0x8bb KEY_ENTER
0x8bc KEY_EPG search
0x8bd KEY_MENU top menu

The non-obvious assigments are: the key labelled »menu« on the remote sends a KEY_INFO code since that seems to be the most useful code in Kodi (file info or playing info, respectively). The »top menu« key sends KEY_MENU which takes you to Kodi's main menu and toggles the play menu. I assigned KEY_EPG to the »search« key since KEY_EPG invokes the context menu in the menu and the decoder info while playing. Finally, I cheekily remapped the »10+« key to KEY_SUBTITLE since the former seems to be unused and I use the latter a lot.

Last, I activated it like this:

# echo '* * denon1146dvd' >> /storage/.config/rc_maps.cfg

Denon RC-1146 remote with Kodi

Today I created a configuration file for my Denon RC-1146 remote. Since Kodi is connected to the DVD input of my amp, I used the remote's default DVD profile.

First, I wired up the IR detector to the Raspberry Pi's GPIO pins as shown in the tutorial.

Because I use OpenELEC rather than RaspBMC, I then had to edit the configuration file to load the device tree overlay.

# mount -o remount,rw /flash
# echo dtoverlay=lirc-rpi >> /flash/config.txt
# mount -o remount,ro /flash

From LibreELEC 9, rc-core is used instead of lircd, so the instructions below will need to change.

For the /storage/.config/lircd.conf file, I tweaked some of the codes for Kodi: the key labelled »menu« on the remote sends a KEY_INFO code since that seems to be the most useful code in Kodi (file info or playing info, respectively). The »top level« key sends KEY_MENU which takes you to Kodi's main menu and toggles the play menu. I assigned KEY_EPG to the »setup« key since KEY_SETUP doesn't seem to do anything while KEY_EPG invokes the context menu in the menu and the decoder info while playing. Finally, I cheekily remapped the »10+« key to KEY_SUBTITLE since the former seems to be unused and I use the latter a lot.

The numeric keys are assigned KEY_NUMERIC prefixes because Kodi requires it.

Also, the key labelled »enter« is assigned to KEY_OK and »return« is assigned to KEY_EXIT since that seems to be more appropriate in the context of lircd.

# Please make this file available to others
# by sending it to <lirc@bartelmus.de>
#
# this config file was automatically generated
# using lirc-0.9.1-git(default) on Tue Apr  5 23:36:06 2016
#
# contributed by <jocki84@googlemail.com>
#
# brand: Denon
# model no. of remote control: RC-1146
# devices being controlled by this remote: Denon DVD Players
# This multi-purpose remote has many emulations, these codes
# were generated using the default setting for DVD, 32134.
#

begin remote

  name  DENON_RC1146_DVD
  bits           15
  flags SPACE_ENC|CONST_LENGTH
  eps            30
  aeps          100

  one           290  1815
  zero          290   760
  ptrail        290
  gap          66911
  toggle_bit_mask 0x0

      begin codes
          KEY_POWER                0x300C
          KEY_UP                   0x08D4
          KEY_DOWN                 0x092B
          KEY_LEFT                 0x082B
          KEY_RIGHT                0x09D4
          KEY_OK                   0x088B # KEY_ENTER
          KEY_INFO                 0x09DB # KEY_MENU
          KEY_MENU                 0x090B # KEY_DVD
          KEY_EPG                  0x08F4 # KEY_SETUP
          KEY_EXIT                 0x0924
          KEY_REWIND               0x089B
          KEY_PLAY                 0x0814
          KEY_FASTFORWARD          0x0964
          KEY_PREVIOUS             0x099B
          KEY_PAUSE                0x091B
          KEY_STOP                 0x09EB
          KEY_NEXT                 0x0864
          KEY_NUMERIC_1            0x0904
          KEY_NUMERIC_2            0x08FB
          KEY_NUMERIC_3            0x0884
          KEY_NUMERIC_4            0x097B
          KEY_NUMERIC_5            0x0984
          KEY_NUMERIC_6            0x087B
          KEY_NUMERIC_7            0x0844
          KEY_NUMERIC_8            0x09BB
          KEY_NUMERIC_9            0x0944
          KEY_NUMERIC_0            0x09FB
          KEY_SUBTITLE             0x08C4 # KEY_102ND
      end codes

end remote

Note for LibreELEC 8.2 In order for lircd to start, it's necessary to

$ touch /storage/.cache/services/lircd.conf

Note for LibreELEC 7.90.008: lircd should be started when the /dev/lirc0 device is created by the lirc_rpi kernel module. This is achieved using udev which starts an appropriate instance of /usr/lib/systemd/system/lircd.service (such as lircd@lirc0:default:lircd.conf.rpi) from /usr/lib/udev/rules.d/98-lircd.rules when the device appears. Occasionally, there might be a link in .config/system.d/multi-user.target.wants which leads to lircd being started before the device node has been created. Such a link should not exist.

Using RaspBMC 1.0 (Frodo) with bluetooth keyboard

Without having checked whether each step was actually necessary, this is how I got a Bluetooth keyboard working with RaspBMC 1.0 (Frodo). Mostly based on this installation and this setup.

SSH into your RaspBMC with username pi and password raspberry.

$ sudo su
# update-rc.d dbus defaults # prevents bluez installation failure
# apt-get install bluez python-gobject # gobject required by bluez-simple-agent

If the installation succeeded, the bluetooth service should be up and running (version bluez-4.99_2 in my case):

# service bluetooth status
[ ok ] bluetooth is running.

Otherwise it can be started with

# service bluetooth start

Put the keyboard into pairing mode and find out its address using

# hcitool scan
Scanning ...
        00:18:00:0A:F7:E3       BTKB-F7E3

With the keyboard still in pairing mode, I then attempted the pairing process with

# bluez-simple-agent hci0 00:18:00:0A:F7:E3
Creating device failed: org.bluez.Error.AlreadyExists: Already Exists

Apparently, the error indicates that the device is already paired (because I had previously used it on my PC), and the remedy is adding an arbitrary 3rd argument to the invocation.

# bluez-simple-agent hci0 00:18:00:0A:F7:E3 a
RequestPinCode (/org/bluez/1981/hci0/dev_00_18_00_0A_F7_E3)
Enter PIN Code: 1234
Release
New device (/org/bluez/1981/hci0/dev_00_18_00_0A_F7_E3)

I first entered the PIN code when prompted and had typed it on the keyboard followed by Enter before the line that says "Release".

I then created the entry to automatically pair the device after it disconnects:

# bluez-test-device trusted 00:18:00:0A:F7:E3 yes

This adds a line containing the device address to the file /var/lib/bluetooth/<adaptor address>/trusts.

Now connect the keyboard and load the necessary uinput module.

# bluez-test-input connect 00:18:00:0A:F7:E3
# modprobe -i uinput
# echo uinput >> /etc/modules

After restarting XBMC, the keyboard worked.

# restart xbmc