How to get a seamless remote experience
#3
2. Remote (continued)

Creating a custom config file
If the grep command did not return any output, however, you will have to create your custom config file. Let's look at a snippet of stock config file (rc6_mce, for MCE remotes) for the general syntax of such a config file:
Code:
0x800f041e KEY_UP
0x800f041f KEY_DOWN
0x800f0420 KEY_LEFT
0x800f0421 KEY_RIGHT
0x800f0422 KEY_OK
So on the left we have a code (which should correspond to the scan code) starting with '0x'. On the right we have the key that has to be pressed. This key can be any 'normal' key on a keyboard (e.g. KEY_A) or any more or less standardized MCE 'key' such as KEY_PLAY, KEY_STOP, KEY_MENU, KEY_RED/GREEN/YELLOW/BLUE or KEY_NUMERIC_x. I'm not sure though how or where those MCE keys are mapped, but many of them work in XBMC. Regardless, all we really need are regular keys anyway, since we can simply map those in the keyboard.xml file (section 3) and many of them are already mapped by default. After all, XBMC can already be controlled using a regular keyboard and we are emulating a keyboard. For instance, XBMC doesn't seem to pickup KEY_INFO, but the 'I' in the keyboard is (also) mapped to this action, we can just use 0x123abc KEY_I, with 123abc being the scancode for the button with which you want to trigger the video info in XBMC.

So what you have to do know if have a good look at your remote and start thinking about which button you want to link to which keyboard button and/or action. I suggest you start defining the default actions that are always the same anyway, such as play, pause, left, right, etc. So open one terminal window with the `ir-keytable -t` command running and one text editor with your config file. Now, for every unambiguous key press it once on your remote, copy the scancode to your config file and connect it to the appropriate action. All in the format depicted above. So if your scancode is 44222a when you press your play button, the line in your config file should look like this: "0x44222a KEY_PLAY". At the end of this process you will have a config file with which your remote can at least control the basic functions.

Before you load your config file I suggest you put the following line/comment on line 1:

Code:
# table some-name, type: $proto

Loading your config file
Whether you have created your own config file or used a stock one, you have to load it in order for it to be used. The config file goes into the /etc/rc_keymaps/ folder. The name doesn't really matter. Just keep it brief and concise. By the way, do not overwrite the standard config files in /lib/udev/rc_keymaps/. If you want to use one, copy it to /etc/rc_keymaps/ and modify it there.

Anyway, to load your config file, use ir-keytable again:

Code:
ir-keytable -c -p $proto -w /etc/rc_keymaps/$file

If you've defined the correct protocol in the comment in the file, you can ommit the -p $proto part. Here I use:
Code:
ir-keytable -c -w /etc/rc_keymaps/onkyo-dvd

For the record, I'm using a universal remote that came with my TX-NR509 AV receiver. It can control a lot of devices (I have a good 10 pages of remote control codes) and I've set it up as a DVD player remote. This is my config file:
Code:
# table onkyo-dvd, type: NEC

0x45b512 KEY_S                  # Source On/Off

0x45b521 KEY_ENTER
0x45b580 KEY_UP
0x45b581 KEY_DOWN
0x45b551 KEY_LEFT
0x45b54d KEY_RIGHT

0x45b520 KEY_MENU               # Setup
0x45b522 KEY_BACK               # Return
0x45b584 KEY_I                  # Video
0x45b5de KEY_C                  # Guide/Top Menu

0x45b527 KEY_H                  # Home
0x45b516 KEY_Z                  # Display

0x45b515 KEY_PLAY
0x45b500 KEY_PLAYPAUSE
0x45b514 KEY_STOP

#0x2d2d32 KEY_REWIND
#0x2d2d33 KEY_FASTFORWARD

0x45b535 KEY_RED
0x45b536 KEY_GREEN
0x45b537 KEY_YELLOW
0x45b533 KEY_BLUE

0x45b50a KEY_NUMERIC_0
0x45b501 KEY_NUMERIC_1
0x45b502 KEY_NUMERIC_2
0x45b503 KEY_NUMERIC_3
0x45b504 KEY_NUMERIC_4
0x45b505 KEY_NUMERIC_5
0x45b506 KEY_NUMERIC_6
0x45b507 KEY_NUMERIC_7
0x45b508 KEY_NUMERIC_8
0x45b509 KEY_NUMERIC_9

#
# Onkyo Remote Code: 33504
#

But like I said, for now, just pay attention to the standard functionality. Also note that ir-keytable will segfault if it finds any comments prior to the first definition. Took me a while to figure out what the hell was wrong with my config file (not that that is a valid reason to segfault but ok). Anyway, the command should output something like this:

Code:
Read onkyo-dvd table
Old keytable cleared
Wrote 29 keycode(s) to driver
Protocols changed to NEC

If you open `ir-keytable -t` again the output for the configured buttons should be similar to this:
Code:
1309389537.706840: event MSC: scancode = 45b521
1309389537.706868: event key down: KEY_ENTER (0x001c)
1309389537.706878: event sync
1309389537.738835: event MSC: scancode = 45b521
1309389537.738859: event MSC: scancode = 45b521
1309389537.986104: event key up: KEY_ENTER (0x001c)
1309389537.986119: event sync
1309389543.267687: event MSC: scancode = 45b581
1309389543.267713: event key down: KEY_DOWN (0x006c)
1309389543.267714: event sync
1309389543.516097: event key up: KEY_DOWN (0x006c)
1309389543.516112: event sync
1309389547.808589: event MSC: scancode = 45b551
1309389547.808612: event key down: KEY_LEFT (0x0069)
1309389547.808613: event sync
1309389548.056101: event key up: KEY_LEFT (0x0069)
1309389548.056117: event sync
1309389549.183552: event MSC: scancode = 45b54d
1309389549.183579: event key down: KEY_RIGHT (0x006a)
1309389549.183581: event sync
1309389549.426105: event key up: KEY_RIGHT (0x006a)
1309389549.426120: event sync
1309389552.252585: event MSC: scancode = 45b522
1309389552.252610: event key down: KEY_BACK (0x009e)
1309389552.252611: event sync
1309389552.496098: event key up: KEY_BACK (0x009e)
1309389552.496118: event sync

So it should recognize the keys you entered. Now start XBMC and see if the buttons you configured actually do something there as well!

If you want to load the config file at boot time you can use /etc/rc_maps.cfg, but I haven't quite figured out how yet. Since my HTPC is also my server, uptime is of some significance to me, so I can't just reboot whenever I want. But in the meantime you can copy the ir-keytable command to /etc/rc.local.

2.3 Let the kernel cooperate with LIRC

Apparently you can also combine the strengths of both the in-kernel mapping and keyboard emulation with LIRC, which does seem to have some capabilities that the kernel drivers don't, such a connecting certain scripts to certain buttons, through irexec. You'll only need to do this though if you need this sort of advanced functionality. According to the LIRC website you need at least 0.9.0, but I also got it working with LIRC 0.8.7. YMMV though. I also didn't really test it very thoroughly, as I don't have any use for LIRC at this moment. For this section you will need to have done everything from section 2.2. You can skip section 2.1.

First, start with installing lirc if you've deinstalled it or never installed it in the first place. If you're asked what remote you want to use, choose "Linux input layer (/dev/input/eventX)". Generally you won't need a transmitter device for XBMC, so select "none". For the device, pick the one with the name in it. In my case, this is the resulting hardware.conf. If your package manager doesn't generate it, just use mine and adapt it:

Code:
#Chosen Remote Control
REMOTE="Linux input layer (/dev/input/eventX)"
REMOTE_MODULES=""
REMOTE_DRIVER="devinput"
REMOTE_DEVICE="/dev/input/by-id/usb-Philips_eHome_Infrared_Transceiver_PH00OXFk-event-if00" ### Change this one!!!! ###
REMOTE_SOCKET=""
REMOTE_LIRCD_CONF="devinput/lircd.conf.devinput"
REMOTE_LIRCD_ARGS=""

#Chosen IR Transmitter
TRANSMITTER="None"
TRANSMITTER_MODULES=""
TRANSMITTER_DRIVER=""
TRANSMITTER_DEVICE=""
TRANSMITTER_SOCKET=""
TRANSMITTER_LIRCD_CONF=""
TRANSMITTER_LIRCD_ARGS=""

#Enable lircd
START_LIRCD="true"

#Don't start lircmd even if there seems to be a good config file
#START_LIRCMD="false"

#Try to load appropriate kernel modules
LOAD_MODULES="true"

# Default configuration files for your hardware if any
LIRCMD_CONF=""

FORCE_NONINTERACTIVE_RECONFIGURATION="false"
START_LIRCMD=""

Then, modprobe the module that provides support for the LIRC protocol to ir-keytable:

Code:
modprobe ir-lirc-codec

If you want to automatically load this module at boot time, add it to /etc/modules. Next, execute the same ir-keytable command again, but add LIRC to your comma separated (list of) protcol(s), e.g.:

Code:
ir-keytable -c -w /etc/rc_keymaps/myconfig -p NEC,LIRC

If you want to make this persistent, change the command in your /etc/rc.local (or equivalent) as well. Note that if you run a Debian based distro, you wil have to (re)issue this command after you reinstall or dpkg-reconfigure lirc, because it will reset the protocol to LIRC only.

Then, again if your package manager didn't generate a correct hardware.conf, you'll most likely also need to modify your lircd.conf. For now, just add

Code:
include "/usr/share/lirc/remotes/devinput/lircd.conf.devinput"

So now the chain looks like this:
Code:
events -> kernel (ir-keytable) -> LIRC -> mappings from your ir-keytable config file chained through to LIRC (through the include line in lircd.conf)
                                       -> custom mappings from lircd.conf (through custom directives in lircd.conf)
Now you can do all the LIRC-only stuff in lircd.conf, while retaining the advantage of kernel drivers. If all is well you should be able to see events in irw:

Code:
000000008001001c 00 KEY_ENTER devinput
0000000080010067 00 KEY_UP devinput
0000000080010069 00 KEY_LEFT devinput
000000008001006a 00 KEY_RIGHT devinput
000000008001006c 00 KEY_DOWN devinput

Up next: multi-purpose buttons with keyboard.xml.
Reply


Messages In This Thread
[Linux] How-to get a seamless remote experience: part III - by LB06 - 2011-06-29, 20:01
[No subject] - by darkscout - 2011-06-29, 20:11
[No subject] - by LB06 - 2011-06-29, 20:27
[No subject] - by gazrat - 2011-06-30, 00:09
[No subject] - by Anastrophe - 2011-06-30, 16:48
[No subject] - by gazrat - 2011-06-30, 21:48
[No subject] - by LB06 - 2011-06-30, 22:34
[No subject] - by gazrat - 2011-07-04, 18:28
[No subject] - by LB06 - 2011-07-04, 18:59
[No subject] - by gazrat - 2011-07-04, 23:52
[No subject] - by LB06 - 2011-07-04, 23:58
[No subject] - by gazrat - 2011-07-05, 00:28
[No subject] - by LB06 - 2011-07-05, 01:17
[No subject] - by wsnipex - 2011-07-05, 09:37
[No subject] - by darkscout - 2011-07-05, 10:23
[No subject] - by LB06 - 2011-07-05, 10:37
[No subject] - by gazrat - 2011-07-05, 20:45
[No subject] - by LB06 - 2011-07-05, 22:11
[No subject] - by gazrat - 2011-07-05, 22:31
[No subject] - by LB06 - 2011-07-05, 23:10
[No subject] - by gazrat - 2011-07-05, 23:16
[No subject] - by SirHc - 2011-07-07, 22:07
Nesting actions? - by konti - 2011-07-08, 12:19
[No subject] - by SirHc - 2011-07-08, 12:45
[No subject] - by LB06 - 2011-07-08, 13:30
[No subject] - by LB06 - 2011-07-08, 13:33
[No subject] - by mason - 2011-07-08, 13:51
[No subject] - by SirHc - 2011-07-08, 20:22
[No subject] - by teeedubb - 2011-07-10, 11:47
[No subject] - by LB06 - 2011-07-10, 13:02
[No subject] - by LB06 - 2011-07-10, 13:55
[No subject] - by teeedubb - 2011-07-10, 14:10
[No subject] - by LB06 - 2011-07-10, 14:56
[No subject] - by gazrat - 2011-07-12, 19:40
[No subject] - by LB06 - 2011-07-12, 22:20
[No subject] - by blubyu - 2011-07-13, 03:03
[No subject] - by teeedubb - 2011-07-14, 05:21
[No subject] - by toliman - 2011-07-27, 14:58
[No subject] - by LB06 - 2011-07-27, 16:16
[No subject] - by Jayphen - 2011-08-24, 06:27
[No subject] - by recluce - 2011-08-24, 19:16
[No subject] - by LB06 - 2011-08-24, 19:19
[No subject] - by Jayphen - 2011-08-25, 00:42
[No subject] - by LB06 - 2011-08-25, 00:57
[No subject] - by Jayphen - 2011-08-25, 01:18
[No subject] - by recluce - 2011-08-25, 01:21
[No subject] - by LB06 - 2011-08-25, 01:27
[No subject] - by LB06 - 2011-08-25, 01:29
[No subject] - by Jayphen - 2011-08-25, 01:30
[No subject] - by LB06 - 2011-08-25, 01:31
[No subject] - by Jayphen - 2011-08-25, 01:33
[No subject] - by LB06 - 2011-08-25, 01:52
[No subject] - by recluce - 2011-08-25, 01:57
[No subject] - by Jayphen - 2011-08-25, 02:10
[No subject] - by LB06 - 2011-08-25, 10:25
[No subject] - by koekiemonster - 2011-09-15, 23:29
RE: - by GreatEmerald - 2013-03-11, 20:57
[No subject] - by stefanwa - 2011-09-20, 16:50
Logout Mark Read Team Forum Stats Members Help
How to get a seamless remote experience9