Skip to content

Commit

Permalink
HID unique ID fix for multiple devices
Browse files Browse the repository at this point in the history
* IntelRealSense#4297 Multicamera IMU data mix up
* Added Windows helper class surrounding Configuration Management nodes
* HID devices now use the unique-ID assigned to their parent node (which is the USB node)
  • Loading branch information
maloel committed Jan 23, 2020
1 parent cad1e76 commit 0ba4b1a
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 278 deletions.
2 changes: 0 additions & 2 deletions examples/sensor-control/rs-sensor-control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ int main(int argc, char * argv[]) try

//We will use the "how_to" class to make the code clear, expressive and encapsulate common actions inside a function

rs2::log_to_console( RS2_LOG_SEVERITY_DEBUG );

std::vector<sensor_action> sensor_actions = create_sensor_actions();

bool choose_a_device = true;
Expand Down
11 changes: 1 addition & 10 deletions src/mf/mf-backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,15 @@ namespace librealsense
std::vector<uvc_device_info> wmf_backend::query_uvc_devices() const
{
std::vector<uvc_device_info> devices;
LOG_DEBUG( "Looking for UVC devices ..." );

auto action = [&devices, this](const uvc_device_info& info, IMFActivate*)
{
LOG_DEBUG( "... found uid= " << info.unique_id << " " << info.device_path );
uvc_device_info device_info = info;
device_info.serial = this->get_device_serial(info.vid, info.pid, info.unique_id);
devices.push_back(device_info);
};

wmf_uvc_device::foreach_uvc_device(action);
LOG_DEBUG( "... done" );

return devices;
}
Expand Down Expand Up @@ -93,12 +90,10 @@ namespace librealsense
wmf_hid_device::wmf_hid_device(const hid_device_info& info)
{
bool found = false;
LOG_DEBUG( "Looking for HID device, uid= " << info.unique_id );

wmf_hid_device::foreach_hid_device([&](const hid_device_info& hid_dev_info, CComPtr<ISensor> sensor) {
if (hid_dev_info.unique_id == info.unique_id)
{
LOG_DEBUG( "... found uid= " << hid_dev_info.unique_id << " " << hid_dev_info.device_path );
_connected_sensors.push_back(std::make_shared<wmf_hid_sensor>(hid_dev_info, sensor));
found = true;
}
Expand All @@ -121,13 +116,10 @@ namespace librealsense

auto action = [&devices](const hid_device_info& info, CComPtr<ISensor>)
{
LOG_DEBUG( "... found uid= " << info.unique_id << " " << info.device_path );
devices.push_back(info);
};

LOG_DEBUG( "Gathering HID devices..." );
wmf_hid_device::foreach_hid_device(action);
LOG_DEBUG( "... done" );

return devices;
}
Expand Down Expand Up @@ -388,10 +380,9 @@ namespace librealsense
{
std::string device_serial = "";
std::string location = "";
std::string composite_id;
usb_spec spec = usb_undefined;

platform::get_usb_descriptors(device_vid, device_pid, device_uid, location, spec, device_serial, composite_id );
platform::get_usb_descriptors(device_vid, device_pid, device_uid, location, spec, device_serial);

return device_serial;
}
Expand Down
30 changes: 23 additions & 7 deletions src/mf/mf-hid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -428,17 +428,33 @@ namespace librealsense
info.device_path = win_to_utf( propertyValue.pwszVal );
info.id = win_to_utf( fName );

auto node = cm_node::from_device_path( propertyValue.pwszVal );
if( node.valid() )
LOG_DEBUG( " " << node.get() << " " << info.id /*node.get_id()*/
<< " parent " << node.get_parent().get()
<< " uid " << node.get_parent().get_uid() );

uint16_t vid, pid, mi;
std::string uid, guid;
if (parse_usb_path_multiple_interface(vid, pid, mi, uid, info.device_path, guid))
{
info.unique_id = get_usb_parent_uid( uid );
auto node = cm_node::from_device_path( propertyValue.pwszVal );
if( node.valid() )
{
// We take the "unique id" (really, the composite ID used to associate all the devices belonging to
// a single composite device) of the PARENT of the HID device:
// 17 USB\VID_8086&PID_0B4D\012345678901 "USB Composite Device"
// 18 USB\VID_8086&PID_0B4D&MI_00\6&CB1C340&0&0000 "Intel(R) RealSense(TM) Depth Camera 465 Depth"
// 19 USB\VID_8086&PID_0B4D&MI_03\6&CB1C340&0&0003 "Intel(R) RealSense(TM) Depth Camera 465 RGB"
// 20 USB\VID_8086&PID_0B4D&MI_05\6&CB1C340&0&0005 "USB Input Device"
// 21 HID\VID_8086&PID_0B4D&MI_05\7&24FD3503&0&0000 "HID Sensor Collection V2"
// 22 USB\VID_8086&PID_0B4D&MI_06\6&CB1C340&0&0006 "Intel(R) RealSense(TM) Depth Camera 465 "
// (the first number is the CM DEVINST handle for each node)
// Note that all the USB devices have the same "CB1C340" ID, while the HID device is "24FD3503".
// Because the HID devices are "inside" a USB device parent in the OS's CM tree, we can try to get the
// parent UID:
info.unique_id = node.get_parent().get_uid();
}
else
{
LOG_WARNING( "Parent for HID device not available: " << info.device_path );
// Leave it empty: it won't be matched against anything
}

info.pid = to_string() << std::hex << pid;
info.vid = to_string() << std::hex << vid;
}
Expand Down
4 changes: 1 addition & 3 deletions src/mf/mf-uvc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -772,8 +772,7 @@ namespace librealsense
}
try
{
std::string parent_id;
if (!get_usb_descriptors(info.vid, info.pid, info.unique_id, _location, _device_usb_spec, _device_serial, parent_id ))
if (!get_usb_descriptors(info.vid, info.pid, info.unique_id, _location, _device_usb_spec, _device_serial))
{
LOG_WARNING("Could not retrieve USB descriptor for device " << std::hex << info.vid << ":"
<< info.pid << " , id:" << info.unique_id << std::dec);
Expand All @@ -792,7 +791,6 @@ namespace librealsense
CHECK_HR(device->GetString(did_guid, const_cast<LPWSTR>(_device_id.c_str()), UINT32(_device_id.size()), nullptr));
}
});
LOG_DEBUG( "UVC dev: [id " << _device_id << " vid " << _info.vid << " pid " << _info.pid << " mi " << _info.mi << " uid " << _info.unique_id << "]" );
}
wmf_uvc_device::~wmf_uvc_device()
Expand Down
Loading

0 comments on commit 0ba4b1a

Please sign in to comment.