获取HID设备功能报告描述符的本机方法? [英] Native way to get the feature report descriptor of HID device?

查看:758
本文介绍了获取HID设备功能报告描述符的本机方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一些 HID设备(触摸数字化仪)与内部R& D工具进行通信.该工具从设备中解析原始特征报告,以绘制触摸报告以及原始特征报告中存在但被Windows 7的HID驱动程序过滤掉的一些其他数据(例如,压力数据) WM_TOUCH消息中不存在.

We have some HID devices (touch digitizers) that communicate with an internal R&D tool. This tool parses the raw feature reports from the devices to draw the touch reports along with some additional data that are present in the raw feature report but filtered out by the HID driver of Windows 7 (eg, pressure data is not present in WM_TOUCH messages).

但是,我们已经开始使用某些设备,这些设备可能具有不同的固件版本,因此它们不共享字段的相同顺序或字节长度,因此我需要修改我们的R& D工具,以使其能够透明地适应所有设备.

However, we have started working with some devices that may have different firmware variants, and thus that do not share the same ordering or bytelength of the fields and I need to modify our R&D tool so that it will adapt transparently to all the devices.

设备来自同一制造商(我们自己),并且共享相同的设备信息,因此不能选择使用这些字段来区分不同的固件.我想做的是获取设备发送的HID功能报告描述符,并根据此信息动态更新我们的功能报告解析方法.

The devices come from the same manufacturer (ourselves) and share the same device info, so using these fields to differentiate between the different firmwares is not an option. What I would like to do is to get the HID feature report descriptor sent by the device and update dynamically our feature report parsing method based on this information.

但是,在浏览Windows API时,我没有设法找到正确的调用方法来获取此描述符.到目前为止,我发现的是原始输入页面在MSDN上,但是我不确定下一步该怎么做.我可以在 RID_DEVICE_HID 中找到所需的信息结构?还是我需要调用完全不同的API?

However, I didn't manage to find the correct method to call in order to get this descriptor when browsing the Windows API. What I have found so far is the Raw Input page on MSDN, but I'm not sure what to do next. Can I find the required information in the RID_DEVICE_HID structure ? Or do I need to call a completely different API ?

提前感谢您的帮助!

推荐答案

好吧,终于有了(几乎全部)功能.正如 mcoill 所推断的那样,我使用了HidP_xxx()函数家族,但是它首先需要一点数据准备.

Ok, finally I've got something (almost completely) functional. As inferred by mcoill, I used the HidP_xxx() family of functions, but it needs a little bit of data preparation first.

我基于此

I based my solution on this example code that targets USB joysticks and adapted it to touch digitizer devices. If someone else also gets confused by the online doc, here are the required steps involved in the process:

    在启动时
  1. 原始输入设备注册应用程序. 这是通过调用函数RegisterRawInputDevice(&Rid, 1, sizeof(Rid))完成的,其中RidRAWINPUTDEVICE并设置了以下属性(为了获得触摸数字转换器):

  1. registering the application for a Raw Input device at launch. This is done by calling the function RegisterRawInputDevice(&Rid, 1, sizeof(Rid)), where Rid is a RAWINPUTDEVICE with the following properties set (in order to get a touch digitizer) :

Rid.usUsage = 0x04;
Rid.usUsagePage = 0x0d;
Rid.dwFlags = RIDEV_INPUT_SINK;

  • 为事件WM_INPUT注册回调OnInput(LPARAM lParam),因为Rid设备将生成此类事件;

  • registering a callback OnInput(LPARAM lParam) for the events WM_INPUT since the Rid device will generate this type of events;

    OnInput(LPARAM lParam)方法将通过两个步骤从此事件获取数据:

    the OnInput(LPARAM lParam) method will get the data from this event in two steps:

    // Parse the raw input header to read its size.
    UINT bufferSize;
    GetRawInputData(HRAWINPUT)lParam, RID_INPUT, NULL, &bufferSize, sizeof(RAWINPUTHEADER));
    
    // Allocate memory for the raw input data and retrieve it
    PRAWINPUT = (PRAWINPUT)HeapAlloc(GetProcessHeap(), 0, bufferSize);
    GetRawInputData(HRAWINPUT)lParam, RID_INPUT, rawInput /* NOT NULL */, &bufferSize, sizeof(RAWINPUTHEADER));
    

  • 然后调用解析方法,该方法创建查找功能所需的HIDP_PREPARSED_DATA结构:

    // Again, read the data size, allocate then retrieve
    GetRawInputDeviceInfo(rawInput->header.hDevice, RIDI_PREPARSEDDATA, NULL, &bufferSize);
    PHIDP_PREPARSED_DATA preparsedData = (PHIDP_PREPARSED_DATA)HeapAlloc(heap, 0, bufferSize);
    GetRawInputDeviceInfo(rawInput->header.hDevice, RIDI_PREPARSEDDATA, preparsedData, &bufferSize);
    

  • 准备的数据分为功能:

        // Create a structure that will hold the values
        HidP_GetCaps(preparsedData, &caps);
        USHORT capsLength = caps.NumberInputValueCaps;
        PHIDP_VALUE_CAPS valueCaps = (PHIDP_VALUE_CAPS)HeapAlloc(heap, 0, capsLength*sizeof(HIDP_VALUE_CAPS));
        HidP_GetValueCaps(HidP_Input, valueCaps, &capsLength, preparsedData);
    

    然后可以要求功能的价值:

    And capabilities can be asked for their value:

        // Read sample value
        HidP_GetUsageValue(HidP_Input, valueCaps[i].UsagePage, 0, valueCaps[i].Range.UsageMin, &value, preparsedData, (PCHAR)rawInput->data.hid.bRawData, rawInput->data.hid.dwSizeHid);
    

    这篇关于获取HID设备功能报告描述符的本机方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆