XBMC will be renamed to Kodi for v14. Read here for more details

HOW-TO:Configure Gyration USB remote for Ubuntu

From XBMC
Revision as of 10:57, 3 October 2011 by NedBot (Talk)

Jump to: navigation, search

Goto: Tips_And_Tricks#XBMC_for_Linux_specific_HOW-TOs

Contents

1 Introduction

There are several buttons on the Gyration Media Center Remote that work with XBMC out of the box, so to speak.

There are also some that do not.

This method uses the evrouter program to map the unused keys (or any key you wish, for that matter) to keyboard keys that XBMC uses.

This was written using Ubuntu 9.10 i386 with XBMC 9.11 installed from the svn ppa.

We are going to use evrouter to look at the two event devices associated with the Gyration remote, which are:

/dev/input/by-id/usb-Gyration_Gyration_RF_Technology_Receiver-event-kbd
/dev/input/by-id/usb-Gyration_Gyration_RF_Technology_Receiver-event-mouse

Also, since we're not using lirc, I am starting xbmc with the --nolirc option.

2 Install evrouter

The Ubuntu repositories do not have evrouter, but there is a .deb package available at the author's website, which this guide will use.

Download the package:

wget http://debian.bedroomlan.org/debian/pool/main/e/evrouter/evrouter_0.4_i386.deb

Install the package:

sudo dpkg -i evrouter_0.4_i386.deb

3 Create configuration file for evrouter

You can use evrouter to dump the output of keys for devices. To do this, run this command:

sudo evrouter -d /dev/input/by-id/usb-Gyration_Gyration_RF_Technology_Receiver-event-*

While the command is running, press the buttons on the remote, and the configuration will be generated. Here is what it should look like:

sudo evrouter -d /dev/input/by-id/usb-Gyration_Gyration_RF_Technology_Receiver-event-*
device 0: /dev/input/by-id/usb-Gyration_Gyration_RF_Technology_Receiver-event-kbd: Gyration Gyration RF Technology Receiver
device 1: /dev/input/by-id/usb-Gyration_Gyration_RF_Technology_Receiver-event-mouse: Gyration Gyration RF Technology Receiver
Display name: localhost:10.0
 
Window "xterm": # Window title
# Window "xterm": # Resource name
# Window "XTerm": # Class name
"Gyration Gyration RF Technology Receiver" "/dev/input/by-id/usb-Gyration_Gyration_RF_Technology_Receiver-event-mouse" none key/102 "fill this in!"

The last part in the quotes, "fill this in," needs to be replaced with the desired action. According to the man page of evrouter, the action can be either a keyboard press, a mouse button, or a shell script. Please read the man page for more info.

man evrouter

Below is a file where every single button on the remote was pressed. The working buttons have been commented out, but they are there in case you want to change the default behavior. Evrouter can be configured on a per-window basis using the Window parameter in the configuration file. The example below is affecting all windows, so if you're using this in windowed mode in a desktop environment, you might want to put the window class or resource name in the quotes. I think it should be "xbmc.bin"

Copy this and save it wherever you want. I have it saved as ~/evrouter_gyration.txt which will be used later in this guide.

#Window "xbmc.bin": # Window title
Window "": # Window title
 
#Power/Sleep
"Gyration Gyration RF Technology Receiver" "/dev/input/by-id/usb-Gyration_Gyration_RF_Technology_Receiver-event-mouse" none key/142 "XKey/End"
 
#or to bring up shutdown menu
#"Gyration Gyration RF Technology Receiver" "/dev/input/by-id/usb-Gyration_Gyration_RF_Technology_Receiver-event-mouse" none key/142 "XKey/S"
 
#LiveTV
"Gyration Gyration RF Technology Receiver" "/dev/input/by-id/usb-Gyration_Gyration_RF_Technology_Receiver-event-mouse" none key/366 "XKey/O"
 
#left mouse
#"Gyration Gyration RF Technology Receiver" "/dev/input/by-id/usb-Gyration_Gyration_RF_Technology_Receiver-event-mouse" none key/272 "fill this in!"
 
#right mouse
#"Gyration Gyration RF Technology Receiver" "/dev/input/by-id/usb-Gyration_Gyration_RF_Technology_Receiver-event-mouse" none key/273 "fill this in!"
 
#green windows button
#"Gyration Gyration RF Technology Receiver" "/dev/input/by-id/usb-Gyration_Gyration_RF_Technology_Receiver-event-mouse" none key/102 "XKey/Escape"
 
#mypictures
"Gyration Gyration RF Technology Receiver" "/dev/input/by-id/usb-Gyration_Gyration_RF_Technology_Receiver-event-mouse" none key/212 "XKey/B"
 
#myTV
#"Gyration Gyration RF Technology Receiver" "/dev/input/by-id/usb-Gyration_Gyration_RF_Technology_Receiver-event-mouse" none key/226 "fill this in!"
 
#mymusic
"Gyration Gyration RF Technology Receiver" "/dev/input/by-id/usb-Gyration_Gyration_RF_Technology_Receiver-event-mouse" none key/391 "XKey/G"
 
#myvideos
"Gyration Gyration RF Technology Receiver" "/dev/input/by-id/usb-Gyration_Gyration_RF_Technology_Receiver-event-mouse" none key/393 "XKey/E"
 
#DVD Menu
#"Gyration Gyration RF Technology Receiver" "/dev/input/by-id/usb-Gyration_Gyration_RF_Technology_Receiver-event-mouse" none key/389 "fill this in!"
 
#stop
#"Gyration Gyration RF Technology Receiver" "/dev/input/by-id/usb-Gyration_Gyration_RF_Technology_Receiver-event-kbd" none key/166 "fill this in!"
 
#record
"Gyration Gyration RF Technology Receiver" "/dev/input/by-id/usb-Gyration_Gyration_RF_Technology_Receiver-event-kbd" none key/167 "XKey/Sys_Req"
 
#pause
"Gyration Gyration RF Technology Receiver" "/dev/input/by-id/usb-Gyration_Gyration_RF_Technology_Receiver-event-kbd" none key/119 "XKey/space"
 
#rewind
#"Gyration Gyration RF Technology Receiver" "/dev/input/by-id/usb-Gyration_Gyration_RF_Technology_Receiver-event-kbd" none key/168 "fill this in!"
 
#fastfoward
#"Gyration Gyration RF Technology Receiver" "/dev/input/by-id/usb-Gyration_Gyration_RF_Technology_Receiver-event-kbd" none key/208 "fill this in!"
 
#play
"Gyration Gyration RF Technology Receiver" "/dev/input/by-id/usb-Gyration_Gyration_RF_Technology_Receiver-event-kbd" none key/207 "XKey/P"
 
#skipback
#"Gyration Gyration RF Technology Receiver" "/dev/input/by-id/usb-Gyration_Gyration_RF_Technology_Receiver-event-kbd" none key/165 "fill this in!"
 
#skip forward
#"Gyration Gyration RF Technology Receiver" "/dev/input/by-id/usb-Gyration_Gyration_RF_Technology_Receiver-event-kbd" none key/163 "fill this in!"
 
#guide
"Gyration Gyration RF Technology Receiver" "/dev/input/by-id/usb-Gyration_Gyration_RF_Technology_Receiver-event-kbd" none key/362 "XKey/Menu"
 
#up
#"Gyration Gyration RF Technology Receiver" "/dev/input/by-id/usb-Gyration_Gyration_RF_Technology_Receiver-event-kbd" none key/103 "fill this in!"
 
#down
#"Gyration Gyration RF Technology Receiver" "/dev/input/by-id/usb-Gyration_Gyration_RF_Technology_Receiver-event-kbd" none key/108 "fill this in!"
 
#left
#"Gyration Gyration RF Technology Receiver" "/dev/input/by-id/usb-Gyration_Gyration_RF_Technology_Receiver-event-kbd" none key/105 "fill this in!"
 
#right
#"Gyration Gyration RF Technology Receiver" "/dev/input/by-id/usb-Gyration_Gyration_RF_Technology_Receiver-event-kbd" none key/106 "fill this in!"
 
#ok
#"Gyration Gyration RF Technology Receiver" "/dev/input/by-id/usb-Gyration_Gyration_RF_Technology_Receiver-event-kbd" none key/28 "fill this in!"
 
#back 
#"Gyration Gyration RF Technology Receiver" "/dev/input/by-id/usb-Gyration_Gyration_RF_Technology_Receiver-event-kbd" none key/158 "XKey/BackSpace"
 
#info
#"Gyration Gyration RF Technology Receiver" "/dev/input/by-id/usb-Gyration_Gyration_RF_Technology_Receiver-event-kbd" none key/130 "XKey/I"
 
#volup
#"Gyration Gyration RF Technology Receiver" "/dev/input/by-id/usb-Gyration_Gyration_RF_Technology_Receiver-event-kbd" none key/115 "fill this in!"
 
#voldown
#"Gyration Gyration RF Technology Receiver" "/dev/input/by-id/usb-Gyration_Gyration_RF_Technology_Receiver-event-kbd" none key/114 "fill this in!"
 
#mute
#"Gyration Gyration RF Technology Receiver" "/dev/input/by-id/usb-Gyration_Gyration_RF_Technology_Receiver-event-kbd" none key/113 "fill this in!"
 
#chan up 
"Gyration Gyration RF Technology Receiver" "/dev/input/by-id/usb-Gyration_Gyration_RF_Technology_Receiver-event-kbd" none key/402 "XKey/Page_Up"
 
#chan down
"Gyration Gyration RF Technology Receiver" "/dev/input/by-id/usb-Gyration_Gyration_RF_Technology_Receiver-event-kbd" none key/403 "XKey/Page_Down"
 
#1
#"Gyration Gyration RF Technology Receiver" "/dev/input/by-id/usb-Gyration_Gyration_RF_Technology_Receiver-event-kbd" none key/2 "fill this in!"
 
#2
#"Gyration Gyration RF Technology Receiver" "/dev/input/by-id/usb-Gyration_Gyration_RF_Technology_Receiver-event-kbd" none key/3 "fill this in!"
 
#3
#"Gyration Gyration RF Technology Receiver" "/dev/input/by-id/usb-Gyration_Gyration_RF_Technology_Receiver-event-kbd" none key/4 "fill this in!"
 
#4
#"Gyration Gyration RF Technology Receiver" "/dev/input/by-id/usb-Gyration_Gyration_RF_Technology_Receiver-event-kbd" none key/5 "fill this in!"
 
#5
#"Gyration Gyration RF Technology Receiver" "/dev/input/by-id/usb-Gyration_Gyration_RF_Technology_Receiver-event-kbd" none key/6 "fill this in!"
 
#6
#"Gyration Gyration RF Technology Receiver" "/dev/input/by-id/usb-Gyration_Gyration_RF_Technology_Receiver-event-kbd" none key/7 "fill this in!"
 
#7
#"Gyration Gyration RF Technology Receiver" "/dev/input/by-id/usb-Gyration_Gyration_RF_Technology_Receiver-event-kbd" none key/8 "fill this in!"
 
#8
#"Gyration Gyration RF Technology Receiver" "/dev/input/by-id/usb-Gyration_Gyration_RF_Technology_Receiver-event-kbd" none key/9 "fill this in!"
 
#9
#"Gyration Gyration RF Technology Receiver" "/dev/input/by-id/usb-Gyration_Gyration_RF_Technology_Receiver-event-kbd" none key/10 "fill this in!"
 
#0
#"Gyration Gyration RF Technology Receiver" "/dev/input/by-id/usb-Gyration_Gyration_RF_Technology_Receiver-event-kbd" none key/11 "fill this in!"
 
#clear
#"Gyration Gyration RF Technology Receiver" "/dev/input/by-id/usb-Gyration_Gyration_RF_Technology_Receiver-event-kbd" none key/1 "fill this in!"
 
#enter
#"Gyration Gyration RF Technology Receiver" "/dev/input/by-id/usb-Gyration_Gyration_RF_Technology_Receiver-event-kbd" none key/28 "fill this in!"

4 Set Up Sudo

Since root permissions are required for evrouter to do what it does, we will launch it using sudo. However, since this is going to be a part of a script, we need to make sure that the user that is launching XBMC is allowed to run evrouter without having to put in the user's password. To do this, use the command visudo with super user permissions:

sudo visudo

This will launch your editor to edit the sudoers file. To allow the user xbmc to run evrouter with super user permissions without a password, add this line:

xbmc ALL=(root) NOPASSWD: /usr/bin/evrouter 


5 Configure evrouter to start up with the X server

Evrouter needs to be started after the X server is running. To do this, I put it in the user's ~/.xinitrc file.

This was tested using mingetty to auto log in a user that has a file ~/.bash_login as follows:

if [[-z "$SSH CONNECTION"]] ; then
        while [[ x`pidof X` = "x" ]]; do startx; done
fi

This will run startx as long as the login is not through SSH and X isn't already running, and will restart it if it dies. There may be better ways to do this, but that's not the discussion here.

Here is the user's ~/.xinitrc file:

#!/bin/bash
/usr/bin/sudo /usr/bin/evrouter --config=/home/xbmc/evrouter_gyration.txt /dev/input/by-id/usb-Gyration_Gyration_RF_Technology_Receiver-event-*
exec /usr/bin/xbmc --standalone --nolirc
/usr/bin/sudo /usr/bin/evrouter --quit

6 Customizations

To change or customize the behavior of evrouter with your remote, you will need to figure out what you want a certain key to do. For instance, I want the My Music key on the remote to take me right to my music.

Using evrouter -d, the configuration for that key looks like this:

"Gyration Gyration RF Technology Receiver" "/dev/input/by-id/usb-Gyration_Gyration_RF_Technology_Receiver-event-mouse" none key/391 "Xfill this in!"

We need to populate an action where "fill this in" is written. Since we are replacing the remote button events with keyboard presses, we need to find which key will do that in the default keyboard keymap. The key on the default keyboard keymap for music is this:

<launch_media_select>XBMC.ActivateWindow(MyMusic)</launch_media_select>

Unfortunately we don't have that key launch_media_select, whatever that is. I guess we'll have to find an unused key.

Looking at the default keyboard mapping, the letter G is not used. So, to make the music key on the remote send that, replace "fill this in!" with the action XKey/G -- it should now look like this:

"Gyration Gyration RF Technology Receiver" "/dev/input/by-id/usb-Gyration_Gyration_RF_Technology_Receiver-event-mouse" none key/391 "XKey/G"

I will now make a keyboard mapping in ~/.xbmc/userdata/keymaps/keyboard.xml to associate G with the action I want in XBMC. I did the same thing for some other buttons as well:

<keymap>
  <global>
    <keyboard>
      <key id="61606">ParentDir</key> <!--back-->
      <key id='61476'>PreviousMenu</key> <!-- green windows key -->
      <b>XBMC.ActivateWindow(MyPictures)</b>
      <e>XBMC.ActivateWindow(MyVideos)</e>
      <g>XBMC.ActivateWindow(MyMusic)</g>
    </keyboard>
  </global>
</keymap>

7 Closing Thoughts

In doing this, I learned that even though some of the buttons don't do anything, XBMC still sees them. You only need to make an evrouter key assignment if the XBMC debug log does not show a keypress. For me, it doesn't show anything at all with the My Music button without an evrouter mapping. Other buttons show something, but not a button id. For instance, here is what the MyTv button shows in the debug log without evrouter or lircd:

17:44:32 T:3077863296 M:1445896192   DEBUG: SDLKeyboard: scancode: 234, sym: 0, unicode: 0, modifier: 0
17:44:33 T:3077863296 M:1445896192   DEBUG: HAL: Device (/org/freedesktop/Hal/devices/usb_device_c16_2_noserial_if1_logicaldev_input) Condition ButtonPressed | media

I don't know what to do with this. What I can do, however, is create an evrouter mapping.

So, to sum up, you only need an evrouter button mapping if the debug log does not show the button id with OnKey. If the button is shown in the debug log with the button ID, you can just map it with an xml file, like I did with back and the green windows key and the back button.

Personal tools
Namespaces

Variants
Actions
Navigation
Wiki help
Toolbox