1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2024-11-29 07:24:13 +01:00

OP-958: Go through the list of enumerated devices, and try to open the device until end of the list.

Leave if we open one with success.
This commit is contained in:
Mathieu Rondonneau 2013-05-27 18:52:27 -07:00
parent 1e4262b309
commit 854d976a7d

View File

@ -131,8 +131,8 @@ int opHID_hidapi::open(int max, int vid, int pid, int usage_page, int usage)
{
int devices_found = false;
struct hid_device_info *current_device_ptr = NULL;
struct hid_device_info *last_device_ptr = NULL;
struct hid_device_info * *current_device_pptr = &current_device_ptr;
struct hid_device_info *tmp_device_ptr = NULL;
struct hid_device_info **current_device_pptr = &current_device_ptr;
OPHID_TRACE("IN");
@ -170,21 +170,27 @@ int opHID_hidapi::open(int max, int vid, int pid, int usage_page, int usage)
}
if (devices_found) {
// Look for the last one in the list
// WARNING: for now this prevent to have devices chained
last_device_ptr = current_device_ptr;
while (last_device_ptr->next) {
last_device_ptr = last_device_ptr->next;
// Go through the list until we can open one
// WARNING: for now this prevent to have device chained
tmp_device_ptr = current_device_ptr;
while (tmp_device_ptr) {
OPHID_DEBUG("Opening device VID(%04hx).PID(%04hx)",
tmp_device_ptr->vendor_id,
tmp_device_ptr->product_id);
handle = hid_open(tmp_device_ptr->vendor_id,
tmp_device_ptr->product_id,
NULL);
if (handle)
break;
tmp_device_ptr = tmp_device_ptr->next;
}
OPHID_DEBUG("Opening device VID(%04hx).PID(%04hx)",
last_device_ptr->vendor_id,
last_device_ptr->product_id);
handle = hid_open(last_device_ptr->vendor_id,
last_device_ptr->product_id,
NULL);
hid_free_enumeration(current_device_ptr);
if (!handle) {