Merge branch 'master' of github.com:signal11/hidapi

This commit is contained in:
Alan Ott
2010-07-05 22:50:51 -04:00
8 changed files with 118 additions and 2 deletions
+41
View File
@@ -451,6 +451,47 @@ int HID_API_EXPORT hid_set_nonblocking(int device, int nonblock)
return 0; /* Success */
}
int HID_API_EXPORT hid_send_feature_report(int device, const unsigned char *data, size_t length)
{
Device *dev = NULL;
// Get the handle
if (device < 0 || device >= MAX_DEVICES)
return -1;
if (devices[device].valid == 0)
return -1;
dev = &devices[device];
BOOL res = HidD_SetFeature(dev->device_handle, (PVOID)data, length);
if (!res) {
register_error(dev, "HidD_SetFeature");
return -1;
}
return length;
}
int HID_API_EXPORT hid_get_feature_report(int device, unsigned char *data, size_t length)
{
Device *dev = NULL;
// Get the handle
if (device < 0 || device >= MAX_DEVICES)
return -1;
if (devices[device].valid == 0)
return -1;
dev = &devices[device];
BOOL res = HidD_GetFeature(dev->device_handle, data, length);
if (!res) {
register_error(dev, "HidD_GetFeature");
return -1;
}
return 0; /* Windows doesn't give us an actual length, unfortunately */
}
void HID_API_EXPORT hid_close(int device)
{
Device *dev = NULL;
+3
View File
@@ -12,3 +12,6 @@ EXPORTS
hid_set_nonblocking @10
hid_enumerate @11
hid_open_path @12
hid_send_feature_report @13
hid_get_feature_report @14
+46 -2
View File
@@ -132,8 +132,9 @@ extern "C" {
*/
int HID_API_EXPORT HID_API_CALL hid_write(int device, const unsigned char *data, size_t length);
/** Read a report from a HID device. The first byte will contain the
Report number, if multiple reports are supported by the device.
/** Read an Input report from a HID device. Input reports are returned
to the host through the INTERRUPT IN endpoint. The first byte will
contain the Report number if the device uses numbered reports.
Params:
device: A device handle returned from hid_open().
@@ -165,6 +166,49 @@ extern "C" {
*/
int HID_API_EXPORT HID_API_CALL hid_set_nonblocking(int device, int nonblock);
/** Send a Feature report to the device. Feature reports are sent
over the Control endpoint as a Set_Report transfer. The first
byte of data[] must contain the Report ID. For devices which only
support a single report, this must be set to 0x0. The remaining
bytes contain the report data. Since the Report ID is mandatory,
calls to hid_send_feature_report() will always contain one more
byte than the report contains. For example, if a hid report is 16
bytes long, 17 bytes must be passed to hid_send_feature_report():
the Report ID (or 0x0, for devices which do not use numbered
reports), followed by the report data (16 bytes). In this example,
the length passed in would be 17.
Params:
device: A device handle returned from hid_open().
data: The data to send, including the report number as
the first byte.
length: The length in bytes of the data to send, including
the report number.
Return Value:
This function returns the actual number of bytes written and
-1 on error.
*/
int HID_API_EXPORT HID_API_CALL hid_send_feature_report(int device, const unsigned char *data, size_t length);
/** Get a feature report from a HID device. Make sure to set the
first byte of data[] to the Report ID of the report to be read.
Make sure to allow space for this extra byte in data[].
Params:
device: A device handle returned from hid_open().
data: A buffer to put the read data into, including the
Report ID. Set the first byte of data[] to the Report
ID of the report to be read.
length: The number of bytes to read, including an extra byte
for the report ID. The buffer can be longer than the
actual report.
Return Value:
This function returns 0 on success and -1 on error.
*/
int HID_API_EXPORT HID_API_CALL hid_get_feature_report(int device, unsigned char *data, size_t length);
/** Close a HID device.
Params:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+28
View File
@@ -97,6 +97,33 @@ int main(int argc, char* argv[])
// data here, but execution should not block.
res = hid_read(handle, buf, 17);
// Send a Feature Report to the device
buf[0] = 0x2;
buf[1] = 0xa0;
buf[2] = 0x0a;
buf[3] = 0x00;
buf[4] = 0x00;
res = hid_send_feature_report(handle, buf, 17);
if (res < 0) {
printf("Unable to send a feature report.\n");
}
memset(buf,0,sizeof(buf));
// Read a Feature Report from the device
buf[0] = 0x2;
res = hid_get_feature_report(handle, buf, sizeof(buf));
if (res < 0) {
printf("Unable to get a feature report.\n");
}
// Print out the returned buffer.
printf("Feature Report\n ");
for (i = 0; i < 17; i++)
printf("%02hhx ", buf[i]);
printf("\n");
// Toggle LED (cmd 0x80). The first byte is the report number (0x1).
buf[0] = 0x1;
buf[1] = 0x80;
@@ -126,6 +153,7 @@ int main(int argc, char* argv[])
printf("Unable to read()\n");
}
printf("Data read:\n ");
// Print out the returned buffer.
for (i = 0; i < res; i++)
printf("%02hhx ", buf[i]);