|
|
@ -8,7 +8,7 @@ |
|
|
|
8/22/2009 |
|
|
|
8/22/2009 |
|
|
|
|
|
|
|
|
|
|
|
Copyright 2009, All Rights Reserved. |
|
|
|
Copyright 2009, All Rights Reserved. |
|
|
|
|
|
|
|
|
|
|
|
At the discretion of the user of this library, |
|
|
|
At the discretion of the user of this library, |
|
|
|
this software may be licensed under the terms of the |
|
|
|
this software may be licensed under the terms of the |
|
|
|
GNU General Public License v3, a BSD-Style license, or the |
|
|
|
GNU General Public License v3, a BSD-Style license, or the |
|
|
@ -181,7 +181,7 @@ static void register_error(hid_device *device, const char *op) |
|
|
|
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), |
|
|
|
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), |
|
|
|
(LPVOID)&msg, 0/*sz*/, |
|
|
|
(LPVOID)&msg, 0/*sz*/, |
|
|
|
NULL); |
|
|
|
NULL); |
|
|
|
|
|
|
|
|
|
|
|
/* Get rid of the CR and LF that FormatMessage() sticks at the
|
|
|
|
/* Get rid of the CR and LF that FormatMessage() sticks at the
|
|
|
|
end of the message. Thanks Microsoft! */ |
|
|
|
end of the message. Thanks Microsoft! */ |
|
|
|
ptr = msg; |
|
|
|
ptr = msg; |
|
|
@ -292,9 +292,9 @@ struct hid_device_info HID_API_EXPORT * HID_API_CALL hid_enumerate(unsigned shor |
|
|
|
|
|
|
|
|
|
|
|
/* Get information for all the devices belonging to the HID class. */ |
|
|
|
/* Get information for all the devices belonging to the HID class. */ |
|
|
|
device_info_set = SetupDiGetClassDevsA(&InterfaceClassGuid, NULL, NULL, DIGCF_PRESENT | DIGCF_DEVICEINTERFACE); |
|
|
|
device_info_set = SetupDiGetClassDevsA(&InterfaceClassGuid, NULL, NULL, DIGCF_PRESENT | DIGCF_DEVICEINTERFACE); |
|
|
|
|
|
|
|
|
|
|
|
/* Iterate over each device in the HID class, looking for the right one. */ |
|
|
|
/* Iterate over each device in the HID class, looking for the right one. */ |
|
|
|
|
|
|
|
|
|
|
|
for (;;) { |
|
|
|
for (;;) { |
|
|
|
HANDLE write_handle = INVALID_HANDLE_VALUE; |
|
|
|
HANDLE write_handle = INVALID_HANDLE_VALUE; |
|
|
|
DWORD required_size = 0; |
|
|
|
DWORD required_size = 0; |
|
|
@ -305,7 +305,7 @@ struct hid_device_info HID_API_EXPORT * HID_API_CALL hid_enumerate(unsigned shor |
|
|
|
&InterfaceClassGuid, |
|
|
|
&InterfaceClassGuid, |
|
|
|
device_index, |
|
|
|
device_index, |
|
|
|
&device_interface_data); |
|
|
|
&device_interface_data); |
|
|
|
|
|
|
|
|
|
|
|
if (!res) { |
|
|
|
if (!res) { |
|
|
|
/* A return of FALSE from this function means that
|
|
|
|
/* A return of FALSE from this function means that
|
|
|
|
there are no more devices. */ |
|
|
|
there are no more devices. */ |
|
|
@ -377,7 +377,7 @@ struct hid_device_info HID_API_EXPORT * HID_API_CALL hid_enumerate(unsigned shor |
|
|
|
/* Unable to open the device. */ |
|
|
|
/* Unable to open the device. */ |
|
|
|
//register_error(dev, "CreateFile");
|
|
|
|
//register_error(dev, "CreateFile");
|
|
|
|
goto cont_close; |
|
|
|
goto cont_close; |
|
|
|
}
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Get the Vendor ID and Product ID for this device. */ |
|
|
|
/* Get the Vendor ID and Product ID for this device. */ |
|
|
@ -421,14 +421,14 @@ struct hid_device_info HID_API_EXPORT * HID_API_CALL hid_enumerate(unsigned shor |
|
|
|
|
|
|
|
|
|
|
|
HidD_FreePreparsedData(pp_data); |
|
|
|
HidD_FreePreparsedData(pp_data); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/* Fill out the record */ |
|
|
|
/* Fill out the record */ |
|
|
|
cur_dev->next = NULL; |
|
|
|
cur_dev->next = NULL; |
|
|
|
str = device_interface_detail_data->DevicePath; |
|
|
|
str = device_interface_detail_data->DevicePath; |
|
|
|
if (str) { |
|
|
|
if (str) { |
|
|
|
len = strlen(str); |
|
|
|
len = strlen(str); |
|
|
|
cur_dev->path = (char*) calloc(len+1, sizeof(char)); |
|
|
|
cur_dev->path = (char*) calloc(len+1, sizeof(char)); |
|
|
|
strncpy(cur_dev->path, str, len+1); |
|
|
|
strncpy(cur_dev->path, str, sizeof(cur_dev->path)); |
|
|
|
cur_dev->path[len] = '\0'; |
|
|
|
cur_dev->path[len] = '\0'; |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
@ -521,7 +521,7 @@ HID_API_EXPORT hid_device * HID_API_CALL hid_open(unsigned short vendor_id, unsi |
|
|
|
struct hid_device_info *devs, *cur_dev; |
|
|
|
struct hid_device_info *devs, *cur_dev; |
|
|
|
const char *path_to_open = NULL; |
|
|
|
const char *path_to_open = NULL; |
|
|
|
hid_device *handle = NULL; |
|
|
|
hid_device *handle = NULL; |
|
|
|
|
|
|
|
|
|
|
|
devs = hid_enumerate(vendor_id, product_id); |
|
|
|
devs = hid_enumerate(vendor_id, product_id); |
|
|
|
cur_dev = devs; |
|
|
|
cur_dev = devs; |
|
|
|
while (cur_dev) { |
|
|
|
while (cur_dev) { |
|
|
@ -547,7 +547,7 @@ HID_API_EXPORT hid_device * HID_API_CALL hid_open(unsigned short vendor_id, unsi |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
hid_free_enumeration(devs); |
|
|
|
hid_free_enumeration(devs); |
|
|
|
|
|
|
|
|
|
|
|
return handle; |
|
|
|
return handle; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -590,7 +590,7 @@ HID_API_EXPORT hid_device * HID_API_CALL hid_open_path(const char *path) |
|
|
|
} |
|
|
|
} |
|
|
|
nt_res = HidP_GetCaps(pp_data, &caps); |
|
|
|
nt_res = HidP_GetCaps(pp_data, &caps); |
|
|
|
if (nt_res != HIDP_STATUS_SUCCESS) { |
|
|
|
if (nt_res != HIDP_STATUS_SUCCESS) { |
|
|
|
register_error(dev, "HidP_GetCaps");
|
|
|
|
register_error(dev, "HidP_GetCaps"); |
|
|
|
goto err_pp_data; |
|
|
|
goto err_pp_data; |
|
|
|
} |
|
|
|
} |
|
|
|
dev->output_report_length = caps.OutputReportByteLength; |
|
|
|
dev->output_report_length = caps.OutputReportByteLength; |
|
|
@ -603,7 +603,7 @@ HID_API_EXPORT hid_device * HID_API_CALL hid_open_path(const char *path) |
|
|
|
|
|
|
|
|
|
|
|
err_pp_data: |
|
|
|
err_pp_data: |
|
|
|
HidD_FreePreparsedData(pp_data); |
|
|
|
HidD_FreePreparsedData(pp_data); |
|
|
|
err:
|
|
|
|
err: |
|
|
|
free_hid_device(dev); |
|
|
|
free_hid_device(dev); |
|
|
|
return NULL; |
|
|
|
return NULL; |
|
|
|
} |
|
|
|
} |
|
|
@ -636,7 +636,7 @@ int HID_API_EXPORT HID_API_CALL hid_write(hid_device *dev, const unsigned char * |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
res = WriteFile(dev->device_handle, buf, length, NULL, &ol); |
|
|
|
res = WriteFile(dev->device_handle, buf, length, NULL, &ol); |
|
|
|
|
|
|
|
|
|
|
|
if (!res) { |
|
|
|
if (!res) { |
|
|
|
if (GetLastError() != ERROR_IO_PENDING) { |
|
|
|
if (GetLastError() != ERROR_IO_PENDING) { |
|
|
|
/* WriteFile() failed. Return error. */ |
|
|
|
/* WriteFile() failed. Return error. */ |
|
|
@ -679,7 +679,7 @@ int HID_API_EXPORT HID_API_CALL hid_read_timeout(hid_device *dev, unsigned char |
|
|
|
memset(dev->read_buf, 0, dev->input_report_length); |
|
|
|
memset(dev->read_buf, 0, dev->input_report_length); |
|
|
|
ResetEvent(ev); |
|
|
|
ResetEvent(ev); |
|
|
|
res = ReadFile(dev->device_handle, dev->read_buf, dev->input_report_length, &bytes_read, &dev->ol); |
|
|
|
res = ReadFile(dev->device_handle, dev->read_buf, dev->input_report_length, &bytes_read, &dev->ol); |
|
|
|
|
|
|
|
|
|
|
|
if (!res) { |
|
|
|
if (!res) { |
|
|
|
if (GetLastError() != ERROR_IO_PENDING) { |
|
|
|
if (GetLastError() != ERROR_IO_PENDING) { |
|
|
|
/* ReadFile() has failed.
|
|
|
|
/* ReadFile() has failed.
|
|
|
@ -705,7 +705,7 @@ int HID_API_EXPORT HID_API_CALL hid_read_timeout(hid_device *dev, unsigned char |
|
|
|
we are in non-blocking mode. Get the number of bytes read. The actual |
|
|
|
we are in non-blocking mode. Get the number of bytes read. The actual |
|
|
|
data has been copied to the data[] array which was passed to ReadFile(). */ |
|
|
|
data has been copied to the data[] array which was passed to ReadFile(). */ |
|
|
|
res = GetOverlappedResult(dev->device_handle, &dev->ol, &bytes_read, TRUE/*wait*/); |
|
|
|
res = GetOverlappedResult(dev->device_handle, &dev->ol, &bytes_read, TRUE/*wait*/); |
|
|
|
|
|
|
|
|
|
|
|
/* Set pending back to false, even if GetOverlappedResult() returned error. */ |
|
|
|
/* Set pending back to false, even if GetOverlappedResult() returned error. */ |
|
|
|
dev->read_pending = FALSE; |
|
|
|
dev->read_pending = FALSE; |
|
|
|
|
|
|
|
|
|
|
@ -725,13 +725,13 @@ int HID_API_EXPORT HID_API_CALL hid_read_timeout(hid_device *dev, unsigned char |
|
|
|
memcpy(data, dev->read_buf, copy_len); |
|
|
|
memcpy(data, dev->read_buf, copy_len); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
end_of_function: |
|
|
|
end_of_function: |
|
|
|
if (!res) { |
|
|
|
if (!res) { |
|
|
|
register_error(dev, "GetOverlappedResult"); |
|
|
|
register_error(dev, "GetOverlappedResult"); |
|
|
|
return -1; |
|
|
|
return -1; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return copy_len; |
|
|
|
return copy_len; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -876,7 +876,7 @@ HID_API_EXPORT const wchar_t * HID_API_CALL hid_error(hid_device *dev) |
|
|
|
/*#define PICPGM*/ |
|
|
|
/*#define PICPGM*/ |
|
|
|
/*#define S11*/ |
|
|
|
/*#define S11*/ |
|
|
|
#define P32 |
|
|
|
#define P32 |
|
|
|
#ifdef S11 |
|
|
|
#ifdef S11 |
|
|
|
unsigned short VendorID = 0xa0a0; |
|
|
|
unsigned short VendorID = 0xa0a0; |
|
|
|
unsigned short ProductID = 0x0001; |
|
|
|
unsigned short ProductID = 0x0001; |
|
|
|
#endif |
|
|
|
#endif |
|
|
@ -906,7 +906,7 @@ int __cdecl main(int argc, char* argv[]) |
|
|
|
memset(buf,0x00,sizeof(buf)); |
|
|
|
memset(buf,0x00,sizeof(buf)); |
|
|
|
buf[0] = 0; |
|
|
|
buf[0] = 0; |
|
|
|
buf[1] = 0x81; |
|
|
|
buf[1] = 0x81; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Open the device. */ |
|
|
|
/* Open the device. */ |
|
|
|
int handle = open(VendorID, ProductID, L"12345"); |
|
|
|
int handle = open(VendorID, ProductID, L"12345"); |
|
|
|