locked
Problem of using HidP_GetUsageValue to retrieval touch hid report. RRS feed

  • Question

  • I tyied to retrieval the hid report of a touch screen and got a problem of using the API, HidP_GetUsageValue, to get the value of tip-switch. Here is the hid report descriptor for the touch screen.

    const char HidReportDescriptor[] =
    {
        0x05, 0x0D,  //Usage Page (Digitizer)   
        0x09, 0x04,  //Usage (Touch Screen)  
        0xA1, 0x01,  //Collection (Application)   
        0x85, 0x01,  //Report ID (1)   
        0x09, 0x22,  //Usage (Finger)   
        0xA1, 0x02,  //Collection (Logical)  
        0x09, 0x42,  //Usage (Tip Switch)   
        0x15, 0x00,  //Logical Minimum (0)   
        0x25, 0x01,  //Logical Maximum (1)   
        0x75, 0x01,  //Report Size (1)   
        0x95, 0x01,  //Report Count (1)   
        0x81, 0x02,  //Input (Data,Var,Abs,NWrp,Lin,Pref,NNul,Bit)   
        0x95, 0x07,  //Report Count (7)   
        0x81, 0x03,  //Input (Cnst,Var,Abs,NWrp,Lin,Pref,NNul,Bit)   
        ...
        ...
    }
    

    When I use HidP_GetUsageValue to get the value of tip-switch, it gets the error of HIDP_STATUS_USAGE_NOT_FOUND.

    /* header file*/ typedef UINT (_stdcall * PGetRawInputDeviceInfoW)( HANDLE hDevice, UINT uiCommand, LPVOID pData, PUINT pcbSize ); typedef NTSTATUS ( __stdcall* PHidP_GetUsageValue )( IN HIDP_REPORT_TYPE ReportType, IN USAGE UsagePage, IN USHORT LinkCollection, // Optional IN USAGE Usage, OUT PULONG UsageValue, IN PHIDP_PREPARSED_DATA PreparsedData, IN PCHAR Report, IN ULONG ReportLength );

     

    /* parser code */ PHIDP_PREPARSED_DATA pPreparsedData; HIDP_CAPS Caps; UINT bufferSize; ULONG usageLength, value; USHORT capsLength; HANDLE hHeap; PHIDP_BUTTON_CAPS pButtonCaps; int ret;
    hHeap = GetProcessHeap(); HMODULE hDll = LoadLibraryA("User32.dll"); HWND pProc = GetProcAddress(hDll, "GetRawInputDeviceInfoW"); FreeLibrary(hDll);
    PGetRawInputDeviceInfoW GetRawInputDeviceInfo = (PGetRawInputDeviceInfoW)pProc; GetRawInputDeviceInfo(pRawInput->header.hDevice, RIDI_PREPARSEDDATA, NULL,
    &bufferSize);
    pPreparsedData = (PHIDP_PREPARSED_DATA)HeapAlloc(hHeap, 0, bufferSize); GetRawInputDeviceInfo(pRawInput->header.hDevice, RIDI_PREPARSEDDATA, pPreparsedData, &bufferSize ); HidP_GetCaps(pPreparsedData, &Caps);
    hDll = LoadLibraryA("hid.dll"); pProc = GetProcAddress(hDll, "HidP_GetUsageValue"); FreeLibrary(hDll); PHidP_GetUsageValue myHidP_GetUsageValue = (PHidP_GetUsageValue)pProc; pButtonCaps = (PHIDP_BUTTON_CAPS)HeapAlloc(hHeap, 0, sizeof(HIDP_BUTTON_CAPS) * Caps.NumberInputButtonCaps); capsLength = Caps.NumberInputButtonCaps; HidP_GetButtonCaps(HidP_Input, pButtonCaps, &capsLength, pPreparsedData); usageLength = Caps.NumberInputButtonCaps;
    for( int i = 0; i < Caps.NumberInputButtonCaps; i ++ ) { if((ret = myHidP_GetUsageValue(HidP_Input, pButtonCaps[i].UsagePage,
    pButtonCaps[i].LinkCollection, pButtonCaps[i].NotRange.Usage,
    &value, pPreparsedData, (PCHAR)pRawInput->data.hid.bRawData, pRawInput->data.hid.dwSizeHid)) == HIDP_STATUS_SUCCESS) { /*Process for tip-switch*/ } switch (ret) { case HIDP_STATUS_SUCCESS : /* correct*/ break; case HIDP_STATUS_INCOMPATIBLE_REPORT_ID: /* error*/ break; case HIDP_STATUS_INVALID_PREPARSED_DATA: /* error*/ break; case HIDP_STATUS_USAGE_NOT_FOUND: /* error*/ break; } }


    The execution information is shown below.

    UsagePage : 0xd, Usage : 0x42, LinkCollection : 1, value : HIDP_STATUS_USAGE_NOT_FOUND( tip-switch )
    UsagePage : 0xd, Usage : 0x42, LinkCollection : 2, value : HIDP_STATUS_USAGE_NOT_FOUND( tip-switch )
    UsagePage : 0xd, Usage : 0x42, LinkCollection : 3, value : HIDP_STATUS_USAGE_NOT_FOUND( tip-switch )
    UsagePage : 0xd, Usage : 0x42, LinkCollection : 4, value : HIDP_STATUS_USAGE_NOT_FOUND( tip-switch )
    UsagePage : 0xd, Usage : 0x42, LinkCollection : 5, value : HIDP_STATUS_USAGE_NOT_FOUND( tip-switch ) 

    Is I passed anything wrong to the API?Thanks for your help.




    • Edited by Viccloud Tuesday, December 9, 2014 3:09 AM
    Tuesday, December 9, 2014 2:51 AM

All replies

  • I use HidP_GetValueCaps to get a data list, and then use HidP_GetUsageValue with the list to get the x, y and id of the touches. But I dont know how to get the on/off information about touches.


    Friday, August 7, 2015 8:50 AM