Human Interface Devices (HID) are supported in the “headful/headed” (viz. headless) version of Windows 10 IoT. Anything that takes users input for an app is an HID device, and can include devices such as screens that provide feedback to the user. Traditional HID devices are the mouse and keyboard, whereas gaming devices such as joystick, XBox controller and steering wheel are also HID devices. A barcode scanner or credit scanner are also be HID devices, A system with just a few push buttons to control it has those pushbuttons as a trivial HID. Technically the HID protocol was developed as a protocol for the USB-HID class such that devices that conform to that class do not need a specific driver.
USB in Universal Apps (in the Windows 8.1 context) is discussed in detail at : https://msdn.microsoft.com/en-us/library/windows/apps/bg182882.aspx
The following HID devices were tested on a Windows 10 RPI2 running Build 10240:
PnP: Plug and play (not plug and pray!) No set up, just plug it in and let it set up and your away!
A USB HID device is identified by a number of hardware Ids which can be viewed via Device Manager:
The Vendor ID is unique to the OEM hardware manufacturer. For example, Intel is 8086, guess why!
The Product Id is the registered Id for a specific product from that OEM. The Usage page is defined list of groupings of USB HID devices The Usage ID is a device class’ id within a group.
For a connected USB HID, these four parameters can be determined from Device Manager:
The HID Hardware Ids for a USB Keyboard, as Device Manager
Ref: Universal Serial Bus - HID Usage Tables - From USB.org
Ref: HID Usages – From MSDN
Note: Whilst the VID and PID are OEM specific, the UsagePageID and UsageID are USB HID specific and can be looked up for a specific USB HID device type.
HID usages are organized into
usage pages
of related controls. A specific control usage is defined by its usage page, a
usage ID
, a name, and a description. Examples of usage pages include Generic Desktop Controls, Game Controls, LEDs, Button, and so on. Examples of controls that are listed on the Generic Desktop Controls usage page include pointers, mouse and keyboard devices, joysticks, and so on. A usage page value is a 16-bit unsigned value.
In the context of a usage page, a valid usage identifier, or
, is a positive integer greater than zero that indicates a usage in a usage page. A usage ID of zero is reserved. A usage ID value is an unsigned 16-bit value
Usage Page Examples:
01h Generic Desktop Controls .. includes Mouse, Keyboard, Keypad and Joystick 02h Simulation Controls 03h VR Controls 04h Sport Controls 05h Game Controls 06h Generic Device Controls 07h Keyboard/ Keypad 08h LEDs 09h Button 0Ah Ordinal 0Bh Telephony Devices 0Ch Consumer Devices 0Dh Digitizer 0Fh Physical Input Device (PID) 10h Unicode 14h Alphanumeric Display 40h Medical Instruments 80h Monitor Devices 81h Monitor Enumerated Values 82h VESA Virtual Controls 83h VESA Command 84h Power Device 85h Battery System
Ref:: http://www.usb.org/developers/hidpage/Hut1_12v2.pdf
Desktop Page including Mouse and keyboard.
A Mouse is 01,02 (Usage Page, Usage Id) and a keypad is 01, 06
Game Controls Page
A 3D Game Controller would be 05, 01 whereas a Pinball device would be 05, 02
You get a “connector” to an HID using the following code, which is typical of hardware access under UWP:
// Create a selector that gets a HID device using VID/PID and a // VendorDefined usage. string selector = HidDevice.GetDeviceSelector(usagePageId, usageId, vendorId, productId); // Enumerate devices using the selector. var devices = await DeviceInformation.FindAllAsync(selector);
The HidDevice is referenced using:
using Windows.Devices.HumanInterfaceDevice;
You then enumerate the devices, which normally would only be one, to get the first such device .. or just take teh first one:
HidDevice hidDevice; if (devices.Count > 0) { // Open the target HID device at index 0. hidDevice = await HidDevice.FromIdAsync(devices.ElementAt(0).Id, FileAccessMode.ReadWrite); }
The
hidDevice
object can then be used in further code to make use of the HID device, such as:
private async Task GetNumericInputReportAsync() { var inputReport = await DeviceList.Current.CurrentDevice.GetInputReportAsync( hidDevice.ReadWriteBuffer.ReportId); var inputReportControl = inputReport.GetNumericControl( hidDevice.ReadWriteBuffer.NumericUsagePage, hidDevice.ReadWriteBuffer.NumericUsageId); var data = inputReportControl.Value; this.NotifyUser("Value read: " + data.ToString( "X2", NumberFormatInfo.InvariantInfo), NotifyType.StatusMessage); }
There is a C# UWP project on GitHub that actions the query for a USB HID device (not the last code segment though). Link: https://github.com/djaus2/WindowsDevices That’s the same repository (updated) as the previous blog. Look for the HIDSampler folder.
Given the four parameters as above, it can check if the USB device is present on the system. The system can be Windows 10 Desktop, phone or IoT. Just set the target CPU and target as usual, deploy and run it.
This menu is created by reading in a JSON file and turning it into a list (using Linq) that then is bound to the menu. See the next blog.
An app is presented that can be used to check the availability of USB connected HID devices on a Windows 10 System, including for Win 10 IoT RPI2.
Next: 1. The JSON code in the above app <ToDo> 2. Win 10 –IoT; Serial <ToDo>