Logitech Harmony 650 remote control and XBMC

Mar 23 2013

Uncategorized
1 comment

Intro

If you really just want to know about the Harmony 650 and XBMC, then I suggest you scroll down to that bit. In arriving at the fix, I spent a lot of time scouring the web and various forums and without much luck. In the true spirit of the interwebs, I decided to share what I had learnt and that’s what this is meant to be about. Unfortunately (for you) the novel I have inside me (we all have one apparently) has been trying to bust out all the time, so this post is much longer than I thought it would be. For those who like long stories (not cut short) read on; for those who want to make their Harmony 650 work with their XBMC, then feel free to skip all the other crap…

I decided recently to move away from the Popcorn Hour based HDX-1000 media player to something a little more colourful and informative – such as XBMC. I’d seen it on a friend’s setup and had even tried it on a Raspberry Pi so I grokked its potential.

When my wife’s silent studio PC gave up the ghost and needed replacing, I decided to press what was left of it into service as an XBMC box. With this, I was almost home and dry when considering my requirements;

  • 100% silent operation
  • Complete control from our Harmony 650 remote
  • Wife friendly

My wife is pretty long suffering with the various bits of tech we have around here. Having said that, she’s not a great fan of anything that takes more than half a second to comprehend and about half that time to complete. This meant that despite the fact that we were introducing a PC to the AV stack under the telly, it had to behave like an appliance. I knew that despite how amazing it might be, it just had to work 100% of the time and be incredibly easy to use in order to gain acceptance.

So, the starting point was an elderly fanless machine from the now defunct Hush Technologies GmbH, although I see that a UK outfit have a very similar machine in their line up – the H-DF1000. It’s a very nice machine, matt black and short, i.e. no taller than a DVD player (of the mid 90s!) and so perfectly ‘living room’ acceptable. It has a Kontron 986LCD-M/mITX motherboard fitted with an Intel Core 2 Duo T7200 processor.  Despite its age (2007), this is quite a respectable processor, but sadly the onboard graphics are not really up to the job – XBMC requires either Nvidia/AMD or 4000 level (integrated) graphics action to do its thing properly. I note that even Atom processors with appropriate level graphics support can pull it off. Well, after all that is exactly the proposition that the Raspberry Pi represents.

Incidentally, when I tried the Raspberry Pi raspbmc build about 9 months ago, I found the user interface response lacking somewhat, but was blown away by its ability to decode and present 1080p video. It just shows how powerful dedicated graphics hardware can be and how little real CPU horsepower is required for all the other functionality around the edge.

I needed to upgrade something in the Hush machine if I was going to pull off decent XBMC performance. I purchased an ATI HD4350 based fanless card from Ebay and popped it in the PCI-Express socket on the motherboard. At this point, there was no 90 degree adaptor shenanigans in place, so this was just a concept to prove that it would work – I would leave the form factor issues for later. Another point that was bothering me which this card addressed was the ability to pipe the audio out via HDMI. Not all cards do this without the need for SPDIF output on the motherboard which, after being connected to the card, can be piped out via HDMI to the monitor/TV. It seems that most ATI cards do the whole thing themselves, albeit with gfx card based audio, so that concern was dealt with.

In my experience, the best way to check out hardware compatibility with a new OS is with a Live CD if at all possible. A quick check of the XBMC wiki revealed that there was Live CD which could also be used to install the software too. This used a minimalist install of Ubuntu to host the XBMC program. Nice.

With an XBMC live CD (V12 – Frodo), I popped it in the machine and booted up. It seemed to work  well enough and so I set about installing it on a USB key (8GB is plenty big enough). The media is hosted on a Synology DS107e (another ARM based wonder machine) and both it and the silent PC were connected via Gigabit ethernet, so this was a good start. After adding media to the video library and playing around for a few hours, I noticed a couple of key issues;

  • Some ‘tearing’ on video playback [Unacceptable]
  • Unstable – needed more than occasional reboots to recover [TOTALLY unacceptable]

More on the tearing later… but for now, I quickly decided to dump the existing hardware and go for something which would be less of a lash up than a graphics card stuck in the motherboard which would have to bent through 90 degrees to even get close to putting the lid back on. My slightly more than cursory look at the world of PCI-Express bus extenders suggested to me that it was probably a big mistake to head in that direction.

What I needed was a big brother to the Raspberry PI, i.e. something which wouldn’t set the world on fire from the point of view of the CPU but would have a decent graphics card onboard to handle the video decoding. I had a look around at the sort of thing that was available for not too much cash and spied this device (GA-E350N-USB3) which has an AMD dual core E-350 processor and a Radion HD 6310 built in. I was a bit concerned that the E-350 has less than half the performance of the T7200 it was replacing, but then I remembered the asymmetry of the Raspberry Pi and told myself to stop worrying. No need to buy a processor or a graphics card, it was all on the motherboard. Nice. £50 – even nicer. I popped off to Ebay and the deal was done.

Now, the original Hush machine had a couple of heat pipes installed, one for the CPU and another for what I can only assume was the graphics controller or a motherboard chipset element (never really looked at that too closely, I must admit – the last time I really looked at a motherboard in detail, it was covered in TTL logic and came with a circuit diagram, Ahh..the 80286, what a device that was!). I had a look at the heat pipe arrangement and figured that I could probably replace the heatsink and fan supplied with the GA-E350N with one of the heatpipe arrangements, but the positioning of the other (smaller) heatsinked device would prevent me from using the second heatpipe.

I had one of those ‘Doh! of course’ moments when I realised that the large heatsink was placed on the graphics controller and not the CPU! The CPU only has a little (5mm tall or so) heatsink fitted to it. When I ran the board up, i realised that while the graphics chip was going to be very happy with the heatpipe setup, the CPU was going to suffer a little with only ambient cooling; after 15 minutes of operation, it failed my ‘can I keep my finger on it’ test which would put it at around 60 degrees C – and that’s the heatsink. Nope, I was going to have to cool it actively. This was meant to be a silent machine though, so as a compromise, I took the fan off the massive graphics chip heatsink that was supplied with the board and running it off 5V instead of 12V achieved near silent operation. A glue gun and a few blobs of strategically placed glue made a ‘permanent’ mounting for the ‘silent’ fan.

Hardware was done. Now on to the XBMC setup again. I made sure I downloaded the .iso file which had support for both Intel and AMD processors (xbmcbuntu-12.00.Intel-AMD.iso) and using a SATA CDROM drive, booted up the machine. I installed the software to the 8GB thumbdrive and it all seemed to be working OK. I added some media to the library and went for playback…..hmm, not so good, the tearing was back.

A little googling revealed that I had arrived on the XBMC scene not too long after a major shakeup in graphics card video decoding. Nvidia use a system called VDPAU which was countered by AMD’s XVBA. Since XVBA was a relative newcomer, XBMC support for it had been a little while in coming and it seemed that V12 was the first to have it built in – without the need to load specific drivers and do other under the hood type of stuff. OK then, so with some (random at first) changes in the Video part of the system settings, I experimented to try and remove the tearing which was evident in most video playback I tried. I messed with video sync settings, de-interlacing and pretty much all that was available to me but with no success. I wondered what else could be upsetting it and some more googling revealed that there was a different linux distribution (Openelec) supporting XBMC, which had a variant that was designed specifically for the E350 processor (Well, specifically the Fusion processor family from AMD) on my new motherboard. So, without really understanding what was wrong, I rushed headlong into another distribution!

I used an USB thumb drive with an Openelec installation image on it and targeted my original 8GB drive for the final installation. Yeah, that sounded simple, but it wasn’t – that’s another story though.

Openelec started up and then straight into XBMC, no problem. Video was without tearing it seemed, but the user interace (UI) response was like treacle. Ugh, that was no good. So, Xbmcbuntu was good for the UI, but bad for the video and Openelec was the opposite. Hmm. As I watched the machine, I noticed that the light on my thumb drive (indicating access) was flashing quite a lot and then it struck me: the thumb drive was probably a real bottleneck when it came to system speed. Plus, USB being the system resource suck that it is, the little CPU was probably quite busy with it too. So, not only was I using a slow ‘system’ disk, but it was via a CPU intensive interface. I wondered if that was the root cause of my poor performance with both Xbmcbuntu and Openelec?

Throwing more cash at the problem, I decided to opt for a 64GB SATA SSD drive. I found a cheap secondhand one on the ‘bay and went for it (I wonder if Openelec supports TRIM, I should look into that). I went through the whole installation process for Openelec (again) but this time targeting the SSD and I haven’t looked back. Boot times are fast, really fast – less than 20 seconds and the user interface is smooth and slick. I hate waiting for computers, I had enough of that when my main machine was an IBM XT and with the massive leap in CPU performance that has occurred since then, I feel cheated that I still have to wait for the damn things. But anyway, I was very impressed with the super smooth XBMC that the Openelec (2.99.4) distribution gave me.

XBMC and the Harmony 650

OK, so here we are, at the crux of the post, the whole reason I decided to write this….

As I said earlier (apologies for those of you who skipped all the crap above, you’re about to get a bit of it whether you like it or not) it’s important for the whole XBMC thing to integrate well into our AV stack. Bottom line; it has to work with the Logitech Harmony 650 (this is all about the wife acceptance factor – WAF).

To this end, I purchased a generic WIndows MCE controller and a USB infrared receiver board. As well as a USB connection, the board had an output which could be used to turn the machine on and off, something which I thought would be handy to have. Now, since I knew that the Harmony was capable of ‘being’ an MCE controller, I was off to a good start.

So once I had the machine up and running and was happy with its performance, it was time to integrate it into the rest of the AV gear and make it a device on the Harmony 650. Before this, I thought I would check that the remote did all that I wanted it to do. Thankfully the user interface for XBMC is pretty straightforward requiring little more than cursor keys, enter, back, menu and OK. Oh and an ‘Info’ key. The info key allows you to see the synopsis, item release date and other info and gives you a point at which to launch a Youtube trailer, all very nice. Thing is, the info key didn’t work.

Pressing the info key brought up what I would best describe as a ‘right click context menu’ which did have ‘movie information’ as an entry that you could then navigate to and select, but this whole process would only work for the title which was approximately halfway down the media list, not where the cursor was when you scroll up and down the list. Hmm….what was going on? So, what did I know?

  • With a keyboard attached, pressing ‘i’ brought up the info screen as expected
  • RIght clicking an attached mouse would bring up the context menu.
  • Pressing ‘info’ on the remote would bring up the context menu – as per the mouse.

Writing this down now, I can see how obvious all this is, but at the time – with my brain working much faster than the speed of speech or writing… (ever experienced that? You can’t figure something out, but as soon as you explain the problem to someone, the moment you complete the problem description the answer becomes apparent. My theory is that you have slowed your brain down – in order to describe the problem to someone with speech – and in doing so have allowed you to reassess the facts properly/in a different way/with a different part of your brain – who knows?)  …I wasn’t looking at the problem correctly.

I had connected the MCE remote as an infrared device, so I needed to check the output of the Linux Infrared Remote Control – lirc program, with the irw command. I logged into the box using SSH and at the prompt typed irw. I stabbed the remote a few times and checked the output – nothing.

Off to google. This revealed a fairly complex world of lircmap.xml, keyboard.xml and remote.xml files. By copying standard files over to /storage/.xbmc/userdata it was possible to edit these files and try to affect the operation of the remote and its key presses. I couldn’t make any changes at all, it seemed. Every time I pressed the ‘info’ key, the damn right context menu popped up.

Time to turn on debugging. This is a great feature since XBMC then pipes all sorts of diagnostic info out to a log file which you can look at to try and make sense of what’s going on.

12:10:06 T:140444752901952 INFO: LIRC Initialize: using: /var/run/lirc/lircd.irtrans
12:10:06 T:140444752901952 DEBUG: Failed to connect to LIRC. Retry in 20s.
12:10:06 T:140444752901952 DEBUG: Keyboard: scancode: 74, sym: 0112, unicode: 0000, modifier: 0
12:10:06 T:140444752901952 DEBUG: OnKey: down (f081) pressed, action is Down
12:10:09 T:140444752901952 DEBUG: ------ Window Init (Pointer.xml) ------

So, what have we got here? Firstly the LIRC system is not doing much, or rather failing at whatever it is trying to do. Next we see a Keyboard event which is subsequently decoded by Onkey as a down arrow press – this is all good. Next is a Window Init event, which was triggered by me pressing the info key. No mention of a key press at all – the ‘window’ which was being ‘init’-ed is the ‘right click context’ menu.

Then, oh so slowly, it started to dawn on me. This isn’t an infrared remote control in the true raw lirc/irw sense of things, it’s an HID keyboard with (built in) mouse! You know, as in you can plug up a keyboard and mouse into a PC and they just work – is that what was going on here? Where was my mouse though?

First, let’s see what’s connected via USB;

openelec:~/.xbmc/temp # lsusb
Bus 001 Device 002: ID 04b4:6830 Cypress Semiconductor Corp. CY7C68300A EZ-USB AT2 USB 2.0 to ATA/ATAPI
Bus 005 Device 003: ID 1241:e000 Belkin 
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 005 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 006 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 007 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub

OK, so I recognise two of these. The first is a USB attached hard disk and the second? Well after removing the IR receiver, re-running the command and replacing the receiver, I could see that my IR receiver was indeed the Belkin device. That was a bit of a surprise as I had no idea it was anything to with Belkin. Time to dig deeper and use lsusb -v

Bus 005 Device 003: ID 1241:e000 Belkin 
Device Descriptor:
 bLength 18
 bDescriptorType 1
 bcdUSB 1.10
 bDeviceClass 0 (Defined at Interface level)
 bDeviceSubClass 0 
 bDeviceProtocol 0 
 bMaxPacketSize0 8
 idVendor 0x1241 Belkin
 idProduct 0xe000 
 bcdDevice 23.5a
 iManufacturer 1 HOLTEK
 iProduct 2 
 iSerial 0 
 bNumConfigurations 1
 Configuration Descriptor:
 bLength 9
 bDescriptorType 2
 wTotalLength 59
 bNumInterfaces 2
 bConfigurationValue 1
 iConfiguration 0 
 bmAttributes 0xa0
 (Bus Powered)
 Remote Wakeup
 MaxPower 100mA
 Interface Descriptor:
 bLength 9
 bDescriptorType 4
 bInterfaceNumber 0
 bAlternateSetting 0
 bNumEndpoints 1
 bInterfaceClass 3 Human Interface Device
 bInterfaceSubClass 1 Boot Interface Subclass
 bInterfaceProtocol 1 Keyboard
 iInterface 0 
 .
 .
 bInterfaceClass 3 Human Interface Device
 bInterfaceSubClass 1 Boot Interface Subclass
 bInterfaceProtocol 2 Mouse
 iInterface 0

Ah, OK so now it’s a Holtek device masquerading as a Belkin? I take a closer look at the IR receiver board and sure enough it has a Holtek device on it. Also note that it is both a keyboard and a mouse. This would explain why pressing some buttons produce keyboard actions and others produce mouse clicks.

So, my IR receiver doesn’t make any use of Lirc, it’s not being handled as an IR device at all. It’s a keyboard and mouse combo that is presented to the system as a USB HID device! The fact that it uses an infrared link between the keyboard and the system is neither here or there, it’s irrelevant to the operating system that the traditional wire has been replaced by an infra red link. After all, the wireless keyboards and mice that you can buy have no special drivers for their operation, they just work, whether they use Infra red or wireless radio links. Somehow, I had allowed my thinking to go down completely the wrong path!

Right, so now the fact that irw produced nothing and all that fiddling with lircmap.xml wasn’t at all helpful makes much more sense. What do I need to do to make the ‘info’ button work now?

Some googling suggested that what I needed to edit was the keyboard.xml file and so I made a local copy in /storage/.xbmc/userdata/keymaps and had a look.

It’s full of key definitions and the actions that are assigned to them. There is a global ‘catch all’ section and then further sections which define key press actions in various contexts. If you haven’t defined a context specific key press action, then the global one applies. So, for example I could see – in the global section, a definition for the ‘i’ key;

<i>Info</i>

So all I needed to do, given that the info key was being interpreted as a mouse right click (See? the clue was in the context menu that normally would pop up with a right click…) was to map that to the ‘info’ command. More googling and it seemed that all I needed to do was add a mouse section to the global part of the file.

<keymap>
 <global>
 <keyboard>
 <p>Play</p>
 <q>Queue</q>
 <f>FastForward</f>
 <r>Rewind</r>
 <left>Left</left>
 <right>Right</right>
 <up>Up</up>
 <down>Down</down>
 <blue>ContextMenu</blue>
 <left mod="ctrl">analogseekback</left>
 <right mod="ctrl">analogseekforward</right>
 <pageup>PageUp</pageup>
 <pagedown>PageDown</pagedown>
 <return>Select</return>
 <enter>Select</enter>
 <backspace>Back</backspace>
 <key id='65446'>Back</key>
 <m>ActivateWindow(PlayerControls)</m>
 <s>ActivateWindow(shutdownmenu)</s>
 <escape>PreviousMenu</escape>
 <i>Info</i>
  .
  .
 </keyboard>
 <mouse>
 <rightclick>Info</rightclick>
 </mouse>

Err…and that was it. With this line installed in my custom (i.e. stored in /userdata/keymaps/keyboard.xml) keyboard.xml file and I was away. So after all that, there was no need to get down and dirty with the fact that I was using a Harmony remote at all, it was (I assume due to the USB IR receiver I was using) just a plain old keyboard and mouse.

So, what did I learn?

USB keys/dongles/sticks don’t necessarily make the best operating disks for a desktop OS. Bloomin’ obvious really, I guess. Why did I think that XBMC or Openelec were somehow anything other than a desktop OS? OK, so they’re fiercely optimised to do a great job as an embedded desktop OS, but that’s definitely what they are and USB is never going to be a substitute for a hard disk or SSD interfaced via SATA. Upon reflection, I could have done something nifty with a RAM disk – especially since I had fitted 4GB of RAM to the machine and I noticed that most of it was sitting there doing nothing.

Don’t be misled by fancy packaging. I had missed that the remote control was nothing more than a standard keyboard and mouse. It just didn’t look like one and as it was interfaced to the PC via infra red, I was all to ready to go rushing down the lirc route. That was quite a big diversion that consumed a number of frustrating hours.

There’s quite a lot of cruft hanging around in XBMC. Or more specifically in the documentation/forums/discussion surrounding XBMC. I can see how this happens, given that it’s an open source development. It may sound like criticism, but it’s not, it’s just a side effect of the way in which the development progress in my view. There’s a problem, many people discuss it, someone produces code/workaround or whatever and it works. Then someone produces a different approach to solving the problem (perhaps more elegant, perhaps not) and we all move on. Thing is, all that old gnashing of teeth and ‘wearing fingers down to the bone producing a fix’ stuff hangs around and can put you off the right track when you’re looking for the current way of addressing a particular problem. Of course, none of this is specific to XBMC it’s all over the place in t’interwebs….

Dedicated hardware pisses all over general purpose stuff. Computing seems to oscillate between polar opposite approaches to things – remember thin clients? But one area where one approach has stuck, very successfully, is that of graphics acceleration. This has reached new heights of asymmetry with devices like the Raspberry Pi and Atom/Fusion CPUs with companion graphics chips made up of obscenely powerful graphics engines. With a video playback device, you really don’t need much in the way of CPU at all when you have such a powerful pixel chuntering device next door on the board.

It takes longer, much longer to write stuff up than you think. It’s fast to think stuff, almost as fast to say it, but it takes ages to write it. I should know this only too well as I used to be a stickler for documentation, but it’s been a while now and I thought that this was ‘only a blog post’ but it’s still writing innit? It always takes longer to do things than to think them, but it can be quite useful to slow one’s thinking down to the speed of ‘doing’ sometimes. I wanted to share my learnings about this so that other Harmony/MCE users can overcome the problem that I did. Maybe they’ll see the signposts along the way to the correct solution a lot faster than me, maybe not, but if someone finds this useful, just one person, then I will have succeeded in my objective for writing all this down. Sorry for the somewhat circuitous route to the three lines (count ’em) that made it all work!

Finally did it achieve the correct level of WAF? Almost. It’s just another appliance that can be operated by the Harmony and so that’s all good. Thing is, the IR receiver board is stuck on the outside of the box with a wire disappearing back into the unit via the machined (nice aluminium front, you see) slot for the (now removed) CDROM drive. The double-sided sticky pad doesn’t work that well and so over time (like 3 minutes) after being repositioned, the board droops, falls off the front and hangs down, held up by the wire. That takes the edge off the WAF, it has to be said.

Comments

  • Very nice article, thank you!

    You saved me a lot of time. I too would have fallen down the rabbit hole of lirc.

Trackbacks and Pingbacks

Leave a Reply