mirror of
https://github.com/RPCS3/hidapi.git
synced 2024-11-27 12:00:43 +00:00
Added some checking.
This commit is contained in:
parent
7222c93ef9
commit
23c43b0e84
@ -426,6 +426,15 @@ int HID_API_EXPORT hid_read(int device, unsigned char *data, size_t length)
|
||||
// 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().
|
||||
res = GetOverlappedResult(dev->device_handle, &ol, &bytes_read, TRUE/*wait*/);
|
||||
|
||||
if (bytes_read > 0 && data[0] == 0x0) {
|
||||
/* If report numbers aren't being used, but Windows sticks a report
|
||||
number (0x0) on the beginning of the report anyway. To make this
|
||||
work like the other platforms, and to make it work more like the
|
||||
HID spec, we'll skip over this byte. */
|
||||
bytes_read--;
|
||||
memmove(data, data+1, bytes_read);
|
||||
}
|
||||
|
||||
end_of_function:
|
||||
if (!res) {
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -19,7 +19,7 @@
|
||||
#include "hidapi.h"
|
||||
|
||||
// Headers needed for sleeping.
|
||||
#ifdef WIN32
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#else
|
||||
#include <unistd.h>
|
||||
@ -28,7 +28,7 @@
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
int res;
|
||||
unsigned char buf[65];
|
||||
unsigned char buf[256];
|
||||
#define MAX_STR 255
|
||||
wchar_t wstr[MAX_STR];
|
||||
int handle;
|
||||
@ -121,17 +121,18 @@ int main(int argc, char* argv[])
|
||||
res = hid_get_feature_report(handle, buf, sizeof(buf));
|
||||
if (res < 0) {
|
||||
printf("Unable to get a feature report.\n");
|
||||
printf("%s", hid_error(handle));
|
||||
}
|
||||
else {
|
||||
// Print out the returned buffer.
|
||||
printf("Feature Report\n ");
|
||||
for (i = 0; i < 17; i++)
|
||||
printf("%02hhx ", buf[i]);
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
// Print out the returned buffer.
|
||||
printf("Feature Report\n ");
|
||||
for (i = 0; i < 17; i++)
|
||||
printf("%02hhx ", buf[i]);
|
||||
printf("\n");
|
||||
|
||||
memset(buf,0,sizeof(buf));
|
||||
|
||||
|
||||
// Toggle LED (cmd 0x80). The first byte is the report number (0x1).
|
||||
buf[0] = 0x1;
|
||||
buf[1] = 0x80;
|
||||
|
Loading…
Reference in New Issue
Block a user