Skip to content

Commit

Permalink
initial hid fix
Browse files Browse the repository at this point in the history
  • Loading branch information
maloel committed Feb 3, 2020
1 parent 7286285 commit 908232d
Show file tree
Hide file tree
Showing 7 changed files with 601 additions and 169 deletions.
2 changes: 2 additions & 0 deletions examples/sensor-control/rs-sensor-control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ 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
5 changes: 2 additions & 3 deletions src/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -488,13 +488,12 @@ namespace librealsense

for (auto&& hid : hids)
{
if (hid.unique_id != "")
if( ! hid.unique_id.empty() )
{
std::stringstream(hid.vid) >> std::hex >> vid;
std::stringstream(hid.pid) >> std::hex >> pid;

if ((hid.unique_id == unique_id) || // Linux check
((hid.unique_id == "*") && (hid.serial_number == device_serial))) // Windows check
if (hid.unique_id == unique_id)
{
hid_group.push_back(hid);
}
Expand Down
11 changes: 10 additions & 1 deletion src/mf/mf-backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,18 @@ 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 @@ -90,10 +93,12 @@ 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 @@ -116,10 +121,13 @@ 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 @@ -380,9 +388,10 @@ 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);
platform::get_usb_descriptors(device_vid, device_pid, device_uid, location, spec, device_serial, composite_id );

return device_serial;
}
Expand Down
17 changes: 12 additions & 5 deletions src/mf/mf-hid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,8 @@ namespace librealsense
/* Retrieve SENSOR_PROPERTY_FRIENDLY_NAME which is the sensor name that is intended to be seen by the user */
BSTR fName{};
LOG_HR(res = pSensor->GetFriendlyName(&fName));
if (FAILED(res)) fName= L"Unidentified HID sensor";
if (FAILED(res))
fName= L"Unidentified HID sensor";

/* Retrieve SENSOR_PROPERTY_PERSISTENT_UNIQUE_ID which is a GUID that uniquely identifies the sensor on the current computer */
SENSOR_ID id{};
Expand Down Expand Up @@ -424,21 +425,27 @@ namespace librealsense
{
if (IsEqualPropertyKey(propertyKey, SENSOR_PROPERTY_DEVICE_PATH))
{
info.device_path = std::string(propertyValue.pwszVal, propertyValue.pwszVal + wcslen(propertyValue.pwszVal));
info.id = std::string(fName, fName + wcslen(fName));
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 = "*";
info.unique_id = get_usb_parent_uid( uid );
info.pid = to_string() << std::hex << pid;
info.vid = to_string() << std::hex << vid;
}
}
if (IsEqualPropertyKey(propertyKey, SENSOR_PROPERTY_SERIAL_NUMBER))
{
auto str = std::string(propertyValue.pwszVal, propertyValue.pwszVal + wcslen(propertyValue.pwszVal));
auto str = win_to_utf( propertyValue.pwszVal );
std::transform(begin(str), end(str), begin(str), ::tolower);
info.serial_number = str;
}
Expand Down
4 changes: 3 additions & 1 deletion src/mf/mf-uvc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -772,7 +772,8 @@ namespace librealsense
}
try
{
if (!get_usb_descriptors(info.vid, info.pid, info.unique_id, _location, _device_usb_spec, _device_serial))
std::string parent_id;
if (!get_usb_descriptors(info.vid, info.pid, info.unique_id, _location, _device_usb_spec, _device_serial, parent_id ))
{
LOG_WARNING("Could not retrieve USB descriptor for device " << std::hex << info.vid << ":"
<< info.pid << " , id:" << info.unique_id << std::dec);
Expand All @@ -791,6 +792,7 @@ 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 908232d

Please sign in to comment.