Fully working remote control (HVR-4000) on kernel 2.6.35
Remote control support (input device events) is now handled by the kernel (>=2.6.17). However, not all remote buttons may work out of the box. The driver that handles input device events, xf86-input-evdev, needs to be patched in order to remap higher keycodes than the xserver may handle. x server (Xorg/x11) is built with 255 keycodes in mind, out from the fact that a keyboard rarely has so many keys (but perhaps >128). The problem arise when we use new special keys like on a remote control or extended keyboards or laptops that uses multimedia keys. These keys might have a keycode higher than the regular keycode space may interpret. (>255).
For a long time I thought the kernel only could handle a few buttons from my remote (some remote buttons was not working (menu, back, ch+,ch-)), so I needed to install lirc to get the whole remote to work properly. Though, its been more and more difficult to run lirc on top of the kernel where both interpret to triggered events. Since the ir_common module is impossible to blacklist (kernel >=2.6.33?), something had to be done. Lately, in Ubuntu 10.10, lirc has been left completely useless because a single key press on the remote has resulted in two actions in eg. xbmc for the keys that xserver responds to.
Thanks to Gianni Ceccarelli, who has made a patch making it possible to remap these higher keycodes, the remote can now be mapped to whatever I would like without the use of lirc.
To figure out what keys are not recognised by xserver, simply use/install evtest.
:~$ sudo aptitude install evtest
My irremote is found at this path /dev/input/by-path/pci-0000\:03\:06.1-event-ir (you will find yours by looking for an event-ir device). In order to find the device easier, I will create an udev rule that make a symbol link to /dev/input/irremote.
:~$ sudo vi /etc/udev/rules.d/10-local.rules
To find the vendor id:
:~$ lspci -nn
Conexant Systems, Inc. CX23880/1/2/3 PCI Video and Audio Decoder [IR Port] [14f1:8804] (rev 05)
Be sure to add 0x infront of the id.
Reload udev or restart computer in order to make the symlink valid. Now we can use this path to test for lost keys in the xserver event mapping:
sudo evtest /dev/input/irremote
Input driver version is 1.0.1 Input device ID: bus 0x1 vendor 0x70 product 0x6902 version 0x1 Input device name: "cx88 IR (Hauppauge WinTV-HVR400" Supported events: Event type 0 (Sync) Event type 1 (Key) Event code 2 (1) Event code 3 (2) Event code 4 (3) Event code 5 (4) Event code 6 (5) Event code 7 (6) Event code 8 (7) Event code 9 (8) Event code 10 (9) Event code 11 (0) Event code 28 (Enter) Event code 103 (Up) Event code 105 (Left) Event code 106 (Right) Event code 108 (Down) Event code 113 (Mute) Event code 114 (VolumeDown) Event code 115 (VolumeUp) Event code 116 (Power) Event code 119 (Pause) Event code 128 (Stop) Event code 139 (Menu) Event code 142 (Sleep) Event code 163 (NextSong) Event code 165 (PreviousSong) Event code 167 (Record) Event code 168 (Rewind) Event code 174 (Exit) Event code 207 (Play) Event code 208 (Fast Forward) Event code 353 (Select) Event code 363 (Channel) Event code 365 (EPG) Event code 367 (MHP) Event code 370 (Subtitle) Event code 372 (Zoom) Event code 377 (TV) Event code 385 (Radio) Event code 388 (Text) Event code 392 (Audio) Event code 393 (Video) Event code 398 (Red) Event code 399 (Green) Event code 400 (Yellow) Event code 401 (Blue) Event code 402 (ChannelUp) Event code 403 (ChannelDown) Event code 412 (Previous) Event type 20 (Repeat) Testing ... (interrupt to exit)
Now we need to download and patch xf86-input-evdev.
:~$ sudo aptitude install git-core build-essential libtool autoconf :~$ sudo aptitude install xserver-xorg-dev xutils-dev :~$ git clone git://www.thenautilus.net/xf86-input-evdev :~$ cd xf86-input-evdev :~/xf86-input-evdev$ git pull git://www.thenautilus.net/xf86-input-evdev code-remap
From git://www.thenautilus.net/xf86-input-evdev * branch code-remap -> FETCH_HEAD Auto-merging man/Makefile.am CONFLICT (content): Merge conflict in man/Makefile.am Auto-merging man/evdev.man Auto-merging src/evdev.c Auto-merging src/evdev.h Automatic merge failed; fix conflicts and then commit the result.
If git complains about a problem regarding merging man/Makefile.am, this is what you need to do.
Open up man/Makefile.am, and edit out these 3 lines
<<<<<<< HEAD ======= >>>>>>> 35315fc33467b93795baddfc581a1937ae3323ca
:~/xf86-input-evdev$ pico man/Makefile.am :~/xf86-input-evdev$ git add man/Makefile.am :~/xf86-input-evdev$ git commit -m "fix merge error" :~/xf86-input-evdev$ git pull
The last command should now give you : Already up-to-date.
On with the installation:
:~/xf86-input-evdev$./autogen.sh :~/xf86-input-evdev$ ./configure :~/xf86-input-evdev$ make :~/xf86-input-evdev$ sudo make install
The new driver is now located in /usr/local/lib/xorg/modules.
Now we need to add this to the module path for X:
:~$ sudo pico /etc/X11/xorg.conf
Add this section in the file:
Section "Files" ModulePath "/usr/local/lib/xorg/modules,/usr/lib/xorg/extra-modules,/usr/lib/xorg/modules" EndSection
Restart X, and check that the driver is correctly loaded.
:~$ grep evdev_drv /var/log/Xorg.0.log
Hopefully the output will be like this:
(II) Loading /usr/local/lib/xorg/modules/input/evdev_drv.so
The patch adds a configuration option called event_key_remap, and takes in arguments like $evdev_code = $x11_code (as a whitespace separated list). $evdev_code is found from the evtest list printet out at the beginning of this document, while $11_code may be found using xmodmap (shown below).
There are two methods for implementing this re-mapping of keys. By editing xorg.conf or creating a local hal fdi rule under /etc/hal/fdi/policy/.
Below follow my xorg.conf implementation:
Section "ServerLayout" Identifier "Default Layout" InputDevice "RF remote" "SendCoreEvents" EndSection Section "InputDevice" Identifier "RF remote" Driver "evdev" Option "Device" "/dev/input/irremote" Option "event_key_remap" "402=112 403=117 365=135 174=22 139=147" EndSection
For short, I would like button ChannelUp (evtest keycode 402 ) on the remote control to map to the Xserver action Prior(Page Up) (keycode 112).
Since I run xmodmap in a terminal from another computer, i add -display :0 in order to for it to grab data from the xserver.
:~$ xmodmap -pke -display :0
keycode 8 = keycode 9 = Escape NoSymbol Escape keycode 10 = 1 exclam 1 exclam exclamdown onesuperior keycode 11 = 2 quotedbl 2 quotedbl at twosuperior keycode 12 = 3 numbersign 3 numbersign sterling threesuperior keycode 13 = 4 currency 4 currency dollar onequarter keycode 14 = 5 percent 5 percent onehalf U2030 keycode 15 = 6 ampersand 6 ampersand yen fiveeighths keycode 16 = 7 slash 7 slash braceleft division keycode 17 = 8 parenleft 8 parenleft bracketleft guillemotleft keycode 18 = 9 parenright 9 parenright bracketright guillemotright keycode 19 = 0 equal 0 equal braceright degree ... keycode 121 = XF86AudioMute NoSymbol XF86AudioMute keycode 122 = XF86AudioLowerVolume NoSymbol XF86AudioLowerVolume keycode 123 = XF86AudioRaiseVolume NoSymbol XF86AudioRaiseVolume keycode 124 = XF86PowerOff NoSymbol XF86PowerOff keycode 125 = KP_Equal NoSymbol KP_Equal keycode 126 = plusminus NoSymbol plusminus keycode 127 = Pause Break Pause Break keycode 128 = XF86LaunchA NoSymbol XF86LaunchA keycode 129 = KP_Decimal NoSymbol KP_Decimal keycode 130 = Hangul NoSymbol Hangul keycode 131 = Hangul_Hanja NoSymbol Hangul_Hanja keycode 132 = keycode 133 = Super_L NoSymbol Super_L keycode 134 = Super_R NoSymbol Super_R keycode 135 = Menu NoSymbol Menu keycode 136 = Cancel NoSymbol Cancel keycode 137 = Redo NoSymbol Redo keycode 138 = SunProps NoSymbol SunProps keycode 139 = Undo NoSymbol Undo keycode 140 = SunFront NoSymbol SunFront keycode 141 = XF86Copy NoSymbol XF86Copy keycode 142 = SunOpen NoSymbol SunOpen keycode 143 = XF86Paste NoSymbol XF86Paste ...
(See logfile for mor detailed output)
Lirc should now be possible to uninstall, making the use of the media center much, much easier.
xbmc recognices a lot of the xmodmap codes, but an option is to directly map keycodes directly into the lircmap.xml file inside .xbmc/userdata folder in your home directory.