Skip to content

Commit

Permalink
Whitespace cleanup in windows implementation (libusb#302)
Browse files Browse the repository at this point in the history
  • Loading branch information
DJm00n authored Jul 9, 2021
1 parent 5a88dcd commit 9404a95
Showing 1 changed file with 23 additions and 23 deletions.
46 changes: 23 additions & 23 deletions windows/hid.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
8/22/2009
Copyright 2009, All Rights Reserved.
At the discretion of the user of this library,
this software may be licensed under the terms of the
GNU General Public License v3, a BSD-Style license, or the
Expand Down Expand Up @@ -153,7 +153,7 @@ struct hid_device_ {
BOOL read_pending;
char *read_buf;
OVERLAPPED ol;
OVERLAPPED write_ol;
OVERLAPPED write_ol;
};

static hid_device *new_hid_device()
Expand All @@ -173,15 +173,15 @@ static hid_device *new_hid_device()
memset(&dev->ol, 0, sizeof(dev->ol));
dev->ol.hEvent = CreateEvent(NULL, FALSE, FALSE /*initial state f=nonsignaled*/, NULL);
memset(&dev->write_ol, 0, sizeof(dev->write_ol));
dev->write_ol.hEvent = CreateEvent(NULL, FALSE, FALSE /*inital state f=nonsignaled*/, NULL);
dev->write_ol.hEvent = CreateEvent(NULL, FALSE, FALSE /*inital state f=nonsignaled*/, NULL);

return dev;
}

static void free_hid_device(hid_device *dev)
{
CloseHandle(dev->ol.hEvent);
CloseHandle(dev->write_ol.hEvent);
CloseHandle(dev->write_ol.hEvent);
CloseHandle(dev->device_handle);
LocalFree(dev->last_error_str);
free(dev->write_buf);
Expand All @@ -202,7 +202,7 @@ static void register_error(hid_device *dev, const char *op)
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPWSTR)&msg, 0/*sz*/,
NULL);

/* Get rid of the CR and LF that FormatMessage() sticks at the
end of the message. Thanks Microsoft! */
ptr = msg;
Expand Down Expand Up @@ -333,9 +333,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. */
device_info_set = SetupDiGetClassDevsA(&InterfaceClassGuid, NULL, NULL, DIGCF_PRESENT | DIGCF_DEVICEINTERFACE);

/* Iterate over each device in the HID class, looking for the right one. */

for (;;) {
HANDLE write_handle = INVALID_HANDLE_VALUE;
DWORD required_size = 0;
Expand All @@ -346,7 +346,7 @@ struct hid_device_info HID_API_EXPORT * HID_API_CALL hid_enumerate(unsigned shor
&InterfaceClassGuid,
device_index,
&device_interface_data);

if (!res) {
/* A return of FALSE from this function means that
there are no more devices. */
Expand Down Expand Up @@ -406,7 +406,7 @@ struct hid_device_info HID_API_EXPORT * HID_API_CALL hid_enumerate(unsigned shor
/* Unable to open the device. */
//register_error(dev, "CreateFile");
goto cont_close;
}
}


/* Get the Vendor ID and Product ID for this device. */
Expand Down Expand Up @@ -449,7 +449,7 @@ struct hid_device_info HID_API_EXPORT * HID_API_CALL hid_enumerate(unsigned shor

HidD_FreePreparsedData(pp_data);
}

/* Fill out the record */
cur_dev->next = NULL;
str = device_interface_detail_data->DevicePath;
Expand Down Expand Up @@ -546,7 +546,7 @@ HID_API_EXPORT hid_device * HID_API_CALL hid_open(unsigned short vendor_id, unsi
struct hid_device_info *devs, *cur_dev;
const char *path_to_open = NULL;
hid_device *handle = NULL;

devs = hid_enumerate(vendor_id, product_id);
cur_dev = devs;
while (cur_dev) {
Expand All @@ -572,7 +572,7 @@ HID_API_EXPORT hid_device * HID_API_CALL hid_open(unsigned short vendor_id, unsi
}

hid_free_enumeration(devs);

return handle;
}

Expand Down Expand Up @@ -625,7 +625,7 @@ HID_API_EXPORT hid_device * HID_API_CALL hid_open_path(const char *path)
}
nt_res = HidP_GetCaps(pp_data, &caps);
if (nt_res != HIDP_STATUS_SUCCESS) {
register_error(dev, "HidP_GetCaps");
register_error(dev, "HidP_GetCaps");
goto err_pp_data;
}
dev->output_report_length = caps.OutputReportByteLength;
Expand All @@ -639,7 +639,7 @@ HID_API_EXPORT hid_device * HID_API_CALL hid_open_path(const char *path)

err_pp_data:
HidD_FreePreparsedData(pp_data);
err:
err:
free_hid_device(dev);
return NULL;
}
Expand Down Expand Up @@ -677,7 +677,7 @@ int HID_API_EXPORT HID_API_CALL hid_write(hid_device *dev, const unsigned char *
}

res = WriteFile(dev->device_handle, buf, (DWORD) length, NULL, &dev->write_ol);

if (!res) {
if (GetLastError() != ERROR_IO_PENDING) {
/* WriteFile() failed. Return error. */
Expand Down Expand Up @@ -730,7 +730,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);
ResetEvent(ev);
res = ReadFile(dev->device_handle, dev->read_buf, (DWORD) dev->input_report_length, &bytes_read, &dev->ol);

if (!res) {
if (GetLastError() != ERROR_IO_PENDING) {
/* ReadFile() has failed.
Expand All @@ -739,11 +739,11 @@ int HID_API_EXPORT HID_API_CALL hid_read_timeout(hid_device *dev, unsigned char
dev->read_pending = FALSE;
goto end_of_function;
}
overlapped = TRUE;
}
overlapped = TRUE;
}
}
else {
overlapped = TRUE;
overlapped = TRUE;
}

if (overlapped) {
Expand Down Expand Up @@ -781,13 +781,13 @@ int HID_API_EXPORT HID_API_CALL hid_read_timeout(hid_device *dev, unsigned char
memcpy(data, dev->read_buf, copy_len);
}
}

end_of_function:
if (!res) {
register_error(dev, "GetOverlappedResult");
return -1;
}

return (int) copy_len;
}

Expand Down Expand Up @@ -1000,7 +1000,7 @@ HID_API_EXPORT const wchar_t * HID_API_CALL hid_error(hid_device *dev)
/*#define PICPGM*/
/*#define S11*/
#define P32
#ifdef S11
#ifdef S11
unsigned short VendorID = 0xa0a0;
unsigned short ProductID = 0x0001;
#endif
Expand Down Expand Up @@ -1030,7 +1030,7 @@ int __cdecl main(int argc, char* argv[])
memset(buf,0x00,sizeof(buf));
buf[0] = 0;
buf[1] = 0x81;


/* Open the device. */
int handle = open(VendorID, ProductID, L"12345");
Expand Down

0 comments on commit 9404a95

Please sign in to comment.