RaspBMC: mapping Samsung remote

One of the great features of RaspBMC is the ability to control it using your existing TV remote when connected via HDMI.  It accomplishes this task by making use of CEC to pass control codes from the TV to the Raspberry Pi.

While most of the important buttons on my Samsung TV pass happily through to XMBC (such as navigation arrows, play, pause, stop, etc) one of the controls which is sorely missing is the ability to access the context menu.  Which means that every time I need to alter a setting I need to plug in a usb keyboard.  I would also like to be able to adjust the XBMC volume using the remote.

Thankfully XMBC is designed in such a way that you can set up your own custom keymaps to alter the behaviour of the existing remote buttons or add new ones.

The first step is to work out which of the buttons on your remote actually get passed through to the Raspi.  Not all buttons on a remote are CEC enabled, which seems to be at the whim of the TV manufacturer as is the name that each button appears as.  My volume buttons are not enabled so I want to remap Channel Up/Down to perform this function when video is playing.

If we connect to Raspi via SSH (using a terminal program such as putty) then we examine the status updates recorded in xbmc.log in response to each key press…

tail -F /home/pi/.xbmc/temp/xbmc.log

This then shows the name of each button (in this case I pressed the ‘green’ button).  The response was to bring up the Videos screen.

22:00:43 T:1182790720   DEBUG: CecLogMessage – key pressed: F3 (green) (73)
22:00:43 T:1182790720   DEBUG: PushCecKeypress – received key fc duration 0
22:00:43 T:1102835712   DEBUG: OnKey: 252 (fc) pressed, action is XBMC.ActivateWindow(MyVideos)

(You may find that key presses are not being logged.  If this is the case then you need to create /home/pi/.xbmc/userdata/advancedsettings.xml and add the lines <advancedsettings> <loglevel>1</loglevel> </advancedsettings>)

Then the final step is to make an entry in /home/pi/.xbmc/userdata/keymaps/remote.xml to bind the key to a new action (such as XBMC.ActivateWindow(VideoLibrary,MovieTitles).  The list of actions can be found the XBMC wiki (ButtonTranslator.cpp).

However things get more complicated with my Samsung remote because many of the buttons do not come up with their actual name…

12:10:10 T:1183839296   DEBUG: CecLogMessage – key pressed: channel up (30)
12:10:10 T:1183839296   DEBUG: PushCecKeypress – received key d2 duration 0
12:10:10 T:1075412992   DEBUG: OnKey: leftshift (d2) pressed, action is PageUp

Above is what happens when I press the Channel Up button.  From the above log you would expect this to respond to something like a <channel up> or <d2> tag.  But it doesn’t.  The tag you want is inexplicably <pageplus>.  The way I found this out was that this button already had a behaviour associated with it in /opt/xbmc-bcm/xbmc-bin/share/xmbc/system/keymaps/remote.xml, so I could trace it back.  However there are buttons on the remote that do pass CEC codes through but aren’t already defined with a behaviour and it seems at this point in time I have no way of finding out what their tag should be!

This is a real pain, because of all the buttons that pass through CEC only half of mine I can work out the correct tag for.  Grr!

So anyway my volume fix ends up looking something like this…

<keymap>
  <global>
  </global>
  <FullScreenVideo>
    <remote>
      <pageplus>volumeup</pageplus>
      <pageminus>volumedown</pageminus>
    </remote>
  </FullScreenVideo>
</keymap>

UPDATE: work-in-progress listing of codes

Advertisements

6 Responses to RaspBMC: mapping Samsung remote

  1. Jakob says:

    Very interesting,
    I just ordered my Rapberry to use it with my samsung tv, looking forward to try this when it gets delivered in six weeks 🙂

  2. raspowner says:

    good stuff

  3. Tilo says:

    On my Samsung pressing the return button works for context menus. Cheers

    • philw4rd says:

      I’m guessing you have a remote which sends ‘title’ when the return key is pressed (someone else here reported this behaviour on another post). On my remote the ‘-/–‘ key sends ‘title’.

      • Sergei says:

        I don’t think so. Samsung remotes send ‘return’ code when the return button is pressed (at least mine does). But someone had a “brilliant” idea to permanently map that code to ‘title’ inside XBMC. Sigh…

  4. Travis says:

    I plugged my Raspbmc into new TV and I was startled that it was controlling XBMC. Then I noticed the AnyNet+ capability. Thanks to your post, I was able to remap a button for the context menu which was much needed. Woohoo! Thanks man!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: