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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
|
/*
hidin.h - headers and declarationd for the 'hidin' external
*/
#ifndef hidin_H
#define hidin_H
#include <windows.h>
#include <basetyps.h>
#include <stdlib.h>
#include <wtypes.h>
#include <setupapi.h>
#ifdef _MSC_VER
#include "hidusage.h"
#include "hidsdi.h"
#else
#include <ddk/hidusage.h>
#include <ddk/hidsdi.h>
#endif
//
// A structure to hold the steady state data received from the hid device.
// Each time a read packet is received we fill in this structure.
// Each time we wish to write to a hid device we fill in this structure.
// This structure is here only for convenience. Most real applications will
// have a more efficient way of moving the hid data to the read, write, and
// feature routines.
//
typedef struct _hid_data
{
BOOLEAN IsButtonData;
UCHAR Reserved;
USAGE UsagePage; // The usage page for which we are looking.
ULONG Status; // The last status returned from the accessor function
// when updating this field.
ULONG ReportID; // ReportID for this given data structure
BOOLEAN IsDataSet; // Variable to track whether a given data structure
// has already been added to a report structure
union {
struct {
ULONG UsageMin; // Variables to track the usage minimum and max
ULONG UsageMax; // If equal, then only a single usage
ULONG MaxUsageLength; // Usages buffer length.
PUSAGE Usages; // list of usages (buttons ``down'' on the device.
} ButtonData;
struct {
USAGE Usage; // The usage describing this value;
USHORT Reserved;
ULONG Value;
LONG ScaledValue;
} ValueData;
};
} t_hid_data;
typedef struct _hid_device
{
PCHAR devicePath;
HANDLE device; // A file handle to the hid device.
HANDLE event;
OVERLAPPED overlapped;
BOOL openedForRead;
BOOL openedForWrite;
BOOL openedOverlapped;
BOOL openedExclusive;
PHIDP_PREPARSED_DATA ppd; // The opaque parser info describing this device
HIDP_CAPS caps; // The Capabilities of this hid device.
HIDD_ATTRIBUTES attributes;
char *inputReportBuffer;
t_hid_data *inputData; // array of hid data structures
ULONG inputDataLength; // Num elements in this array.
PHIDP_BUTTON_CAPS inputButtonCaps;
PHIDP_VALUE_CAPS inputValueCaps;
char *outputReportBuffer;
t_hid_data *outputData;
ULONG outputDataLength;
PHIDP_BUTTON_CAPS outputButtonCaps;
PHIDP_VALUE_CAPS outputValueCaps;
char *featureReportBuffer;
t_hid_data *featureData;
ULONG featureDataLength;
PHIDP_BUTTON_CAPS featureButtonCaps;
PHIDP_VALUE_CAPS featureValueCaps;
} t_hid_device;
/*
* displays the vendor and product ID and the version
* number for the given device handle
*/
void getDeviceInfo(HANDLE deviceHandle);
/*
* find number of attached HID devices
*/
int findHidDevices();
/*
* find name of attached HID devices
*/
t_symbol *findDeviceName(DWORD deviceID);
/*
* connects to the hid device specified through a number
* returns a handle to the device (x->x_hid.device)
*/
HANDLE connectDeviceNumber(DWORD i);
/* Connects to the USB HID described by the combination of vendor id, product id
If the attribute is null, it will connect to first device satisfying the remaining
attributes. */
HANDLE connectDeviceName(DWORD *vendorID, DWORD *productID, DWORD *versionNumber);
/*
* get hid device capabilities (and display them)
* also instantiates the x->x_hid.caps field and
* allocates the memory we'll need to use this device
*/
void getDeviceCapabilities(t_hid_device *hid);
/*
* read input data from hid device and display them
*/
int readHid(t_hid_device *hidDevice);
int readHidOverlapped(t_hid_device *hidDevice);
BOOLEAN getFeature(t_hid_device *HidDevice);
BOOLEAN unpackReport(PCHAR ReportBuffer, USHORT ReportBufferLength, HIDP_REPORT_TYPE ReportType,
t_hid_data *Data, ULONG DataLength, PHIDP_PREPARSED_DATA Ppd);
BOOLEAN packReport(PCHAR ReportBuffer, USHORT ReportBufferLength, HIDP_REPORT_TYPE ReportType,
t_hid_data *Data, ULONG DataLength, PHIDP_PREPARSED_DATA Ppd);
#endif // hidin_H
|