Saying "Hi!" to developing with HID in Windows 8.1
- Posted: Nov 22, 2013 at 6:00AM
Today's Hardware Friday projects take us back to the HID world that's opened up in Windows 8.1. The first project by Bruno Capuano (aka El Bruno), shows how quickly you can take advantage of, and how easy it is, HID...
First the most important thing: I almost forgot to write about this. Windows 8.1 have a new capability that allows us to work with HID devices, so my posts on the USB missile launcher connected to the Kinect or the USB post light notifier, is now much easy.
To have a good start, the first article you should read is this one:
- Communicating with peripheral Devices
It explains the new capabilities we have in Win8.1 to connect with:
- 3D printers
- USB devices
- Human Devices Interfaces
For this example I’ll go with the capacity to connect with HDI. In the following example I’ll show who to create a Win8.1 app which displays the list of connected HDI devices.
1. Create an app Store Windows for Windows 8.1
2. Once created the app, we should define in its manifesto that it will connect with an HDI device. Appxmanifiest editor does not support this functionality, so we should edit in text mode. The section that we modify is Capabilities and in this section we define access to HID.
4. Once changed the appxmanifiest, we can add a listview and a button to display the connected devices. The following function performs this task.
5. If we launch the application, with the USB EMail Notifier (I wrote about this one here), we will see the following output
The next project by Dan Ardelean takes us deeper into using HID, focusing on how to interface with an Xbox 360 controller..
I've started thinking about this post a while ago when Windows 8.1 was still in preview (I actually did some testing at that time because I was really excited about this new "cool" scenario store applications) and after seeing this Build 2013 session: Apps for HID Devices.
As I did not had the cool missile launcher to play with I have chosen the XBOX360 Wireless controller connected to my PC using an USB adapter similar to this one. One of the reasons why I did this, apart from proof of concept post, is because I have some bluetooth toys that I like to "drive" using the Xbox360 controller (starting with version 8.1 we have full bluetooth support for the Store applications: SPP, OBEX, GATT/BLE ). The Xbox360 controller gives one of the best gaming experience, way better than any touchscreen, keyboard or motion controllers and also enables multiplayer gaming on the same device/screen.
In order to be able to connect to the Xbox controller we will need to find the VID, PID and UsagePage specific for our device. As I did not know these values I've used the HClient Sample application to retrieve them. To run the HClient sample you will need Microsoft Visual Studio 2013 and, more important, Windows Driver Kit (WDK) 8.1. HClient gives you detailed information on all the HID devices connected to your PC and to easily find out which HID device is the one you are looking for just disconnect the device from the computer, look at the items inside the list, reconnect the device and identify the new device. This way I identified that my XBOX360 controller has VID: 0x045E, PID: 0x02A1, UsagePage: 0x1, Usage: 0x5 (there might be multiple hardware versions of the desktop adapter that might have different PIDs):
Selecting the HID Caps for the controller we will see that the input report is 15 bytes long and we don't have an output or a feature report available for this device. This is one of the reasons why, in this case, it would be better to use XInput instead of HID because it would give you access to the lights and the motors inside the controller.
Now that we have the needed values we can start to build our Windows Store application. The first thing we need to do is to set the necessary Capabilities that enable communication between our application and the Xbox controller (manually edit the Package.appxmanifest inside your project using the View code option). In want to know more about the options you can set read How to specify device capabilities for HID.
If everything went fine we are now connected to at least one Xbox360 Controller and we can subscribe the InputReportReceived event. The input report contain all the 15 bytes that we need and we can manually parse the bytes or, even better, we can use the defined structures. In our case we have 10 BooleanControls which are our buttons :
There, two HID projects for the price of one. No more excuses now! HID is no longer hard, so use it already!