I’m currently working on using the Griffin PowerMate USB device from .Net.
The PowerMate is a beautiful little rotary controller made of brushed steel with a blue “underglow” LED light. You can rotate it and click it, and that’s basically all. It does one thing, and does it well. Steve would have liked it.
The PowerMate costs $45 from Griffin’s webshop, and they charge only $8 to ship it all the way to Norway. Even though Griffin’s webpage only states compatibility with Windows XP and Vista (and OSX, of-course), the device runs just fine on my Windows 7 x64 laptop. IIRC, I didn’t have to do anything out of the ordinary when I installed it. It comes with an application that can map rotation and clicks to keyboard events, mouse events, volume control, power control, file open and misc iTunes events.
I plan on using it to control my favourite Digital Audio Workstation, Ableton Live, through a small self-made program that reads the rotation and click events from the PowerMate and translates it into MIDI, easily digestible by AbletonLive.
But first, I had to figure out how to talk to the PowerMate. I emailed Griffin support and Jitin was kind enough to send me the HID specifications for the PowerMate, together with some sample code. For more information about Human Interface Devices (HID) programming, visit the excellent HID page. The example from Griffin was a MFC-based C++ application. It required the Windows Driver Kit. To use the WDK, you also need the latest version of the Windows SDK, or you’ll get compile errors looking like this:
c:\program files (x86)\microsoft visual studio 10.0\vc\include\crtdefs.h(543): error C2065: ‘_In_opt_z_’ : undeclared identifier
c:\program files (x86)\microsoft visual studio 10.0\vc\include\new.h(52): error C2065: ‘_In_opt_’ : undeclared identifier
The version of the Windows SDK that comes with VisualStudio won’t work with the latest WDK. Also, make sure you add the include and lib directories before any Visual C++ directories, or you’ll get the same type of errors. In Visual Studio, go to “Project | Properties | VC++ Directories” and set “Include Directories” to something like this:
And the “Library Directories” to something like this:
The sample application from Griffin has a simple user interface that lets you control LED intensity and LED pulsing, as well as read knob rotation and button state.
The sample application and the PowerMate HID spec was great for understanding the protocol used to talk to the PowerMate.
I wanted to inspect the actual data being sent to and from the device, and stumbled upon a USB packed sniffer called Busdog. I had to enable unsigned drivers to get it to work on my Windows 7 x64 laptop (described in this article). This tool is great for tracking down protocol related bugs, and I ended up using it a lot. In the end, I had to uninstall it (disabling unsigned drivers in the process), as it made my laptop unstable with regards to hibernation.
The sample code uses MFC, which is a bit long in the tooth. Now, I’ve done my fair share of MFC programming in the past, so I guess I could have based my PowerMate-to-MIDI application on the MFC-based sample, but since I’m working mostly with C# and .Net these days (and enjoying it), I decided to do it the .Net way instead.
This is work in progress, and I’ll do another post when the .Net part is done.
More information can be found on the project page.