hid: Rewrite HidP_SetUsageValue using enum_value_caps.

Signed-off-by: Rémi Bernon <rbernon@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Rémi Bernon 2021-06-25 10:06:50 +02:00 committed by Alexandre Julliard
parent 0a192647fe
commit cb5856695c
2 changed files with 12 additions and 62 deletions

View File

@ -192,48 +192,6 @@ static NTSTATUS get_report_data(BYTE *report, INT reportLength, INT startBit, IN
return HIDP_STATUS_SUCCESS;
}
static NTSTATUS set_report_data(BYTE *report, INT reportLength, INT startBit, INT valueSize, ULONG value)
{
if ((startBit + valueSize) / 8 > reportLength)
return HIDP_STATUS_INVALID_REPORT_LENGTH;
if (valueSize == 1)
{
ULONG byte_index = startBit / 8;
ULONG bit_index = startBit - (byte_index * 8);
if (value)
report[byte_index] |= (1 << bit_index);
else
report[byte_index] &= ~(1 << bit_index);
}
else
{
ULONG byte_index = (startBit + valueSize - 1) / 8;
ULONG data = value;
ULONG remainingBits = valueSize;
while (remainingBits)
{
BYTE subvalue = data & 0xff;
data >>= 8;
if (remainingBits >= 8)
{
report[byte_index] = subvalue;
byte_index --;
remainingBits -= 8;
}
else if (remainingBits > 0)
{
BYTE mask = (0xff << (8-remainingBits)) & subvalue;
report[byte_index] |= mask;
remainingBits = 0;
}
}
}
return HIDP_STATUS_SUCCESS;
}
NTSTATUS WINAPI HidP_GetButtonCaps( HIDP_REPORT_TYPE report_type, HIDP_BUTTON_CAPS *caps, USHORT *caps_count,
PHIDP_PREPARSED_DATA preparsed_data )
{
@ -533,25 +491,21 @@ static NTSTATUS set_usage_value( const struct hid_value_caps *caps, void *user )
return HIDP_STATUS_NULL;
}
NTSTATUS WINAPI HidP_SetUsageValue(HIDP_REPORT_TYPE ReportType, USAGE UsagePage, USHORT LinkCollection,
USAGE Usage, ULONG UsageValue, PHIDP_PREPARSED_DATA PreparsedData,
CHAR *Report, ULONG ReportLength)
NTSTATUS WINAPI HidP_SetUsageValue( HIDP_REPORT_TYPE report_type, USAGE usage_page, USHORT collection, USAGE usage,
ULONG value, PHIDP_PREPARSED_DATA preparsed_data, char *report_buf, ULONG report_len )
{
WINE_HID_ELEMENT element;
NTSTATUS rc;
struct usage_value_params params = {.value_buf = &value, .value_len = sizeof(value), .report_buf = report_buf};
WINE_HIDP_PREPARSED_DATA *preparsed = (WINE_HIDP_PREPARSED_DATA *)preparsed_data;
struct caps_filter filter = {.values = TRUE, .usage_page = usage_page, .collection = collection, .usage = usage};
USHORT count = 1;
TRACE("(%i, %x, %i, %i, %i, %p, %p, %i)\n", ReportType, UsagePage, LinkCollection, Usage, UsageValue,
PreparsedData, Report, ReportLength);
TRACE( "report_type %d, usage_page %x, collection %d, usage %x, value %u, preparsed_data %p, report_buf %p, report_len %u.\n",
report_type, usage_page, collection, usage, value, preparsed_data, report_buf, report_len );
rc = find_usage(ReportType, UsagePage, LinkCollection, Usage, PreparsedData, Report, 0, &element);
if (!report_len) return HIDP_STATUS_INVALID_REPORT_LENGTH;
if (rc == HIDP_STATUS_SUCCESS)
{
return set_report_data((BYTE*)Report, ReportLength,
element.valueStartBit, element.bitCount, UsageValue);
}
return rc;
filter.report_id = report_buf[0];
return enum_value_caps( preparsed, report_type, report_len, &filter, set_usage_value, &params, &count );
}
NTSTATUS WINAPI HidP_SetUsageValueArray( HIDP_REPORT_TYPE report_type, USAGE usage_page, USHORT collection,

View File

@ -2093,7 +2093,6 @@ static void test_hidp(HANDLE file, int report_id)
status = HidP_GetUsageValue(HidP_Input, HID_USAGE_PAGE_GENERIC, 0, HID_USAGE_GENERIC_Z,
&value, preparsed_data, report, caps.InputReportByteLength);
ok(status == HIDP_STATUS_SUCCESS, "HidP_GetUsageValue returned %#x\n", status);
todo_wine
ok(value == 0x7fffffff, "got value %x, expected %#x\n", value, 0x7fffffff);
value = 0x3fffffff;
@ -2292,13 +2291,12 @@ static void test_hidp(HANDLE file, int report_id)
status = HidP_SetUsageValue(HidP_Feature, HID_USAGE_PAGE_ORDINAL, waveform_list, 3,
HID_USAGE_HAPTICS_WAVEFORM_RUMBLE, preparsed_data, report,
caps.FeatureReportByteLength + 1);
todo_wine
ok(status == HIDP_STATUS_INVALID_REPORT_LENGTH, "HidP_SetUsageValue returned %#x\n", status);
report[0] = 1 - report_id;
status = HidP_SetUsageValue(HidP_Feature, HID_USAGE_PAGE_ORDINAL, waveform_list, 3,
HID_USAGE_HAPTICS_WAVEFORM_RUMBLE, preparsed_data, report,
caps.FeatureReportByteLength);
todo_wine
todo_wine_if(!report_id)
ok(status == (report_id ? HIDP_STATUS_SUCCESS : HIDP_STATUS_INCOMPATIBLE_REPORT_ID),
"HidP_SetUsageValue returned %#x\n", status);
report[0] = 2;
@ -2310,7 +2308,6 @@ static void test_hidp(HANDLE file, int report_id)
report[0] = report_id;
status = HidP_SetUsageValue(HidP_Feature, HID_USAGE_PAGE_ORDINAL, 0xdead, 3, HID_USAGE_HAPTICS_WAVEFORM_RUMBLE,
preparsed_data, report, caps.FeatureReportByteLength);
todo_wine
ok(status == HIDP_STATUS_USAGE_NOT_FOUND, "HidP_SetUsageValue returned %#x\n", status);
status = HidP_SetUsageValue(HidP_Feature, HID_USAGE_PAGE_ORDINAL, waveform_list, 3,
@ -2323,7 +2320,6 @@ static void test_hidp(HANDLE file, int report_id)
buffer[0] = report_id;
value = HID_USAGE_HAPTICS_WAVEFORM_RUMBLE;
memcpy(buffer + 1, &value, 2);
todo_wine
ok(!memcmp(buffer, report, sizeof(buffer)), "unexpected report data\n");
status = HidP_GetUsageValue(HidP_Feature, HID_USAGE_PAGE_ORDINAL, waveform_list, 3, &value,