summaryrefslogtreecommitdiff
path: root/gr-fcd/lib/hid
diff options
context:
space:
mode:
Diffstat (limited to 'gr-fcd/lib/hid')
-rw-r--r--gr-fcd/lib/hid/Makefile.am44
-rw-r--r--gr-fcd/lib/hid/hid-libusb.c174
-rw-r--r--gr-fcd/lib/hid/hidapi.h2
-rw-r--r--gr-fcd/lib/hid/hidmac.c128
-rw-r--r--gr-fcd/lib/hid/hidwin.c40
5 files changed, 172 insertions, 216 deletions
diff --git a/gr-fcd/lib/hid/Makefile.am b/gr-fcd/lib/hid/Makefile.am
deleted file mode 100644
index 2ad4796fe..000000000
--- a/gr-fcd/lib/hid/Makefile.am
+++ /dev/null
@@ -1,44 +0,0 @@
-#
-# Copyright 2012 Free Software Foundation, Inc.
-#
-# This file is part of GNU Radio
-#
-# GNU Radio is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 3, or (at your option)
-# any later version.
-#
-# GNU Radio is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with GNU Radio; see the file COPYING. If not, write to
-# the Free Software Foundation, Inc., 51 Franklin Street,
-# Boston, MA 02110-1301, USA.
-#
-
-include $(top_srcdir)/Makefile.common
-
-AM_CPPFLAGS = \
- $(STD_DEFINES_AND_INCLUDES) \
- $(WITH_INCLUDES) \
- $(USB_CPPFLAGS)
-
-noinst_LTLIBRARIES = libhid.la
-
-libhid_la_SOURCES =
-
-if FCD_MACOSX
- libhid_la_SOURCES += hidmac.c
-else if FCD_WINDOWS
- libhid_la_SOURCES += hidwin.c
-else
- libhid_la_SOURCES += hid-libusb.c
-endif
-
-noinst_HEADERS = hidapi.h
-
-libhid_la_LIBADD = $(USB_LIBS)
-
diff --git a/gr-fcd/lib/hid/hid-libusb.c b/gr-fcd/lib/hid/hid-libusb.c
index 7069f50d0..82cbc9151 100644
--- a/gr-fcd/lib/hid/hid-libusb.c
+++ b/gr-fcd/lib/hid/hid-libusb.c
@@ -10,7 +10,7 @@
Libusb Version - 8/13/2010
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 Public License v3, a BSD-Style license, or the
@@ -77,23 +77,23 @@ struct input_report {
struct hid_device_ {
/* Handle to the actual device. */
libusb_device_handle *device_handle;
-
+
/* Endpoint information */
int input_endpoint;
int output_endpoint;
int input_ep_max_packet_size;
- /* The interface number of the HID */
+ /* The interface number of the HID */
int interface;
-
+
/* Indexes of Strings */
int manufacturer_index;
int product_index;
int serial_index;
-
+
/* Whether blocking reads are used */
int blocking; /* boolean */
-
+
/* Read thread objects */
pthread_t thread;
pthread_mutex_t mutex; /* Protects input_reports */
@@ -126,11 +126,11 @@ static hid_device *new_hid_device(void)
dev->shutdown_thread = 0;
dev->transfer = NULL;
dev->input_reports = NULL;
-
+
pthread_mutex_init(&dev->mutex, NULL);
pthread_cond_init(&dev->condition, NULL);
pthread_barrier_init(&dev->barrier, NULL, 2);
-
+
return dev;
}
@@ -191,13 +191,13 @@ static int get_usage(uint8_t *report_descriptor, size_t size,
int size_code;
int data_len, key_size;
int usage_found = 0, usage_page_found = 0;
-
+
while (i < size) {
int key = report_descriptor[i];
int key_cmd = key & 0xfc;
//printf("key: %02hhx\n", key);
-
+
if ((key & 0xf0) == 0xf0) {
/* This is a Long Item. The next byte contains the
length of the data section (value) for this key.
@@ -232,7 +232,7 @@ static int get_usage(uint8_t *report_descriptor, size_t size,
};
key_size = 1;
}
-
+
if (key_cmd == 0x4) {
*usage_page = get_bytes(report_descriptor, size, data_len, i);
usage_page_found = 1;
@@ -246,11 +246,11 @@ static int get_usage(uint8_t *report_descriptor, size_t size,
if (usage_page_found && usage_found)
return 0; /* success */
-
+
/* Skip over this key and it's associated data */
i += data_len + key_size;
}
-
+
return -1; /* failure */
}
#endif // INVASIVE_GET_USAGE
@@ -262,7 +262,7 @@ static uint16_t get_first_language(libusb_device_handle *dev)
{
uint16_t buf[32];
int len;
-
+
/* Get the string from libusb. */
len = libusb_get_string_descriptor(dev,
0x0, /* String ID */
@@ -271,7 +271,7 @@ static uint16_t get_first_language(libusb_device_handle *dev)
sizeof(buf));
if (len < 4)
return 0x0;
-
+
return buf[1]; // First two bytes are len and descriptor type.
}
@@ -280,7 +280,7 @@ static int is_language_supported(libusb_device_handle *dev, uint16_t lang)
uint16_t buf[32];
int len;
int i;
-
+
/* Get the string from libusb. */
len = libusb_get_string_descriptor(dev,
0x0, /* String ID */
@@ -289,8 +289,8 @@ static int is_language_supported(libusb_device_handle *dev, uint16_t lang)
sizeof(buf));
if (len < 4)
return 0x0;
-
-
+
+
len /= 2; /* language IDs are two-bytes each. */
/* Start at index 1 because there are two bytes of protocol data. */
for (i = 1; i < len; i++) {
@@ -325,7 +325,7 @@ static wchar_t *get_usb_string(libusb_device_handle *dev, uint8_t idx)
lang = get_usb_code_for_current_locale();
if (!is_language_supported(dev, lang))
lang = get_first_language(dev);
-
+
/* Get the string from libusb. */
len = libusb_get_string_descriptor(dev,
idx,
@@ -334,17 +334,17 @@ static wchar_t *get_usb_string(libusb_device_handle *dev, uint8_t idx)
sizeof(buf));
if (len < 0)
return NULL;
-
+
buf[sizeof(buf)-1] = '\0';
-
+
if (len+1 < sizeof(buf))
buf[len+1] = '\0';
-
+
/* Initialize iconv. */
ic = iconv_open("UTF-32", "UTF-16");
if (ic == (iconv_t)-1)
return NULL;
-
+
/* Convert to UTF-32 (wchar_t on glibc systems).
Skip the first character (2-bytes). */
inptr = buf+2;
@@ -359,13 +359,13 @@ static wchar_t *get_usb_string(libusb_device_handle *dev, uint8_t idx)
wbuf[sizeof(wbuf)/sizeof(wbuf[0])-1] = 0x00000000;
if (outbytes >= sizeof(wbuf[0]))
*((wchar_t*)outptr) = 0x00000000;
-
+
/* Allocate and copy the string. */
str = wcsdup(wbuf+1);
err:
iconv_close(ic);
-
+
return str;
}
@@ -377,7 +377,7 @@ static char *make_path(libusb_device *dev, int interface_number)
libusb_get_device_address(dev),
interface_number);
str[sizeof(str)-1] = '\0';
-
+
return strdup(str);
}
@@ -410,12 +410,12 @@ struct hid_device_info HID_API_EXPORT *hid_enumerate(unsigned short vendor_id,
libusb_device_handle *handle;
ssize_t num_devs;
int i = 0;
-
+
struct hid_device_info *root = NULL; // return object
struct hid_device_info *cur_dev = NULL;
-
+
setlocale(LC_ALL,"");
-
+
if (!initialized)
hid_init();
@@ -431,7 +431,7 @@ struct hid_device_info HID_API_EXPORT *hid_enumerate(unsigned short vendor_id,
int res = libusb_get_device_descriptor(dev, &desc);
unsigned short dev_vid = desc.idVendor;
unsigned short dev_pid = desc.idProduct;
-
+
/* HID's are defined at the interface level. */
if (desc.bDeviceClass != LIBUSB_CLASS_PER_INTERFACE)
continue;
@@ -462,11 +462,11 @@ struct hid_device_info HID_API_EXPORT *hid_enumerate(unsigned short vendor_id,
root = tmp;
}
cur_dev = tmp;
-
+
/* Fill out the record */
cur_dev->next = NULL;
cur_dev->path = make_path(dev, interface_num);
-
+
res = libusb_open(dev, &handle);
if (res >= 0) {
@@ -501,7 +501,7 @@ struct hid_device_info HID_API_EXPORT *hid_enumerate(unsigned short vendor_id,
between interfaces. */
int detached = 0;
unsigned char data[256];
-
+
/* Usage Page and Usage */
res = libusb_kernel_driver_active(handle, interface_num);
if (res == 1) {
@@ -550,7 +550,7 @@ struct hid_device_info HID_API_EXPORT *hid_enumerate(unsigned short vendor_id,
/* Release Number */
cur_dev->release_number = desc.bcdDevice;
-
+
/* Interface Number */
cur_dev->interface_number = interface_num;
}
@@ -585,7 +585,7 @@ hid_device * hid_open(unsigned short vendor_id, unsigned short product_id, wchar
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) {
@@ -611,14 +611,14 @@ hid_device * hid_open(unsigned short vendor_id, unsigned short product_id, wchar
}
hid_free_enumeration(devs);
-
+
return handle;
}
static void read_callback(struct libusb_transfer *transfer)
{
hid_device *dev = transfer->user_data;
-
+
if (transfer->status == LIBUSB_TRANSFER_COMPLETED) {
struct input_report *rpt = malloc(sizeof(*rpt));
@@ -644,13 +644,13 @@ static void read_callback(struct libusb_transfer *transfer)
num_queued++;
}
cur->next = rpt;
-
+
/* Pop one off if we've reached 30 in the queue. This
way we don't grow forever if the user never reads
anything from the device. */
if (num_queued > 30) {
return_data(dev, NULL, 0);
- }
+ }
}
pthread_mutex_unlock(&dev->mutex);
}
@@ -668,7 +668,7 @@ static void read_callback(struct libusb_transfer *transfer)
else {
LOG("Unknown transfer code: %d\n", transfer->status);
}
-
+
/* Re-submit the transfer object. */
libusb_submit_transfer(transfer);
}
@@ -691,14 +691,14 @@ static void *read_thread(void *param)
read_callback,
dev,
5000/*timeout*/);
-
+
/* Make the first submission. Further submissions are made
from inside read_callback() */
libusb_submit_transfer(dev->transfer);
// Notify the main thread that the read thread is up and running.
pthread_barrier_wait(&dev->barrier);
-
+
/* Handle all the events. */
while (!dev->shutdown_thread) {
int res;
@@ -708,14 +708,14 @@ static void *read_thread(void *param)
break;
}
}
-
+
/* Cancel any transfer that may be pending. This call will fail
if no transfers are pending, but that's OK. */
if (libusb_cancel_transfer(dev->transfer) == 0) {
/* The transfer was cancelled, so wait for its completion. */
libusb_handle_events(NULL);
}
-
+
/* Now that the read thread is stopping, Wake any threads which are
waiting on data (in hid_read_timeout()). Do this under a mutex to
make sure that a thread which is about to go to sleep waiting on
@@ -732,7 +732,7 @@ static void *read_thread(void *param)
cleaned up after the call to pthread_join() (in hid_close()), but
since hid_close() calls libusb_cancel_transfer(), on these objects,
they can not be cleaned up here. */
-
+
return NULL;
}
@@ -749,9 +749,9 @@ hid_device * HID_API_EXPORT hid_open_path(const char *path)
int res;
int d = 0;
int good_open = 0;
-
+
setlocale(LC_ALL,"");
-
+
if (!initialized)
hid_init();
@@ -782,7 +782,7 @@ hid_device * HID_API_EXPORT hid_open_path(const char *path)
break;
}
good_open = 1;
-
+
/* Detach the kernel driver, but only if the
device is managed by the kernel */
if (libusb_kernel_driver_active(dev->device_handle, intf_desc->bInterfaceNumber) == 1) {
@@ -795,7 +795,7 @@ hid_device * HID_API_EXPORT hid_open_path(const char *path)
break;
}
}
-
+
res = libusb_claim_interface(dev->device_handle, intf_desc->bInterfaceNumber);
if (res < 0) {
LOG("can't claim interface %d: %d\n", intf_desc->bInterfaceNumber, res);
@@ -812,7 +812,7 @@ hid_device * HID_API_EXPORT hid_open_path(const char *path)
/* Store off the interface number */
dev->interface = intf_desc->bInterfaceNumber;
-
+
/* Find the INPUT and OUTPUT endpoints. An
OUTPUT endpoint is not required. */
for (i = 0; i < intf_desc->bNumEndpoints; i++) {
@@ -824,10 +824,10 @@ hid_device * HID_API_EXPORT hid_open_path(const char *path)
int is_interrupt =
(ep->bmAttributes & LIBUSB_TRANSFER_TYPE_MASK)
== LIBUSB_TRANSFER_TYPE_INTERRUPT;
- int is_output =
+ int is_output =
(ep->bEndpointAddress & LIBUSB_ENDPOINT_DIR_MASK)
== LIBUSB_ENDPOINT_OUT;
- int is_input =
+ int is_input =
(ep->bEndpointAddress & LIBUSB_ENDPOINT_DIR_MASK)
== LIBUSB_ENDPOINT_IN;
@@ -844,12 +844,12 @@ hid_device * HID_API_EXPORT hid_open_path(const char *path)
dev->output_endpoint = ep->bEndpointAddress;
}
}
-
+
pthread_create(&dev->thread, NULL, read_thread, dev);
-
+
// Wait here for the read thread to be initialized.
pthread_barrier_wait(&dev->barrier);
-
+
}
free(dev_path);
}
@@ -860,7 +860,7 @@ hid_device * HID_API_EXPORT hid_open_path(const char *path)
}
libusb_free_device_list(devs, 1);
-
+
// If we have a good handle, return it.
if (good_open) {
return dev;
@@ -895,13 +895,13 @@ int HID_API_EXPORT hid_write(hid_device *dev, const unsigned char *data, size_t
dev->interface,
(unsigned char *)data, length,
1000/*timeout millis*/);
-
+
if (res < 0)
return -1;
-
+
if (skipped_report_id)
length++;
-
+
return length;
}
else {
@@ -912,13 +912,13 @@ int HID_API_EXPORT hid_write(hid_device *dev, const unsigned char *data, size_t
(unsigned char*)data,
length,
&actual_length, 1000);
-
+
if (res < 0)
return -1;
-
+
if (skipped_report_id)
actual_length++;
-
+
return actual_length;
}
}
@@ -966,14 +966,14 @@ int HID_API_EXPORT hid_read_timeout(hid_device *dev, unsigned char *data, size_t
bytes_read = return_data(dev, data, length);
goto ret;
}
-
+
if (dev->shutdown_thread) {
/* This means the device has been disconnected.
An error code of -1 should be returned. */
bytes_read = -1;
goto ret;
}
-
+
if (milliseconds == -1) {
/* Blocking */
while (!dev->input_reports && !dev->shutdown_thread) {
@@ -994,7 +994,7 @@ int HID_API_EXPORT hid_read_timeout(hid_device *dev, unsigned char *data, size_t
ts.tv_sec++;
ts.tv_nsec -= 1000000000L;
}
-
+
while (!dev->input_reports && !dev->shutdown_thread) {
res = pthread_cond_timedwait(&dev->condition, &dev->mutex, &ts);
if (res == 0) {
@@ -1002,7 +1002,7 @@ int HID_API_EXPORT hid_read_timeout(hid_device *dev, unsigned char *data, size_t
bytes_read = return_data(dev, data, length);
break;
}
-
+
/* If we're here, there was a spurious wake up
or the read thread was shutdown. Run the
loop again (ie: don't break). */
@@ -1039,7 +1039,7 @@ int HID_API_EXPORT hid_read(hid_device *dev, unsigned char *data, size_t length)
int HID_API_EXPORT hid_set_nonblocking(hid_device *dev, int nonblock)
{
dev->blocking = !nonblock;
-
+
return 0;
}
@@ -1063,14 +1063,14 @@ int HID_API_EXPORT hid_send_feature_report(hid_device *dev, const unsigned char
dev->interface,
(unsigned char *)data, length,
1000/*timeout millis*/);
-
+
if (res < 0)
return -1;
-
+
/* Account for the report ID */
if (skipped_report_id)
length++;
-
+
return length;
}
@@ -1094,13 +1094,13 @@ int HID_API_EXPORT hid_get_feature_report(hid_device *dev, unsigned char *data,
dev->interface,
(unsigned char *)data, length,
1000/*timeout millis*/);
-
+
if (res < 0)
return -1;
if (skipped_report_id)
res++;
-
+
return res;
}
@@ -1109,31 +1109,31 @@ void HID_API_EXPORT hid_close(hid_device *dev)
{
if (!dev)
return;
-
+
/* Cause read_thread() to stop. */
dev->shutdown_thread = 1;
libusb_cancel_transfer(dev->transfer);
/* Wait for read_thread() to end. */
pthread_join(dev->thread, NULL);
-
+
/* Clean up the Transfer objects allocated in read_thread(). */
free(dev->transfer->buffer);
libusb_free_transfer(dev->transfer);
-
+
/* release the interface */
libusb_release_interface(dev->device_handle, dev->interface);
-
+
/* Close the handle */
libusb_close(dev->device_handle);
-
+
/* Clear out the queue of received reports. */
pthread_mutex_lock(&dev->mutex);
while (dev->input_reports) {
return_data(dev, NULL, 0);
}
pthread_mutex_unlock(&dev->mutex);
-
+
free_hid_device(dev);
}
@@ -1316,7 +1316,7 @@ static struct lang_map_entry lang_map[] = {
LANG("Xhosa", "xh", 0x0434),
LANG("Yiddish", "yi", 0x043D),
LANG("Zulu", "zu", 0x0435),
- LANG(NULL, NULL, 0x0),
+ LANG(NULL, NULL, 0x0),
};
uint16_t get_usb_code_for_current_locale(void)
@@ -1324,16 +1324,16 @@ uint16_t get_usb_code_for_current_locale(void)
char *locale;
char search_string[64];
char *ptr;
-
+
/* Get the current locale. */
locale = setlocale(0, NULL);
if (!locale)
return 0x0;
-
+
/* Make a copy of the current locale string. */
strncpy(search_string, locale, sizeof(search_string));
search_string[sizeof(search_string)-1] = '\0';
-
+
/* Chop off the encoding part, and make it lower case. */
ptr = search_string;
while (*ptr) {
@@ -1350,10 +1350,10 @@ uint16_t get_usb_code_for_current_locale(void)
while (lang->string_code) {
if (!strcmp(lang->string_code, search_string)) {
return lang->usb_code;
- }
+ }
lang++;
}
-
+
/* There was no match. Find with just the language only. */
/* Chop off the variant. Chop it off at the '_'. */
ptr = search_string;
@@ -1365,18 +1365,18 @@ uint16_t get_usb_code_for_current_locale(void)
}
ptr++;
}
-
+
#if 0 // TODO: Do we need this?
/* Find the entry which matches the string code of our language. */
lang = lang_map;
while (lang->string_code) {
if (!strcmp(lang->string_code, search_string)) {
return lang->usb_code;
- }
+ }
lang++;
}
#endif
-
+
/* Found nothing. */
return 0x0;
}
diff --git a/gr-fcd/lib/hid/hidapi.h b/gr-fcd/lib/hid/hidapi.h
index 31b1cf206..8e55c8474 100644
--- a/gr-fcd/lib/hid/hidapi.h
+++ b/gr-fcd/lib/hid/hidapi.h
@@ -87,7 +87,7 @@ extern "C" {
needed. This function should be called at the beginning of
execution however, if there is a chance of HIDAPI handles
being opened by different threads simultaneously.
-
+
@ingroup API
@returns
diff --git a/gr-fcd/lib/hid/hidmac.c b/gr-fcd/lib/hid/hidmac.c
index 276541be1..d8c69a8e5 100644
--- a/gr-fcd/lib/hid/hidmac.c
+++ b/gr-fcd/lib/hid/hidmac.c
@@ -1,14 +1,14 @@
/*******************************************************
HIDAPI - Multi-Platform library for
communication with HID devices.
-
+
Alan Ott
Signal 11 Software
2010-07-03
Copyright 2010, All Rights Reserved.
-
+
At the discretion of the user of this library,
this software may be licensed under the terms of the
GNU Public License v3, a BSD-Style license, or the
@@ -51,7 +51,7 @@ static int pthread_barrier_init(pthread_barrier_t *barrier, const pthread_barrie
errno = EINVAL;
return -1;
}
-
+
if(pthread_mutex_init(&barrier->mutex, 0) < 0) {
return -1;
}
@@ -118,7 +118,7 @@ struct hid_device_ {
pthread_barrier_t barrier; /* Ensures correct startup sequence */
pthread_barrier_t shutdown_barrier; /* Ensures correct shutdown sequence */
int shutdown_thread;
-
+
hid_device *next;
};
@@ -148,7 +148,7 @@ static hid_device *new_hid_device(void)
pthread_cond_init(&dev->condition, NULL);
pthread_barrier_init(&dev->barrier, NULL, 2);
pthread_barrier_init(&dev->shutdown_barrier, NULL, 2);
-
+
/* Add the new record to the device_list. */
pthread_mutex_lock(&device_list_mutex);
if (!device_list)
@@ -164,7 +164,7 @@ static hid_device *new_hid_device(void)
}
}
pthread_mutex_unlock(&device_list_mutex);
-
+
return dev;
}
@@ -172,7 +172,7 @@ static void free_hid_device(hid_device *dev)
{
if (!dev)
return;
-
+
/* Delete any input reports still left over. */
struct input_report *rpt = dev->input_reports;
while (rpt) {
@@ -209,7 +209,7 @@ static void free_hid_device(hid_device *dev)
d->next = d->next->next;
break;
}
-
+
d = d->next;
}
}
@@ -234,7 +234,7 @@ static int32_t get_int_property(IOHIDDeviceRef device, CFStringRef key)
{
CFTypeRef ref;
int32_t value;
-
+
ref = IOHIDDeviceGetProperty(device, key);
if (ref) {
if (CFGetTypeID(ref) == CFNumberGetTypeID()) {
@@ -285,7 +285,7 @@ static int get_string_property(IOHIDDeviceRef device, CFStringRef prop, wchar_t
}
else
return 0;
-
+
}
static int get_string_property_utf8(IOHIDDeviceRef device, CFStringRef prop, char *buf, size_t len)
@@ -312,7 +312,7 @@ static int get_string_property_utf8(IOHIDDeviceRef device, CFStringRef prop, cha
}
else
return 0;
-
+
}
@@ -354,7 +354,7 @@ static int make_path(IOHIDDeviceRef device, char *buf, size_t len)
res = get_string_property_utf8(
device, CFSTR(kIOHIDTransportKey),
transport, sizeof(transport));
-
+
if (!res)
return -1;
@@ -363,8 +363,8 @@ static int make_path(IOHIDDeviceRef device, char *buf, size_t len)
res = snprintf(buf, len, "%s_%04hx_%04hx_%p",
transport, vid, pid, device);
-
-
+
+
buf[len-1] = '\0';
return res+1;
}
@@ -372,7 +372,7 @@ static int make_path(IOHIDDeviceRef device, char *buf, size_t len)
static int init_hid_manager(void)
{
IOReturn res;
-
+
/* Initialize all the HID Manager Objects */
hid_mgr = IOHIDManagerCreate(kCFAllocatorDefault, kIOHIDOptionsTypeNone);
IOHIDManagerSetDeviceMatching(hid_mgr, NULL);
@@ -400,7 +400,7 @@ int HID_API_EXPORT hid_exit(void)
CFRelease(hid_mgr);
hid_mgr = NULL;
}
-
+
return 0;
}
@@ -410,21 +410,21 @@ struct hid_device_info HID_API_EXPORT *hid_enumerate(unsigned short vendor_id,
struct hid_device_info *cur_dev = NULL;
CFIndex num_devices;
int i;
-
+
setlocale(LC_ALL,"");
/* Set up the HID Manager if it hasn't been done */
hid_init();
-
+
/* Get a list of the Devices */
CFSetRef device_set = IOHIDManagerCopyDevices(hid_mgr);
- /* Convert the list into a C array so we can iterate easily. */
+ /* Convert the list into a C array so we can iterate easily. */
num_devices = CFSetGetCount(device_set);
IOHIDDeviceRef *device_array = calloc(num_devices, sizeof(IOHIDDeviceRef));
CFSetGetValues(device_set, (const void **) device_array);
- /* Iterate over each device, making an entry for it. */
+ /* Iterate over each device, making an entry for it. */
for (i = 0; i < num_devices; i++) {
unsigned short dev_vid;
unsigned short dev_pid;
@@ -474,7 +474,7 @@ struct hid_device_info HID_API_EXPORT *hid_enumerate(unsigned short vendor_id,
cur_dev->manufacturer_string = dup_wcs(buf);
get_product_string(dev, buf, BUF_LEN);
cur_dev->product_string = dup_wcs(buf);
-
+
/* VID/PID */
cur_dev->vendor_id = dev_vid;
cur_dev->product_id = dev_pid;
@@ -486,10 +486,10 @@ struct hid_device_info HID_API_EXPORT *hid_enumerate(unsigned short vendor_id,
cur_dev->interface_number = -1;
}
}
-
+
free(device_array);
CFRelease(device_set);
-
+
return root;
}
@@ -514,7 +514,7 @@ hid_device * HID_API_EXPORT hid_open(unsigned short vendor_id, unsigned short pr
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) {
@@ -540,7 +540,7 @@ hid_device * HID_API_EXPORT hid_open(unsigned short vendor_id, unsigned short pr
}
hid_free_enumeration(devs);
-
+
return handle;
}
@@ -555,7 +555,7 @@ static void hid_device_removal_callback(void *context, IOReturn result,
d->disconnected = 1;
CFRunLoopStop(d->run_loop);
}
-
+
d = d->next;
}
pthread_mutex_unlock(&device_list_mutex);
@@ -580,7 +580,7 @@ static void hid_report_callback(void *context, IOReturn result, void *sender,
/* Lock this section */
pthread_mutex_lock(&dev->mutex);
-
+
/* Attach the new report object to the end of the list. */
if (dev->input_reports == NULL) {
/* The list is empty. Put it at the root. */
@@ -623,7 +623,7 @@ static void perform_signal_callback(void *context)
static void *read_thread(void *param)
{
hid_device *dev = param;
-
+
/* Move the device's run loop to this thread. */
IOHIDDeviceScheduleWithRunLoop(dev->device_handle, CFRunLoopGetCurrent(), dev->run_loop_mode);
@@ -636,7 +636,7 @@ static void *read_thread(void *param)
ctx.perform = &perform_signal_callback;
dev->source = CFRunLoopSourceCreate(kCFAllocatorDefault, 0/*order*/, &ctx);
CFRunLoopAddSource(CFRunLoopGetCurrent(), dev->source, dev->run_loop_mode);
-
+
/* Store off the Run Loop so it can be stopped from hid_close()
and on device disconnection. */
dev->run_loop = CFRunLoopGetCurrent();
@@ -682,7 +682,7 @@ static void *read_thread(void *param)
if (!dev->disconnected) {
IOHIDDeviceClose(dev->device_handle, kIOHIDOptionsTypeNone);
}
-
+
/* Wait here until hid_close() is called and makes it past
the call to CFRunLoopWakeUp(). This thread still needs to
be valid when that function is called on the other thread. */
@@ -696,22 +696,22 @@ hid_device * HID_API_EXPORT hid_open_path(const char *path)
int i;
hid_device *dev = NULL;
CFIndex num_devices;
-
+
dev = new_hid_device();
/* Set up the HID Manager if it hasn't been done */
hid_init();
CFSetRef device_set = IOHIDManagerCopyDevices(hid_mgr);
-
+
num_devices = CFSetGetCount(device_set);
IOHIDDeviceRef *device_array = calloc(num_devices, sizeof(IOHIDDeviceRef));
- CFSetGetValues(device_set, (const void **) device_array);
+ CFSetGetValues(device_set, (const void **) device_array);
for (i = 0; i < num_devices; i++) {
char cbuf[BUF_LEN];
size_t len;
IOHIDDeviceRef os_dev = device_array[i];
-
+
len = make_path(os_dev, cbuf, sizeof(cbuf));
if (!strcmp(cbuf, path)) {
// Matched Paths. Open this Device.
@@ -722,29 +722,29 @@ hid_device * HID_API_EXPORT hid_open_path(const char *path)
free(device_array);
CFRelease(device_set);
dev->device_handle = os_dev;
-
+
/* Create the buffers for receiving data */
dev->max_input_report_len = (CFIndex) get_max_report_length(os_dev);
dev->input_report_buf = calloc(dev->max_input_report_len, sizeof(uint8_t));
-
+
/* Create the Run Loop Mode for this device.
printing the reference seems to work. */
sprintf(str, "HIDAPI_%p", os_dev);
- dev->run_loop_mode =
+ dev->run_loop_mode =
CFStringCreateWithCString(NULL, str, kCFStringEncodingASCII);
-
+
/* Attach the device to a Run Loop */
IOHIDDeviceRegisterInputReportCallback(
os_dev, dev->input_report_buf, dev->max_input_report_len,
&hid_report_callback, dev);
IOHIDManagerRegisterDeviceRemovalCallback(hid_mgr, hid_device_removal_callback, NULL);
-
+
/* Start the read thread */
pthread_create(&dev->thread, NULL, read_thread, dev);
/* Wait here for the read thread to be initialized. */
pthread_barrier_wait(&dev->barrier);
-
+
return dev;
}
else {
@@ -782,20 +782,20 @@ static int set_report(hid_device *dev, IOHIDReportType type, const unsigned char
data_to_send = data;
length_to_send = length;
}
-
+
if (!dev->disconnected) {
res = IOHIDDeviceSetReport(dev->device_handle,
type,
data[0], /* Report ID*/
data_to_send, length_to_send);
-
+
if (res == kIOReturnSuccess) {
return length;
}
else
return -1;
}
-
+
return -1;
}
@@ -830,11 +830,11 @@ static int cond_wait(const hid_device *dev, pthread_cond_t *cond, pthread_mutex_
data in the queue before returning, and if not, go back
to sleep. See the pthread_cond_timedwait() man page for
details. */
-
+
if (dev->shutdown_thread || dev->disconnected)
return -1;
}
-
+
return 0;
}
@@ -850,11 +850,11 @@ static int cond_timedwait(const hid_device *dev, pthread_cond_t *cond, pthread_m
data in the queue before returning, and if not, go back
to sleep. See the pthread_cond_timedwait() man page for
details. */
-
+
if (dev->shutdown_thread || dev->disconnected)
return -1;
}
-
+
return 0;
}
@@ -865,7 +865,7 @@ int HID_API_EXPORT hid_read_timeout(hid_device *dev, unsigned char *data, size_t
/* Lock the access to the report list. */
pthread_mutex_lock(&dev->mutex);
-
+
/* There's an input report queued up. Return it. */
if (dev->input_reports) {
/* Return the first one */
@@ -878,7 +878,7 @@ int HID_API_EXPORT hid_read_timeout(hid_device *dev, unsigned char *data, size_t
bytes_read = -1;
goto ret;
}
-
+
if (dev->shutdown_thread) {
/* This means the device has been closed (or there
has been an error. An error code of -1 should
@@ -888,7 +888,7 @@ int HID_API_EXPORT hid_read_timeout(hid_device *dev, unsigned char *data, size_t
}
/* There is no data. Go to sleep and wait for data. */
-
+
if (milliseconds == -1) {
/* Blocking */
int res;
@@ -913,7 +913,7 @@ int HID_API_EXPORT hid_read_timeout(hid_device *dev, unsigned char *data, size_t
ts.tv_sec++;
ts.tv_nsec -= 1000000000L;
}
-
+
res = cond_timedwait(dev, &dev->condition, &dev->mutex, &ts);
if (res == 0)
bytes_read = return_data(dev, data, length);
@@ -942,7 +942,7 @@ int HID_API_EXPORT hid_set_nonblocking(hid_device *dev, int nonblock)
{
/* All Nonblocking operation is handled by the library. */
dev->blocking = !nonblock;
-
+
return 0;
}
@@ -985,14 +985,14 @@ void HID_API_EXPORT hid_close(hid_device *dev)
IOHIDDeviceUnscheduleFromRunLoop(dev->device_handle, dev->run_loop, dev->run_loop_mode);
IOHIDDeviceScheduleWithRunLoop(dev->device_handle, CFRunLoopGetMain(), kCFRunLoopDefaultMode);
}
-
+
/* Cause read_thread() to stop. */
dev->shutdown_thread = 1;
-
+
/* Wake up the run thread's event loop so that the thread can exit. */
CFRunLoopSourceSignal(dev->source);
CFRunLoopWakeUp(dev->run_loop);
-
+
/* Notify the read thread that it can shut down now. */
pthread_barrier_wait(&dev->shutdown_barrier);
@@ -1005,7 +1005,7 @@ void HID_API_EXPORT hid_close(hid_device *dev)
if (!dev->disconnected) {
IOHIDDeviceClose(dev->device_handle, kIOHIDOptionsTypeNone);
}
-
+
/* Clear out the queue of received reports. */
pthread_mutex_lock(&dev->mutex);
while (dev->input_reports) {
@@ -1085,19 +1085,19 @@ int main(void)
{
IOHIDManagerRef mgr;
int i;
-
+
mgr = IOHIDManagerCreate(kCFAllocatorDefault, kIOHIDOptionsTypeNone);
IOHIDManagerSetDeviceMatching(mgr, NULL);
IOHIDManagerOpen(mgr, kIOHIDOptionsTypeNone);
-
+
CFSetRef device_set = IOHIDManagerCopyDevices(mgr);
-
+
CFIndex num_devices = CFSetGetCount(device_set);
IOHIDDeviceRef *device_array = calloc(num_devices, sizeof(IOHIDDeviceRef));
CFSetGetValues(device_set, (const void **) device_array);
-
+
setlocale(LC_ALL, "");
-
+
for (i = 0; i < num_devices; i++) {
IOHIDDeviceRef dev = device_array[i];
printf("Device: %p\n", dev);
@@ -1107,16 +1107,16 @@ int main(void)
char cbuf[256];
get_serial_number(dev, serial, 256);
-
+
printf(" Serial: %ls\n", serial);
printf(" Loc: %ld\n", get_location_id(dev));
get_transport(dev, buf, 256);
printf(" Trans: %ls\n", buf);
make_path(dev, cbuf, 256);
printf(" Path: %s\n", cbuf);
-
+
}
-
+
return 0;
}
#endif
diff --git a/gr-fcd/lib/hid/hidwin.c b/gr-fcd/lib/hid/hidwin.c
index 26d870fd8..5d34aadf4 100644
--- a/gr-fcd/lib/hid/hidwin.c
+++ b/gr-fcd/lib/hid/hidwin.c
@@ -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 Public License v3, a BSD-Style license, or the
@@ -162,7 +162,7 @@ static void register_error(hid_device *device, 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;
@@ -174,7 +174,7 @@ static void register_error(hid_device *device, const char *op)
ptr++;
}
- // Store the message off in the Device entry so that
+ // Store the message off in the Device entry so that
// the hid_error() function can pick it up.
LocalFree(device->last_error_str);
device->last_error_str = msg;
@@ -284,9 +284,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;
@@ -297,7 +297,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.
@@ -344,7 +344,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.
@@ -354,7 +354,7 @@ struct hid_device_info HID_API_EXPORT * HID_API_CALL hid_enumerate(unsigned shor
// Check the VID/PID to see if we should add this
// device to the enumeration list.
- if ((vendor_id == 0x0 && product_id == 0x0) ||
+ if ((vendor_id == 0x0 && product_id == 0x0) ||
(attrib.VendorID == vendor_id && attrib.ProductID == product_id)) {
#define WSTR_LEN 512
@@ -388,7 +388,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;
@@ -488,7 +488,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) {
@@ -514,7 +514,7 @@ HID_API_EXPORT hid_device * HID_API_CALL hid_open(unsigned short vendor_id, unsi
}
hid_free_enumeration(devs);
-
+
return handle;
}
@@ -550,7 +550,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->input_report_length = caps.InputReportByteLength;
@@ -562,7 +562,7 @@ HID_API_EXPORT hid_device * HID_API_CALL hid_open_path(const char *path)
err_pp_data:
HidD_FreePreparsedData(pp_data);
-err:
+err:
CloseHandle(dev->device_handle);
free(dev);
return NULL;
@@ -577,7 +577,7 @@ int HID_API_EXPORT HID_API_CALL hid_write(hid_device *dev, const unsigned char *
memset(&ol, 0, sizeof(ol));
res = WriteFile(dev->device_handle, data, length, NULL, &ol);
-
+
if (!res) {
if (GetLastError() != ERROR_IO_PENDING) {
// WriteFile() failed. Return error.
@@ -612,7 +612,7 @@ int HID_API_EXPORT HID_API_CALL hid_read_timeout(hid_device *dev, unsigned char
dev->read_pending = TRUE;
ResetEvent(ev);
res = ReadFile(dev->device_handle, dev->read_buf, dev->input_report_length, &bytes_read, &dev->ol);
-
+
if (!res) {
if (GetLastError() != ERROR_IO_PENDING) {
// ReadFile() has failed.
@@ -638,7 +638,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
// data has been copied to the data[] array which was passed to ReadFile().
res = GetOverlappedResult(dev->device_handle, &dev->ol, &bytes_read, TRUE/*wait*/);
-
+
// Set pending back to false, even if GetOverlappedResult() returned error.
dev->read_pending = FALSE;
@@ -656,13 +656,13 @@ int HID_API_EXPORT HID_API_CALL hid_read_timeout(hid_device *dev, unsigned char
memcpy(data, dev->read_buf, length);
}
}
-
+
end_of_function:
if (!res) {
register_error(dev, "GetOverlappedResult");
return -1;
}
-
+
return bytes_read;
}
@@ -805,7 +805,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
@@ -835,7 +835,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");