From: Aric Stewart Subject: [11/11]hid: Implement HidP_GetScaledUsageValue Message-Id: <55928E49.7060600@codeweavers.com> Date: Tue, 30 Jun 2015 07:40:41 -0500 --- dlls/hid/hid.spec | 2 +- dlls/hid/hidp.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++------ include/ddk/hidpi.h | 1 + 3 files changed, 48 insertions(+), 7 deletions(-) diff --git a/dlls/hid/hid.spec b/dlls/hid/hid.spec index 8772a35..c7b056d 100644 --- a/dlls/hid/hid.spec +++ b/dlls/hid/hid.spec @@ -23,7 +23,7 @@ @ stub HidP_GetData @ stub HidP_GetExtendedAttributes @ stub HidP_GetLinkCollectionNodes -@ stub HidP_GetScaledUsageValue +@ stdcall HidP_GetScaledUsageValue(long long long long ptr ptr ptr long) @ stub HidP_GetSpecificButtonCaps @ stub HidP_GetSpecificValueCaps @ stdcall HidP_GetUsageValue(long long long long ptr ptr ptr long) diff --git a/dlls/hid/hidp.c b/dlls/hid/hidp.c index eab1fbe..135f2b2 100644 --- a/dlls/hid/hidp.c +++ b/dlls/hid/hidp.c @@ -149,15 +149,14 @@ NTSTATUS WINAPI HidP_GetCaps(PHIDP_PREPARSED_DATA PreparsedData, return HIDP_STATUS_SUCCESS; } - -NTSTATUS WINAPI HidP_GetUsageValue(HIDP_REPORT_TYPE ReportType, USAGE UsagePage, USHORT LinkCollection, USAGE Usage, PULONG UsageValue, PHIDP_PREPARSED_DATA PreparsedData, PCHAR Report, ULONG ReportLength) +static NTSTATUS find_value(HIDP_REPORT_TYPE ReportType, USAGE UsagePage, USHORT LinkCollection, USAGE Usage, PHIDP_PREPARSED_DATA PreparsedData, PCHAR Report, WINE_HID_ELEMENT **element) { PWINE_HIDP_PREPARSED_DATA data = (PWINE_HIDP_PREPARSED_DATA)PreparsedData; WINE_HID_REPORT *report = NULL; USHORT v_count = 0, r_count = 0; int i; - TRACE("(%i, %x, %i, %i, %p, %p, %p, %i)\n", ReportType, UsagePage, LinkCollection, Usage, UsageValue, PreparsedData, Report, ReportLength); + TRACE("(%i, %x, %i, %i, %p, %p)\n", ReportType, UsagePage, LinkCollection, Usage, PreparsedData, Report); if (data->magic != HID_MAGIC) return HIDP_STATUS_INVALID_PREPARSED_DATA; @@ -202,15 +201,56 @@ NTSTATUS WINAPI HidP_GetUsageValue(HIDP_REPORT_TYPE ReportType, USAGE UsagePage, report->Elements[i].caps.value.UsagePage == UsagePage && report->Elements[i].caps.value.u.NotRange.Usage == Usage) { - return GetReportData((BYTE*)Report, ReportLength, - report->Elements[i].valueStartBit, - report->Elements[i].bitCount, UsageValue); + *element = &report->Elements[i]; + return HIDP_STATUS_SUCCESS; } } return HIDP_STATUS_USAGE_NOT_FOUND; } +NTSTATUS WINAPI HidP_GetScaledUsageValue(HIDP_REPORT_TYPE ReportType, USAGE UsagePage, USHORT LinkCollection, USAGE Usage, PLONG UsageValue, PHIDP_PREPARSED_DATA PreparsedData, PCHAR Report, ULONG ReportLength) +{ + NTSTATUS rc; + WINE_HID_ELEMENT *element; + TRACE("(%i, %x, %i, %i, %p, %p, %p, %i)\n", ReportType, UsagePage, LinkCollection, Usage, UsageValue, PreparsedData, Report, ReportLength); + + rc = find_value(ReportType, UsagePage, LinkCollection, Usage, PreparsedData, Report, &element); + + if (rc == HIDP_STATUS_SUCCESS) + { + ULONG rawValue; + rc = GetReportData((BYTE*)Report, ReportLength, + element->valueStartBit, element->bitCount, &rawValue); + if (rc != HIDP_STATUS_SUCCESS) + return rc; + if (element->caps.value.BitSize == 16) + rawValue = (short)rawValue; + *UsageValue = rawValue; + } + + return rc; +} + + +NTSTATUS WINAPI HidP_GetUsageValue(HIDP_REPORT_TYPE ReportType, USAGE UsagePage, USHORT LinkCollection, USAGE Usage, PULONG UsageValue, PHIDP_PREPARSED_DATA PreparsedData, PCHAR Report, ULONG ReportLength) +{ + WINE_HID_ELEMENT *element; + NTSTATUS rc; + + TRACE("(%i, %x, %i, %i, %p, %p, %p, %i)\n", ReportType, UsagePage, LinkCollection, Usage, UsageValue, PreparsedData, Report, ReportLength); + + rc = find_value(ReportType, UsagePage, LinkCollection, Usage, PreparsedData, Report, &element); + + if (rc == HIDP_STATUS_SUCCESS) + { + return GetReportData((BYTE*)Report, ReportLength, + element->valueStartBit, element->bitCount, UsageValue); + } + + return rc; +} + NTSTATUS WINAPI HidP_GetUsages(HIDP_REPORT_TYPE ReportType, USAGE UsagePage, USHORT LinkCollection, PUSAGE UsageList, PULONG UsageLength, PHIDP_PREPARSED_DATA PreparsedData, PCHAR Report, ULONG ReportLength) { diff --git a/include/ddk/hidpi.h b/include/ddk/hidpi.h index 40821de..527a966 100644 --- a/include/ddk/hidpi.h +++ b/include/ddk/hidpi.h @@ -143,6 +143,7 @@ NTSTATUS WINAPI HidP_GetUsageValue(HIDP_REPORT_TYPE ReportType, USAGE UsagePage, NTSTATUS WINAPI HidP_GetValueCaps(HIDP_REPORT_TYPE ReportType, PHIDP_VALUE_CAPS ValueCaps, PUSHORT ValueCapsLength, PHIDP_PREPARSED_DATA PreparsedData); NTSTATUS WINAPI HidP_InitializeReportForID(HIDP_REPORT_TYPE ReportType, UCHAR ReportID, PHIDP_PREPARSED_DATA PreparsedData, PCHAR Report, ULONG ReportLength); ULONG WINAPI HidP_MaxUsageListLength(HIDP_REPORT_TYPE ReportType, USAGE UsagePage, PHIDP_PREPARSED_DATA PreparsedData); +NTSTATUS WINAPI HidP_GetScaledUsageValue(HIDP_REPORT_TYPE ReportType, USAGE UsagePage, USHORT LinkCollection, USAGE Usage, PLONG UsageValue, PHIDP_PREPARSED_DATA PreparsedData, PCHAR Report, ULONG ReportLength); #ifndef FACILITY_HID_ERROR_CODE #define FACILITY_HID_ERROR_CODE 0x11