diff --git a/ground/openpilotgcs/src/plugins/ophid/src/ophid_hidapi.cpp b/ground/openpilotgcs/src/plugins/ophid/src/ophid_hidapi.cpp index baacd5502..69007d804 100644 --- a/ground/openpilotgcs/src/plugins/ophid/src/ophid_hidapi.cpp +++ b/ground/openpilotgcs/src/plugins/ophid/src/ophid_hidapi.cpp @@ -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 = ¤t_device_ptr; + struct hid_device_info *tmp_device_ptr = NULL; + struct hid_device_info **current_device_pptr = ¤t_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) {