4 #include <pybind11/pybind11.h> 7 #include <pybind11/operators.h> 10 #include <pybind11/stl.h> 11 #include <pybind11/stl_bind.h> 15 #include <pybind11/functional.h> 19 #include "../src/backend.h" 21 #include "../../third-party/stb_image_write.h" 26 #define NAME pybackend2 27 #define SNAME "pybackend2" 29 namespace py = pybind11;
37 PYBIND11_MAKE_OPAQUE(std::vector<uint8_t>)
42 py::enum_<platform::usb_spec>(
m,
"USB_TYPE")
51 m.doc() =
"Wrapper for the backend of librealsense";
53 py::class_<platform::control_range> control_range(m,
"control_range");
54 control_range.def(py::init<>())
55 .def(py::init<int32_t, int32_t, int32_t, int32_t>(),
"in_min"_a,
"in_max"_a,
"in_step"_a,
"in_def"_a)
57 .def_readwrite(
"max", &platform::control_range::max)
58 .def_readwrite(
"def", &platform::control_range::def)
59 .def_readwrite(
"step", &platform::control_range::step);
61 py::class_<platform::time_service> time_service(m,
"time_service");
64 py::class_<platform::os_time_service, platform::time_service> os_time_service(m,
"os_time_service");
66 #define BIND_RAW_RO_ARRAY(class, name, type, size) #name, [](const class &c) -> const std::array<type, size>& { return reinterpret_cast<const std::array<type, size>&>(c.name); } 67 #define BIND_RAW_RW_ARRAY(class, name, type, size) BIND_RAW_RO_ARRAY(class, name, type, size), [](class &c, const std::array<type, size> &arr) { for (int i=0; i<size; ++i) c.name[i] = arr[i]; } 69 py::class_<platform::guid> guid(m,
"guid");
70 guid.def_readwrite(
"data1", &platform::guid::data1)
71 .def_readwrite(
"data2", &platform::guid::data2)
72 .def_readwrite(
"data3", &platform::guid::data3)
81 },
"data1"_a,
"data2"_a,
"data3"_a,
"data4"_a)
87 py::class_<platform::extension_unit> extension_unit(m,
"extension_unit");
88 extension_unit.def(py::init<>())
92 },
"subdevice"_a,
"unit"_a,
"node"_a,
"guid"_a)
93 .def_readwrite(
"subdevice", &platform::extension_unit::subdevice)
95 .def_readwrite(
"node", &platform::extension_unit::node)
98 py::class_<platform::command_transfer, std::shared_ptr<platform::command_transfer>> command_transfer(m,
"command_transfer");
99 command_transfer.def(
"send_receive", &platform::command_transfer::send_receive,
"data"_a,
"timeout_ms"_a=5000,
"require_response"_a=
true);
101 py::enum_<rs2_option>
option(m,
"option");
192 py::enum_<platform::power_state>
power_state(m,
"power_state");
195 power_state.export_values();
197 py::class_<platform::stream_profile>
stream_profile(m,
"stream_profile");
204 std::stringstream ss;
205 ss <<
"<" SNAME ".stream_profile: " 207 <<
"x" << p.
height <<
" @ " << p.
fps <<
"fps " 208 << std::hex << p.
format <<
">";
213 py::bind_vector<std::vector<uint8_t>>(
m,
"VectorByte");
215 py::class_<platform::frame_object> frame_object(m,
"frame_object");
216 frame_object.def_readwrite(
"frame_size", &platform::frame_object::frame_size)
217 .def_readwrite(
"metadata_size", &platform::frame_object::metadata_size)
223 },
"filename"_a,
"width"_a,
"height"_a,
"bytes_per_pixel"_a,
"stride"_a)
227 },
"filename"_a,
"width"_a,
"height"_a,
"bytes_per_pixel"_a);
229 py::class_<platform::uvc_device_info>
uvc_device_info(m,
"uvc_device_info");
231 .def_readwrite(
"vid", &platform::uvc_device_info::vid)
232 .def_readwrite(
"pid", &platform::uvc_device_info::pid)
233 .def_readwrite(
"mi", &platform::uvc_device_info::mi)
234 .def_readwrite(
"unique_id", &platform::uvc_device_info::unique_id)
235 .def_readwrite(
"device_path", &platform::uvc_device_info::device_path)
236 .def(py::self == py::self);
238 py::class_<platform::usb_device_info>
usb_device_info(m,
"usb_device_info");
240 .def_readwrite(
"vid", &platform::usb_device_info::vid)
241 .def_readwrite(
"pid", &platform::usb_device_info::pid)
242 .def_readwrite(
"mi", &platform::usb_device_info::mi)
243 .def_readwrite(
"unique_id", &platform::usb_device_info::unique_id);
245 py::class_<platform::hid_device_info>
hid_device_info(m,
"hid_device_info");
247 .def_readwrite(
"vid", &platform::hid_device_info::vid)
248 .def_readwrite(
"pid", &platform::hid_device_info::pid)
249 .def_readwrite(
"unique_id", &platform::hid_device_info::unique_id)
250 .def_readwrite(
"device_path", &platform::hid_device_info::device_path);
252 py::class_<platform::hid_sensor>
hid_sensor(m,
"hid_sensor");
255 py::class_<platform::hid_sensor_input> hid_sensor_input(m,
"hid_sensor_input");
259 py::class_<platform::callback_data> callback_data(m,
"callback_data");
261 .def_readwrite(
"sensor_input", &platform::callback_data::sensor_input)
264 py::class_<platform::sensor_data> sensor_data(m,
"sensor_data");
266 .def_readwrite(
"fo", &platform::sensor_data::fo);
268 py::class_<platform::hid_profile> hid_profile(m,
"hid_profile");
269 hid_profile.def(py::init<>())
270 .def_readwrite(
"sensor_name", &platform::hid_profile::sensor_name)
271 .def_readwrite(
"frequency", &platform::hid_profile::frequency);
281 custom_sensor_report_field.export_values();
283 py::class_<platform::hid_sensor_data> hid_sensor_data(m,
"hid_sensor_data");
290 .def_readwrite(
"ts_low", &platform::hid_sensor_data::ts_low)
291 .def_readwrite(
"ts_high", &platform::hid_sensor_data::ts_high);
293 py::class_<platform::hid_device, std::shared_ptr<platform::hid_device>> hid_device(m,
"hid_device");
295 hid_device.def(
"open", &platform::hid_device::open,
"hid_profiles"_a)
296 .def(
"close", &platform::hid_device::close)
297 .def(
"stop_capture", &platform::hid_device::stop_capture, py::call_guard<py::gil_scoped_release>())
298 .def(
"start_capture", &platform::hid_device::start_capture,
"callback"_a)
299 .def(
"get_sensors", &platform::hid_device::get_sensors)
300 .def(
"get_custom_report_data", &platform::hid_device::get_custom_report_data,
301 "custom_sensor_name"_a,
"report_name"_a,
"report_field"_a);
303 py::class_<platform::multi_pins_hid_device, std::shared_ptr<platform::multi_pins_hid_device>,
platform::hid_device> multi_pins_hid_device(m,
"multi_pins_hid_device");
305 multi_pins_hid_device.def(
py::init<std::vector<std::shared_ptr<platform::hid_device>>&>())
306 .def(
"open", &platform::multi_pins_hid_device::open,
"hid_profiles"_a)
307 .def(
"close", &platform::multi_pins_hid_device::close)
308 .def(
"stop_capture", &platform::multi_pins_hid_device::stop_capture, py::call_guard<py::gil_scoped_release>())
309 .def(
"start_capture", &platform::multi_pins_hid_device::start_capture,
"callback"_a)
310 .def(
"get_sensors", &platform::multi_pins_hid_device::get_sensors)
311 .def(
"get_custom_report_data", &platform::multi_pins_hid_device::get_custom_report_data,
312 "custom_sensor_name"_a,
"report_name"_a,
"report_field"_a);
314 py::class_<platform::uvc_device, std::shared_ptr<platform::uvc_device>> uvc_device(m,
"uvc_device");
316 py::class_<platform::retry_controls_work_around, std::shared_ptr<platform::retry_controls_work_around>,
platform::uvc_device> retry_controls_work_around(m,
"retry_controls_work_around");
318 retry_controls_work_around.def(
py::init<std::shared_ptr<platform::uvc_device>>())
319 .def(
"probe_and_commit",
329 ,
"profile"_a,
"callback"_a)
335 .def(
"start_callbacks", &platform::retry_controls_work_around::start_callbacks)
336 .def(
"stop_callbacks", &platform::retry_controls_work_around::stop_callbacks)
337 .def(
"get_usb_specification", &platform::retry_controls_work_around::get_usb_specification)
340 py::gil_scoped_release release;
343 .def(
"set_power_state", &platform::retry_controls_work_around::set_power_state,
"state"_a)
344 .def(
"get_power_state", &platform::retry_controls_work_around::get_power_state)
345 .def(
"init_xu", &platform::retry_controls_work_around::init_xu,
"xu"_a)
348 std::vector<uint8_t>
data(l.size());
349 for (
int i = 0;
i < l.size(); ++
i)
350 data[
i] = l[
i].cast<uint8_t>();
352 },
"xu"_a,
"ctrl"_a,
"data"_a)
355 return dev.
set_xu(xu, ctrl, data.data(), (int)data.size());
356 },
"xu"_a,
"ctrl"_a,
"data"_a)
359 std::vector<uint8_t>
data(len);
360 dev.
get_xu(xu, ctrl, data.data(), (int)len);
362 for (
size_t i = 0;
i <
len; ++
i)
365 },
"xu"_a,
"ctrl"_a,
"len"_a)
366 .def(
"get_xu_range", &platform::retry_controls_work_around::get_xu_range,
"xu"_a,
"ctrl"_a,
"len"_a)
372 .def(
"set_pu", &platform::retry_controls_work_around::set_pu,
"opt"_a,
"value"_a)
373 .def(
"get_pu_range", &platform::retry_controls_work_around::get_pu_range,
"opt"_a)
374 .def(
"get_profiles", &platform::retry_controls_work_around::get_profiles)
377 .def(
"get_device_location", &platform::retry_controls_work_around::get_device_location);
381 py::class_<platform::backend, std::shared_ptr<platform::backend>> backend(m,
"backend");
382 backend.def(
"create_uvc_device", &platform::backend::create_uvc_device,
"info"_a)
383 .def(
"query_uvc_devices", &platform::backend::query_uvc_devices)
384 .def(
"create_usb_device", &platform::backend::create_usb_device,
"info"_a)
385 .def(
"query_usb_devices", &platform::backend::query_usb_devices)
386 .def(
"create_hid_device", &platform::backend::create_hid_device,
"info"_a)
387 .def(
"query_hid_devices", &platform::backend::query_hid_devices)
388 .def(
"create_time_service", &platform::backend::create_time_service);
390 py::class_<platform::multi_pins_uvc_device, std::shared_ptr<platform::multi_pins_uvc_device>,
platform::uvc_device> multi_pins_uvc_device(m,
"multi_pins_uvc_device");
391 multi_pins_uvc_device.def(
py::init<std::vector<std::shared_ptr<platform::uvc_device>>&>())
392 .def(
"probe_and_commit",
402 ,
"profile"_a,
"callback"_a)
408 .def(
"start_callbacks", &platform::multi_pins_uvc_device::start_callbacks)
409 .def(
"stop_callbacks", &platform::multi_pins_uvc_device::stop_callbacks)
410 .def(
"get_usb_specification", &platform::multi_pins_uvc_device::get_usb_specification)
413 py::gil_scoped_release release;
416 .def(
"set_power_state", &platform::multi_pins_uvc_device::set_power_state,
"state"_a)
417 .def(
"get_power_state", &platform::multi_pins_uvc_device::get_power_state)
418 .def(
"init_xu", &platform::multi_pins_uvc_device::init_xu,
"xu"_a)
421 std::vector<uint8_t>
data(l.size());
422 for (
int i = 0;
i < l.size(); ++
i)
423 data[
i] = l[
i].cast<uint8_t>();
424 return dev.
set_xu(xu, ctrl, data.data(), (int)data.size());
425 },
"xu"_a,
"ctrl"_a,
"data"_a)
428 return dev.
set_xu(xu, ctrl, data.data(), (int)data.size());
429 },
"xu"_a,
"ctrl"_a,
"data"_a)
432 std::vector<uint8_t>
data(len);
433 dev.
get_xu(xu, ctrl, data.data(), (int)len);
435 for (
size_t i = 0;
i <
len; ++
i)
438 },
"xu"_a,
"ctrl"_a,
"len"_a)
439 .def(
"get_xu_range", &platform::multi_pins_uvc_device::get_xu_range,
"xu"_a,
"ctrl"_a,
"len"_a)
445 .def(
"set_pu", &platform::multi_pins_uvc_device::set_pu,
"opt"_a,
"value"_a)
446 .def(
"get_pu_range", &platform::multi_pins_uvc_device::get_pu_range,
"opt"_a)
447 .def(
"get_profiles", &platform::multi_pins_uvc_device::get_profiles)
450 .def(
"get_device_location", &platform::multi_pins_uvc_device::get_device_location);
463 std::vector<uint8_t>
data(l.size());
464 for (
int i = 0;
i < l.size(); ++
i)
465 data[
i] = l[
i].cast<uint8_t>();
466 return encode_command(static_cast<command>(opcode), p1, p2, p3, p4, data);
467 },
"opcode"_a,
"p1"_a=0,
"p2"_a=0,
"p3"_a=0,
"p4"_a=0,
"data"_a = py::list(0));
static const textual_icon lock
rs2_camera_info
Read-only strings that can be queried from the device. Not all information attributes are available o...
static const textual_icon unlock
GLuint const GLchar * name
rs2_option
Defines general configuration controls. These can generally be mapped to camera UVC controls...
platform::guid stoguid(std::string str)
#define BIND_RAW_RW_ARRAY(class, name, type, size)
void create_snapshot(std::shared_ptr< info_interface > &snapshot) const override
std::vector< uint8_t > encode_command(command opcode, uint32_t p1=0, uint32_t p2=0, uint32_t p3=0, uint32_t p4=0, std::vector< uint8_t > data=std::vector< uint8_t >())
virtual void create_snapshot(std::shared_ptr< option > &snapshot) const
GLdouble GLdouble GLdouble w
GLsizei const GLchar *const * string
GLfloat GLfloat GLfloat GLfloat h
std::vector< rs2_option > get_supported_options() const override
def info(name, value, persistent=False)
void register_info(rs2_camera_info info, const std::string &val)
GLint GLsizei GLsizei height
GLint GLint GLsizei GLint GLenum format
void update(std::shared_ptr< extension_snapshot > ext) override
bool supports_info(rs2_camera_info info) const override
const base::type::char_t * unit
void update_info(rs2_camera_info info, const std::string &val)
const std::string & get_info(rs2_camera_info info) const override
void enable_recording(std::function< void(const info_interface &)> record_action) override
void next(auto_any_t cur, type2type< T, C > *)
STBIWDEF int stbi_write_png(char const *filename, int w, int h, int comp, const void *data, int stride_in_bytes)
typename::boost::move_detail::remove_reference< T >::type && move(T &&t) BOOST_NOEXCEPT