From 62fc4c00b01363a11d3c414a8a5e320f8c042af6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Am=C3=A9d=C3=A9e=20d=27Aboville?= Date: Thu, 30 Jan 2020 09:40:17 -0500 Subject: [PATCH] Impl Drop for Device wrapper, so it k4a_device_close()s the device when it goes out of scope. Also close the device in the streaming example. --- examples/calibration.rs | 66 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 65 insertions(+), 1 deletion(-) diff --git a/examples/calibration.rs b/examples/calibration.rs index 13e07d7..83aa622 100644 --- a/examples/calibration.rs +++ b/examples/calibration.rs @@ -1,6 +1,7 @@ #![allow(non_upper_case_globals)] extern crate k4a_sys; use std::ptr; +use std::default; use std::ffi::{CString}; use k4a_sys::*; @@ -65,9 +66,72 @@ impl Device { serial_number.into_string().ok() } } + + pub fn installed_count() -> u32 { + unsafe { + k4a_device_get_installed_count() + } + } } +impl Drop for Device { + fn drop (&mut self) { + unsafe { + k4a_device_close(self.k4a_device) + } + + } +} +pub struct DeviceConfiguration (k4a_device_configuration_t); +impl Default for DeviceConfiguration { + fn default() -> Self { + Self (k4a_sys::k4a_device_configuration_t { + color_format: k4a_image_format_t_K4A_IMAGE_FORMAT_COLOR_MJPG, + color_resolution: k4a_color_resolution_t_K4A_COLOR_RESOLUTION_720P, + depth_mode: k4a_depth_mode_t_K4A_DEPTH_MODE_WFOV_2X2BINNED, + camera_fps: 0, + synchronized_images_only: false, + depth_delay_off_color_usec: 0, + wired_sync_mode: 0, + subordinate_delay_off_master_usec: 0, + disable_streaming_indicator: false, + } + ) + } +} +impl DeviceConfiguration { + pub fn init_disable_all() -> Self { + Self (k4a_sys::k4a_device_configuration_t { + color_format: k4a_image_format_t_K4A_IMAGE_FORMAT_COLOR_MJPG, + color_resolution: k4a_color_resolution_t_K4A_COLOR_RESOLUTION_OFF, + depth_mode: k4a_depth_mode_t_K4A_DEPTH_MODE_OFF, + camera_fps: k4a_fps_t_K4A_FRAMES_PER_SECOND_30, + synchronized_images_only: false, + depth_delay_off_color_usec: 0, + wired_sync_mode: k4a_wired_sync_mode_t_K4A_WIRED_SYNC_MODE_STANDALONE, + subordinate_delay_off_master_usec: 0, + disable_streaming_indicator: false, + }) + } +} + +fn print_calibration() { + let num_devices = Device::installed_count(); + println!("Found {} connected devices", num_devices); + + unsafe { + let mut config : DeviceConfiguration= DeviceConfiguration::init_disable_all(); + println!("my config exists"); + for i in 0..num_devices { + let device = Device::open(i); + + } + } + +} + fn main () { let device = Device::open(0).expect("Couldn't open device"); let serial_number = device.get_serial().expect("Couldn't get serial number"); - println!("Found device with serial number {}", serial_number) + // println!("Found device with serial number {}", serial_number); + print_calibration(); } \ No newline at end of file