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

Working HID Devices on Win 10-RPI2

The following HID devices were tested on a Windows 10 RPI2 running Build 10240:

USB

  • Generic USB Mouse work OK PnP
  • Generic USB Keyboard work OK PnP

USB-Wireless

  • Microsoft Arc Mouse works OK PnP

 

USB Bluetooth

  • Microsoft Bluetooth Mouse works OK Didn’t need pairing code. Just activated device when pairing.
  • Microsoft Bluetooth Keyboard: Could not get it to pair
  • ACER Bluetooth Travel Mouse works OK. Didn’t need pairing code. Just activated device when pairing.

 

PnP: Plug and play (not plug and pray!) No set up, just plug it in and let it set up and your away! Smile


USB HID

A USB HID device is identified by a number of hardware Ids which can be viewed via Device Manager:

  • Vendor ID (vid)
  • Product ID (pid)
  • Usage Page
  • Usage ID

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:

  • In Windows 10, right click on the Start Menu and select Device Manager
  • Find the HID device in the tree (you will probably have to expand the tree). Right click on it and choose Properties
    Eg.  Keyboards/HID Keyboard Device
  • Select the Details tab and choose Hardware Ids
  • The top line will be a string with VID and PID, eg HID\VID_045E&PID_07B1&REV_0674&MI_00
  • Lower down is a string such as HID_DEVICE_UP:0001_U:0006. 0001 is the Usage Page and 0006 is the Usage ID.

image

The HID Hardware Ids for a USB Keyboard, as Device Manager


HID Usage

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.

Usage Page

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.

Usage ID

In the context of a usage page, a valid usage identifier, or

usage ID

, 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

 

image

Desktop Page including Mouse and keyboard.

A Mouse is 01,02  (Usage Page, Usage Id) and a  keypad is 01, 06

 

image

Game Controls Page

A 3D Game Controller would be 05, 01 whereas a Pinball device would be 05, 02

 

HID Coding

A USB HID device is identified by a number of hardware Ids which can be viewed via Device Manager:

  • Vendor ID (vid)
  • Product ID (pid)
  • Usage Page
  • Usage ID

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); }

 

 

 

 

 

 

 

HIDSample Program

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.

 

image

 

  • To check if a HID device is present, enter the four IDs on the left and press the green button.
  • You will need to get the VID and PID from Device Manager prior.
  • You can get the Usage IDs from device manager or select from the HID device class from the dropdown menu top right:

 

 

image

 

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.

 

  • To use the four “Set” buttons, you need to set suitable parameters for devices on your system, as per Device Manager.
    The button handlers set these specific values such that when pressed, five parameters (including the class GUID) are written to the textboxes on the left.

 

  • The other three buttons, lower right exercise three USB APIs that search for USB devices (not necessarily HID) but I haven’t got any joy out of these. See the code. Please leave comments if you can contribute. It is noted in the code comments that a similar API for Serial does work. This is covered in the 2nd next blog.

 

The Take Home:

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>