Architecture and Customization

Version 11 (christian, 01/01/2015 03:31 pm)

1 2 christian
{{toc}}
2 2 christian
3 1
h1. Background
4 2 christian
5 2 christian
LinHES 7 introduced a number of changes to the way remotes and associated devices are handled. This is largely being picked up from changes in the Linux base. The way remotes are now handled is significantly different and also requires a different tool set to build and diagnose an implementation. In general this new implementation is a significant improvement in what was previously a rather adhoc structure.
6 2 christian
7 2 christian
This guide will attempt to introduce you to the new architecture and tool sets relevant to LinHES.
8 2 christian
9 2 christian
h1. Architecture
10 7 christian
11 5 christian
The following picture is a logical representation of how various blocks in LinHES are connected.
12 8 christian
13 11 christian
!LinHES-Remote-Arch5.1.jpg!
14 5 christian
15 5 christian
As of LinHES 7, the remote drivers are included in the kernel whereas previously they were part of the lirc subsystem. If Lircd is not running then by default the Remote Driver will issue keyboard and/or mouse events. These events will be seen by higher level applications such as X and MythTV as if normal keyboard and mouse events occurred. Thus if you do not require certain lirc functions such as irexec then you can quite happily not use lirc at all. Note, some remotes actually do issue mouse events such as certain imon remotes.
16 9 christian
17 9 christian
h2. Remote Receiver
18 9 christian
19 9 christian
Each Remote Receiver will be identified by a unique device ID which will be associated by a driver that recognizes that ID. In most cases this should automatically make the needed associations. In some rare cases more than one driver may try to associate with the device which can cause conflicts. In these exceptional cases, this device can be blacklisted from the driver or the driver itself can be blacklisted.
20 9 christian
21 9 christian
The device ID can normally be found using tools such "lsusb" where you may see an entry similar to:
22 9 christian
<pre>Bus 003 Device 002: ID 15c2:0043 SoundGraph Inc.</pre>
23 9 christian
24 9 christian
h2. Remote Driver
25 9 christian
26 9 christian
The driver does not actually know about the remote, it only sees the IR codes received by and translated by the Remote Receiver. The Remote Receiver may use any number of protocols (e.g. RC6, imon, etc) and its associated driver will normally understand all of the protocol variants that the Remote Receiver supports.
27 9 christian
28 9 christian
The Remote Driver will interact with the Remote Receiver in order to maintain the device and of course receive information from the remote itself. Depending on the Remote Receiver and associated Remote, the driver may separate the events as keyboard and mouse events. In this case you may see entries in "/dev/input/by-id" with entries such as "usb-15c2_0043-event-if00" and "usb-15c2_0043-event-mouse". Note in customization it is generally safer to specify a driver using its "/dev/input/by-id" path rather than the "/dev/input" path.
29 9 christian
30 9 christian
h2. ir-keytable
31 9 christian
32 9 christian
ir-keytable interacts with the driver and normalizes its output. It utilizes a keymap file normally found in "/etc/rc_keymaps" and the default association with the driver will be defined by "/etc/rc_maps.cfg"
33 9 christian
34 9 christian
There are a number of things that you can do with ir-keytable including:
35 9 christian
* Identify the driver and its protocols (eg. ir-keytable)
36 9 christian
* Monitor the driver output of received events from the Remote Receiver (eg. ir-keytable -t)
37 9 christian
* configure the driver for items such as protocols (eg. ir-keytable -p RC6, LIRC, etc)
38 9 christian
* Load a specific or custom keymap for a driver (eg. ir-keytable -w /etc/rc_keymaps/imon_mce)
39 9 christian
40 9 christian
For example, in one of my systems ir-keytable returns:
41 9 christian
<pre># ir-keytable
42 9 christian
Found /sys/class/rc/rc0/ (/dev/input/event7) with:
43 9 christian
        Driver imon, table rc-imon-pad
44 9 christian
        Supported protocols: RC-6 other
45 9 christian
        Enabled protocols: RC-6
46 9 christian
        Repeat delay = 500 ms, repeat period = 33 ms</pre>
47 9 christian
48 10 christian
I also force my imon receiver (to generate the above) to use the RC6 protocol and the imon_mce keytable instead of the default imon protocol and imon keymap using:
49 1
<pre>/usr/bin/ir-keytable -c -p RC6 -w /etc/rc_keymaps/imon_mce</pre>
50 10 christian
51 10 christian
I test the output of my driver using "ir-keytable -t" which yields output such as:
52 10 christian
<pre># ir-keytable -t
53 10 christian
Testing events. Please, press CTRL-C to abort.
54 10 christian
1330396066.132941: event MSC: scancode = 800ff418
55 10 christian
1330396066.132950: event key down: KEY_PAUSE (0x0077)
56 10 christian
1330396066.132951: event sync</pre>
57 10 christian
58 10 christian
*NOTE:* for "ir-keytable -t" to work, lirc must not be running. Disable lirc using *"sv stop lircd"*.
59 10 christian
60 10 christian
If your keymap file does not match the input protocol from the driver then you will only see output similar to:
61 10 christian
<pre># ir-keytable -t
62 10 christian
Testing events. Please, press CTRL-C to abort.
63 10 christian
1330396066.132941: event MSC: scancode = 800ff418
64 10 christian
1330396066.132951: event sync</pre>
65 10 christian
66 10 christian
It is important to note that if you use lirc then the code numbers (such as (0x0077)) are used by lircd.conf.
67 10 christian
68 10 christian
h2. Remote Driver Event interface
69 10 christian
70 10 christian
The Remote Driver will output events to only one of the standard keyboard/mouse interface, /dev/lircd?, or devinput. If you do not enable lirc then the driver will default to the standard keyboard/mouse event interface. In most cases this will be fine for mythtv and will be the simplest way to implement your system.
71 10 christian
72 10 christian
If however, you want to use some of lirc's higher functions such as irexec (I use this to have my remote shutdown the system) then you will want to use one of the other interfaces. By default there is nothing to do to create *devinput* but to use */dev/lircd?* you will need to specifically tell ir-keytable to use the lirc protocol in addition to any other protocols if it does not do so already. Use "ir-keytable" to see which protocols are enabled and see of LIRC is one of them. If not you can try "ir-keytable -p lirc" plus any other protocol such rc-6 to add it in.
73 10 christian
74 10 christian
If the lirc protocol is enabled and the driver supports it, you will see a file such as /dev/lircd0 or /dev/lircd1 etc. From here you can have lirc set up the way you always have in the past with your standard lircd.conf file. If the driver does not create */dev/lircd?* then chances are it only uses *devinput*. If you have to use *devinput* then you will likely not be able to use your normal lircd.conf file but instead you will need to use the standard *devinput* version of lircd.conf which is in "/usr/share/lirc/remotes/devinput/lircd.conf.devinput".
75 10 christian
76 10 christian
Normally all of the current driver to lirc associations are handled in */etc/sv/lircd/run* with a default to using */dev/lircd?*
77 10 christian
If the run file does not already do this then to hook lirc into the *devinput* interface you will need to create a file called */etc/runit/lirc.sh* which contains a line similar to:
78 10 christian
<pre>/usr/sbin/lircd -r -n --driver devinput -d /dev/input/by-id/usb-15c2_0043-event-if00 --output /var/run/lirc/lircd</pre>
79 10 christian
80 10 christian
h2. LIRC
81 10 christian
82 1
In LinHES, LIRC is normally running and is initiated and configured by */etc/sv/lircd/run*. To customize the lirc config files please refer to the "Remotes":http://linhes.org/projects/linhes/wiki/Remotes wiki entry.
83 11 christian
84 11 christian
Note if you are using *devinput* you will need to use the *devinput* version of lircd.conf. Depending on the driver this may still require some minor modification. The lircd.conf entries must match the number output (e.g. 0x0077) that you saw using "ir-keytable -t". If it does not then you will not see any output from lirc.
85 11 christian
86 11 christian
To test the output of lirc, you should use *irw*. If you have everything configured properly then you will see output similar to:
87 11 christian
<pre># irw
88 11 christian
0000000080010077 00 KEY_PAUSE devinput
89 11 christian
0000000080010077 00 KEY_PAUSE_UP devinput</pre>
90 11 christian
91 11 christian
h2. lircrc
92 11 christian
93 11 christian
Finally you are into myth's world. Mythtv uses lircrc to 
94 9 christian
95 9 christian
96 9 christian
h1. Tools
97 9 christian
98 9 christian
Mode2 is no longer relevant.
99 9 christian
100 9 christian
h2. lsusb
101 9 christian
h2. ir-keytable
102 9 christian
h2. irw