forked from nefarius/ScpToolkit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreport.cpp
71 lines (58 loc) · 2.36 KB
/
report.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include "StdAfx.h"
BOOLEAN ReadOverlapped(PHID_DEVICE HidDevice, LPOVERLAPPED lpOverlapped)
{
DWORD bytesRead;
BOOL readStatus;
readStatus = ReadFile(HidDevice->HidDevice, HidDevice->InputReportBuffer, HidDevice->Caps.InputReportByteLength, &bytesRead, lpOverlapped);
if (!readStatus)
{
return GetLastError() == ERROR_IO_PENDING;
}
else
{
SetEvent(lpOverlapped->hEvent);
return TRUE;
}
}
BOOLEAN UnpackReport(__in_bcount(ReportBufferLength) PCHAR ReportBuffer, IN USHORT ReportBufferLength, IN HIDP_REPORT_TYPE ReportType, IN OUT PHID_DATA Data, IN ULONG DataLength, IN PHIDP_PREPARSED_DATA Ppd)
{
ULONG numUsages;
ULONG i;
UCHAR reportID;
ULONG Index;
ULONG nextUsage;
reportID = ReportBuffer[0];
for (i = 0; i < DataLength; i++, Data++)
{
if (reportID == Data->ReportID)
{
if (Data->IsButtonData)
{
numUsages = Data->ButtonData.MaxUsageLength;
Data->Status = HidP_GetUsages(ReportType, Data->UsagePage, 0, Data->ButtonData.Usages, &numUsages, Ppd, ReportBuffer, ReportBufferLength);
for (Index = 0, nextUsage = 0; Index < numUsages; Index++)
{
if (Data->ButtonData.UsageMin <= Data->ButtonData.Usages[Index] && Data->ButtonData.Usages[Index] <= Data->ButtonData.UsageMax)
{
Data->ButtonData.Usages[nextUsage++] = Data->ButtonData.Usages[Index];
}
}
if (nextUsage < Data->ButtonData.MaxUsageLength)
{
Data->ButtonData.Usages[nextUsage] = 0;
}
}
else
{
Data->Status = HidP_GetUsageValue(ReportType, Data->UsagePage, 0, Data->ValueData.Usage, &Data->ValueData.Value, Ppd, ReportBuffer, ReportBufferLength);
if (HIDP_STATUS_SUCCESS != Data->Status)
{
return FALSE;
}
Data->Status = HidP_GetScaledUsageValue(ReportType, Data->UsagePage, 0, Data->ValueData.Usage, &Data->ValueData.ScaledValue, Ppd, ReportBuffer, ReportBufferLength);
}
Data->IsDataSet = TRUE;
}
}
return TRUE;
}