-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
rs usb api and implementations added #3828
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,8 @@ | |
#include "android-uvc.h" | ||
#include "android-hid.h" | ||
#include "../types.h" | ||
#include "usb_host/device_watcher.h" | ||
#include "device_watcher.h" | ||
#include "../usb/usb-enumerator.h" | ||
#include <chrono> | ||
#include <cctype> // std::tolower | ||
|
||
|
@@ -38,18 +39,29 @@ namespace librealsense { | |
} | ||
|
||
std::vector<uvc_device_info> android_backend::query_uvc_devices() const { | ||
return usb_host::device_watcher::query_uvc_devices(); | ||
return device_watcher_usbhost::instance()->query_uvc_devices(); | ||
} | ||
|
||
std::shared_ptr<usb_device> android_backend::create_usb_device(usb_device_info info) const { | ||
throw std::runtime_error("create_usb_device Not supported"); | ||
std::shared_ptr<command_transfer> android_backend::create_usb_device(usb_device_info info) const { | ||
auto devices = usb_enumerator::query_devices(); | ||
for(auto&& dev : devices){ | ||
auto curr = dev->get_info(); | ||
if(info.id == curr.id) | ||
return std::make_shared<platform::command_transfer_usb>(dev); | ||
} | ||
return nullptr; | ||
} | ||
|
||
std::vector<usb_device_info> android_backend::query_usb_devices() const { | ||
std::vector<usb_device_info> results; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pls change the name to |
||
auto devices = usb_enumerator::query_devices(); | ||
|
||
std::vector<usb_device_info> result; | ||
// Not supported | ||
return result; | ||
for(auto&& dev : devices) | ||
{ | ||
auto infos = dev->get_subdevices_infos(); | ||
results.insert(results.end(), infos.begin(), infos.end()); | ||
} | ||
return results; | ||
} | ||
|
||
std::shared_ptr<hid_device> android_backend::create_hid_device(hid_device_info info) const { | ||
|
@@ -68,7 +80,7 @@ namespace librealsense { | |
|
||
|
||
std::shared_ptr<device_watcher> android_backend::create_device_watcher() const { | ||
return std::make_shared<usb_host::device_watcher>(); | ||
return device_watcher_usbhost::instance(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There should be no need to wrap a singleton with shared_ptr. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I need to implement the backend API: |
||
} | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ | |
#include "android-uvc.h" | ||
#include "../types.h" | ||
#include "libuvc/utlist.h" | ||
#include "usb_host/device_watcher.h" | ||
#include "../usb/usb-enumerator.h" | ||
#include "../libuvc/utlist.h" | ||
|
||
|
||
|
@@ -19,6 +19,7 @@ | |
|
||
namespace librealsense { | ||
namespace platform { | ||
|
||
bool android_uvc_device::is_connected(const uvc_device_info &info) { | ||
auto result = true; | ||
|
||
|
@@ -308,53 +309,54 @@ namespace librealsense { | |
return result; | ||
} | ||
|
||
void android_uvc_device::set_power_state(power_state state) { | ||
std::lock_guard<std::mutex> lock(_power_mutex); | ||
|
||
if (state == D0 && _power_state == D3) { | ||
uint16_t vid = _info.vid, pid = _info.pid, mi = _info.mi; | ||
|
||
std::vector<std::shared_ptr<usbhost_uvc_device>> uvc_devices; | ||
for(auto&& dev : usb_host::device_watcher::get_device_list()) | ||
std::shared_ptr<usbhost_uvc_device> android_uvc_device::open_uvc_device(uint16_t mi) | ||
{ | ||
for(auto&& dev : usb_enumerator::query_devices()) | ||
{ | ||
for(auto&& in : dev->get_interfaces(USB_SUBCLASS_CONTROL)) | ||
{ | ||
if(in->get_number() != mi) | ||
continue; | ||
std::shared_ptr<usbhost_uvc_device> uvc(new usbhost_uvc_device(), | ||
[](usbhost_uvc_device *ptr) {usbhost_close(ptr); }); | ||
uvc->device = dev; | ||
uvc->vid = dev->get_vid(); | ||
uvc->pid = dev->get_pid(); | ||
uvc_devices.push_back(uvc); | ||
uvc->device = std::static_pointer_cast<usb_device_usbhost>(dev); | ||
uvc->vid = dev->get_info().vid; | ||
uvc->pid = dev->get_info().pid; | ||
usbhost_open(uvc.get(), mi); | ||
return uvc; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This function will open the first device with matched MI. How can one query the 2nd or 3rd device ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
} | ||
} | ||
return nullptr; | ||
} | ||
|
||
for (auto device : uvc_devices) { | ||
|
||
usbhost_open(device.get(), mi); | ||
void android_uvc_device::set_power_state(power_state state) { | ||
std::lock_guard<std::mutex> lock(_power_mutex); | ||
|
||
if (device->deviceData.ctrl_if.bInterfaceNumber == mi) { | ||
_device = device; | ||
if (state == D0 && _power_state == D3) { | ||
uint16_t vid = _info.vid, pid = _info.pid, mi = _info.mi; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. vid/pid seem unused in this segment - pls recheck There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. will remove |
||
|
||
for (auto ct = _device->deviceData.ctrl_if.input_term_descs; | ||
ct; ct = ct->next) { | ||
_input_terminal = ct->bTerminalID; | ||
} | ||
_device = open_uvc_device(mi); | ||
|
||
for (auto pu = _device->deviceData.ctrl_if.processing_unit_descs; | ||
pu; pu = pu->next) { | ||
_processing_unit = pu->bUnitID; | ||
} | ||
if(!_device) | ||
throw std::runtime_error("Device not found!"); | ||
|
||
for (auto eu = _device->deviceData.ctrl_if.extension_unit_descs; | ||
eu; eu = eu->next) { | ||
_extension_unit = eu->bUnitID; | ||
} | ||
for (auto ct = _device->deviceData.ctrl_if.input_term_descs; | ||
ct; ct = ct->next) { | ||
_input_terminal = ct->bTerminalID; | ||
} | ||
|
||
_device->device->claim_interface(mi); | ||
for (auto pu = _device->deviceData.ctrl_if.processing_unit_descs; | ||
pu; pu = pu->next) { | ||
_processing_unit = pu->bUnitID; | ||
} | ||
|
||
_power_state = D0; | ||
return; | ||
} | ||
for (auto eu = _device->deviceData.ctrl_if.extension_unit_descs; | ||
eu; eu = eu->next) { | ||
_extension_unit = eu->bUnitID; | ||
} | ||
|
||
throw std::runtime_error("Device not found!"); | ||
_power_state = D0; | ||
|
||
} | ||
if (state == D3 && _power_state == D0) { | ||
_device.reset(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The method
create_usb_device
returnscommand_transfer
?If so - please use "_dev" suffix as
command_transfer
is too vagueAlso is this intended to work with non-Realsense devices, such as platform cam ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the original
usb_device
was an empty class which inheritedcommand_transfer
, since I removedusb_device
I needed to replace it withcommand_transfer
but I don't want to make more changes to the backend API in this PR unless it is necessary .