Time-of-Flight Library(ToF) 3.13.3
 
usb_interface.hpp
1#ifndef _CHRONOPTICS_TOF_USB_INTERFACE_HPP_
2#define _CHRONOPTICS_TOF_USB_INTERFACE_HPP_
3
4#include <chronoptics/tof/usb_interface.h>
5
6#include <chronoptics/tof/camera_config.hpp>
7#include <chronoptics/tof/calibration.hpp>
8#include <chronoptics/tof/data.hpp>
9#include <chronoptics/tof/gige_interface.hpp>
10
11namespace chronoptics {
12namespace tof {
13
14/** USB device
15*/
16class UsbDevice : public detail::Base<tof_usb_device, tof_usb_device_delete> {
17 public:
18 /** Construct from pointer */
19 UsbDevice(tof_usb_device_t ptr = nullptr) {
20 this->ptr_ = ptr;
21 }
22
23 /** Get serial corresponding with USB device
24 * @return Serial
25 */
26 const char* serial() {
27 return tof_usb_device_serial(this->ptr_, TOF_ERROR_HANDLER{});
28 }
29
30};
31
32/** DEPRECATED, use KeaCamera. Connect to a camera directly using the USB
33 * interface
34*/
35class UsbInterface : public detail::Base<tof_usb_interface, tof_usb_interface_delete> {
36 public:
37 /** Construct from pointer */
38 UsbInterface(tof_usb_interface_t ptr = nullptr) {
39 this->ptr_ = ptr;
40 }
41
42 /** Create USB camera from a usb device
43 * @param usb_device USB device
44 */
45 UsbInterface(UsbDevice &usb_device) {
46 this->ptr_ = tof_usb_interface_new(*reinterpret_cast<tof_usb_device_t*>(&usb_device), TOF_ERROR_HANDLER{});
47 }
48
49 /** Check whether a connection is still maintained with the camera
50 * @return Is connected
51 */
52 bool is_connected() const {
53 return tof_usb_interface_is_connected(this->ptr_, TOF_ERROR_HANDLER{});
54 }
55
56 /** Tests the connection speed of the USB port. This is useful to check
57 * whether a hub or USB port works well. The maximum speed that the camera is
58 * able to transmit is ~3.0 Gbps.
59 * @return Connection speed in Gpbs (bits)
60 */
62 return tof_usb_interface_test_stream_speed(this->ptr_, TOF_ERROR_HANDLER{});
63 }
64
65 /** Download camera configuration from the camera
66 * @return Camera configuration
67 */
69 CameraConfig new_camera_config(static_cast<tof_camera_config_t>(nullptr));
70 auto ptr = reinterpret_cast<tof_camera_config_t*>(&new_camera_config);
71 *ptr = tof_usb_interface_download_configuration(this->ptr_, TOF_ERROR_HANDLER{});
72 return new_camera_config;
73 }
74
75 /** Download calibration from the camera
76 * @return Calibration
77 */
79 Calibration new_calibration(static_cast<tof_calibration_t>(nullptr));
80 auto ptr = reinterpret_cast<tof_calibration_t*>(&new_calibration);
81 *ptr = tof_usb_interface_download_calibration(this->ptr_, TOF_ERROR_HANDLER{});
82 return new_calibration;
83 }
84
85 /** Upload camera configuration to the camera
86 * @param config Camera configuration
87 */
88 void upload_configuration(const CameraConfig &config) {
89 return tof_usb_interface_upload_configuration(this->ptr_, *reinterpret_cast<const tof_camera_config_t*>(&config), TOF_ERROR_HANDLER{});
90 }
91
92 /** Check whether this camera is capable of streaming the specified type
93 * @param stream Depth stream type
94 * @return Is capable
95 */
96 bool depth_stream_capable(DepthStreamType stream) const {
97 return tof_usb_interface_depth_stream_capable(this->ptr_, static_cast<tof_depth_stream_type>(stream), TOF_ERROR_HANDLER{});
98 }
99
100 /** Start the depth stream
101 * @param stream Depth stream type
102 */
103 void start_depth_stream(DepthStreamType stream) {
104 return tof_usb_interface_start_depth_stream(this->ptr_, static_cast<tof_depth_stream_type>(stream), TOF_ERROR_HANDLER{});
105 }
106
107 /** Stop the depth stream
108 */
110 return tof_usb_interface_stop_depth_stream(this->ptr_, TOF_ERROR_HANDLER{});
111 }
112
113 /** Returns true if a depth frame is available
114 * @return Depth frame available
115 */
116 bool has_depth_data() const {
117 return tof_usb_interface_has_depth_data(this->ptr_, TOF_ERROR_HANDLER{});
118 }
119
120 /** Get a depth frame
121 * @return Depth frame
122 */
124 Data new_data(static_cast<tof_data_t>(nullptr));
125 auto ptr = reinterpret_cast<tof_data_t*>(&new_data);
126 *ptr = tof_usb_interface_get_depth_data(this->ptr_, TOF_ERROR_HANDLER{});
127 return new_data;
128 }
129
130 /** Check whether camera supports an image stream
131 * @return Camera supports an image stream
132 */
133 bool image_stream_capable() const {
134 return tof_usb_interface_image_stream_capable(this->ptr_, TOF_ERROR_HANDLER{});
135 }
136
137 /** Start image stream
138 */
140 return tof_usb_interface_start_image_stream(this->ptr_, TOF_ERROR_HANDLER{});
141 }
142
143 /** Stop image stream
144 */
146 return tof_usb_interface_stop_image_stream(this->ptr_, TOF_ERROR_HANDLER{});
147 }
148
149 /** Check whether image frame is available
150 * @return Image frame available
151 */
152 bool has_image_data() const {
153 return tof_usb_interface_has_image_data(this->ptr_, TOF_ERROR_HANDLER{});
154 }
155
156 /** Get image frame
157 * @return Image data
158 */
160 Data new_data(static_cast<tof_data_t>(nullptr));
161 auto ptr = reinterpret_cast<tof_data_t*>(&new_data);
162 *ptr = tof_usb_interface_get_image_data(this->ptr_, TOF_ERROR_HANDLER{});
163 return new_data;
164 }
165
166 /** Get the image frame into the supplied pointer
167 * @param pointer The pointer to the data to write into
168 * @param capacity The amount of data the pointer can hold
169 * @param callback Callback that will be called when pointer is no longer in
170 * use
171 * @return Image data
172 */
173 Data get_image_data_into_pointer(uint8_t* pointer, size_t capacity, user_pointer_destructed_fn &callback) {
174 Data new_data(static_cast<tof_data_t>(nullptr));
175 auto ptr = reinterpret_cast<tof_data_t*>(&new_data);
176 *ptr = tof_usb_interface_get_image_data_into_pointer(this->ptr_, pointer, capacity, user_pointer_destructed_cb_handler, &callback, TOF_ERROR_HANDLER{});
177 return new_data;
178 }
179
180 /** Get the image frame into the supplied pointer
181 * @param pointer The pointer to the data to write into
182 * @param capacity The amount of data the pointer can hold
183 * @param callback Callback that will be called when pointer is no longer in
184 * use
185 * @param callback_user_data User data that will be passed back when the function pointer is called
186 * @return Image data
187 */
188 Data get_image_data_into_pointer(uint8_t* pointer, size_t capacity, tof_user_pointer_destructed_t callback, void* callback_user_data) {
189 Data new_data(static_cast<tof_data_t>(nullptr));
190 auto ptr = reinterpret_cast<tof_data_t*>(&new_data);
191 *ptr = tof_usb_interface_get_image_data_into_pointer(this->ptr_, pointer, capacity, callback, callback_user_data, TOF_ERROR_HANDLER{});
192 return new_data;
193 }
194
195 /** Get the capacity for amount of user pointers that can be registered
196 * @return User pointer capacity
197 */
199 return tof_usb_interface_get_user_pointer_capacity(this->ptr_, TOF_ERROR_HANDLER{});
200 }
201
202 /** Set the capacity for amount of user pointers that can be registered
203 * @param capacity User pointer capacity
204 */
205 void set_user_pointer_capacity(size_t capacity) {
206 return tof_usb_interface_set_user_pointer_capacity(this->ptr_, capacity, TOF_ERROR_HANDLER{});
207 }
208
209 /** Add a pointer that will be filled with depth data. This method allows you
210 * to fill data straight into your own data structure without any additional
211 * copying.
212 * @param pointer The pointer to the data to write into
213 * @param capacity The amount of data the pointer can hold
214 * @param callback Callback that will be called when pointer is no longer in
215 * use
216 */
217 void add_depth_user_pointer(uint8_t* pointer, size_t capacity, user_pointer_destructed_fn &callback) {
218 return tof_usb_interface_add_depth_user_pointer(this->ptr_, pointer, capacity, user_pointer_destructed_cb_handler, &callback, TOF_ERROR_HANDLER{});
219 }
220
221 /** Add a pointer that will be filled with depth data. This method allows you
222 * to fill data straight into your own data structure without any additional
223 * copying.
224 * @param pointer The pointer to the data to write into
225 * @param capacity The amount of data the pointer can hold
226 * @param callback Callback that will be called when pointer is no longer in
227 * use
228 * @param callback_user_data User data that will be passed back when the function pointer is called
229 */
230 void add_depth_user_pointer(uint8_t* pointer, size_t capacity, tof_user_pointer_destructed_t callback, void* callback_user_data) {
231 return tof_usb_interface_add_depth_user_pointer(this->ptr_, pointer, capacity, callback, callback_user_data, TOF_ERROR_HANDLER{});
232 }
233
234 /** Get the tof library version running on the camera
235 * @return Version
236 */
237 const char* version() {
238 return tof_usb_interface_version(this->ptr_, TOF_ERROR_HANDLER{});
239 }
240
241 /** Check whether the camera is capable of software trigger
242 * @return Software trigger capable
243 */
245 return tof_usb_interface_software_trigger_capable(this->ptr_, TOF_ERROR_HANDLER{});
246 }
247
248 /** Software trigger the camera
249 */
251 return tof_usb_interface_software_trigger(this->ptr_, TOF_ERROR_HANDLER{});
252 }
253
254};
255
256/** Discover all connected chronoptics usb cameras
257 * @return The usb devices
258 */
259inline std::vector<UsbDevice> usb_device_discover() {
260 size_t size = tof_usb_device_discover(nullptr, 0, TOF_ERROR_HANDLER{});
261 std::vector<UsbDevice> vec;
262 vec.reserve(size);
263 for (size_t i = 0; i < size; i++)
264 vec.emplace_back(static_cast<tof_usb_device_t>(nullptr));
265 auto data = reinterpret_cast<tof_usb_device_t*>(vec.data());
266 size = tof_usb_device_discover(data, vec.size(), TOF_ERROR_HANDLER{});
267 return vec;
268}
269
270/** Discover one chronoptics usb camera
271 * @return A USB device
272 */
273inline UsbDevice usb_device_discover_one() {
274 UsbDevice new_usb_device(static_cast<tof_usb_device_t>(nullptr));
275 auto ptr = reinterpret_cast<tof_usb_device_t*>(&new_usb_device);
276 *ptr = tof_usb_device_discover_one(TOF_ERROR_HANDLER{});
277 return new_usb_device;
278}
279
280/** Discover usb camera with the given serial
281 * @param serial Serial of the camera to find
282 * @return A USB device
283 */
284inline UsbDevice usb_device_find(StringView serial) {
285 UsbDevice new_usb_device(static_cast<tof_usb_device_t>(nullptr));
286 auto ptr = reinterpret_cast<tof_usb_device_t*>(&new_usb_device);
287 *ptr = tof_usb_device_find(serial, TOF_ERROR_HANDLER{});
288 return new_usb_device;
289}
290
291} // tof
292} // chronoptics
293
294#endif
This class contains all the calibration information.
Definition: calibration.hpp:38
This class allows you to view/edit the camera settings.
This is the class that contains depth or image data.
Definition: data.hpp:31
UsbDevice(tof_usb_device_t ptr=nullptr)
Construct from pointer.
const char * serial()
Get serial corresponding with USB device.
DEPRECATED, use KeaCamera.
bool depth_stream_capable(DepthStreamType stream) const
Check whether this camera is capable of streaming the specified type.
bool is_connected() const
Check whether a connection is still maintained with the camera.
void software_trigger()
Software trigger the camera.
bool image_stream_capable() const
Check whether camera supports an image stream.
void stop_image_stream()
Stop image stream.
UsbInterface(UsbDevice &usb_device)
Create USB camera from a usb device.
void set_user_pointer_capacity(size_t capacity)
Set the capacity for amount of user pointers that can be registered.
double test_stream_speed()
Tests the connection speed of the USB port.
void start_depth_stream(DepthStreamType stream)
Start the depth stream.
Data get_image_data_into_pointer(uint8_t *pointer, size_t capacity, tof_user_pointer_destructed_t callback, void *callback_user_data)
Get the image frame into the supplied pointer.
bool has_depth_data() const
Returns true if a depth frame is available.
void stop_depth_stream()
Stop the depth stream.
Data get_image_data()
Get image frame.
void add_depth_user_pointer(uint8_t *pointer, size_t capacity, user_pointer_destructed_fn &callback)
Add a pointer that will be filled with depth data.
void start_image_stream()
Start image stream.
void add_depth_user_pointer(uint8_t *pointer, size_t capacity, tof_user_pointer_destructed_t callback, void *callback_user_data)
Add a pointer that will be filled with depth data.
Data get_image_data_into_pointer(uint8_t *pointer, size_t capacity, user_pointer_destructed_fn &callback)
Get the image frame into the supplied pointer.
size_t get_user_pointer_capacity() const
Get the capacity for amount of user pointers that can be registered.
UsbInterface(tof_usb_interface_t ptr=nullptr)
Construct from pointer.
const char * version()
Get the tof library version running on the camera.
Calibration download_calibration()
Download calibration from the camera.
Data get_depth_data()
Get a depth frame.
bool software_trigger_capable()
Check whether the camera is capable of software trigger.
bool has_image_data() const
Check whether image frame is available.
CameraConfig download_configuration()
Download camera configuration from the camera.
void upload_configuration(const CameraConfig &config)
Upload camera configuration to the camera.