diff --git a/README.md b/README.md index e601007..db8bcd2 100644 --- a/README.md +++ b/README.md @@ -5,10 +5,19 @@ A bingden wrapper for the Azure Kinect Sensor SDK, which works on both Linux and Vendors the compiled SDK libs from version 1.3. At the moment I have compiled the sdk on both Linux and Windows -and added the `include`s and dynamic libraries by hand to the +and added the `include`s and dynamic libraries by hand to the `vendor` folder. It might be possible to compile libk4a from source in the future, but it looks time consuming. +Examples +------ +I am re-implementing and adding the examples that match the SDK's example in rust. You can run them with eg: +``` +cargo run --example enumerate +``` + +Future plans +------ This is temporarily missing the `depthengine` library, my plan is to statically compile this into the lib soon. Raise an issue if you'd like dynamic linking, but since `k4a` is such diff --git a/README.md~ b/README.md~ new file mode 100644 index 0000000..e601007 --- /dev/null +++ b/README.md~ @@ -0,0 +1,25 @@ +k4a-sys +------- +A bingden wrapper for the Azure Kinect Sensor SDK, which works on both Linux and Windows. + +Vendors the compiled SDK libs from version 1.3. + +At the moment I have compiled the sdk on both Linux and Windows +and added the `include`s and dynamic libraries by hand to the +`vendor` folder. It might be possible to compile libk4a from source in the future, +but it looks time consuming. + +This is temporarily missing the `depthengine` library, my plan is to statically compile this into the lib soon. + +Raise an issue if you'd like dynamic linking, but since `k4a` is such +a niche library, I think it's very convenient to have it statically compiled +into the lib for now. + +I'm also planning on writing a safe Rust wrapper library, `k4a-rs` to allow Rust-idiomatic (not raw pointers!) +access to the libraries. It will probably live in this repo and we'll move `k4a-sys` to a sub-directory here, the +same way [`bzip2-rs` and `bzip2-sys`](https://github.com/alexcrichton/bzip2-rs) work. + +I think in the near future we'll remove bindgen from the list of dependencies and only run it every library update, +that is, by hand/script instead of in the build.rs. This is because bindgen has ~60 dependencies, and should always +generate the same output file anyways. (It's possible to make the output cross platform). + diff --git a/examples/enumerate.rs b/examples/enumerate.rs new file mode 100644 index 0000000..762eb9b --- /dev/null +++ b/examples/enumerate.rs @@ -0,0 +1,40 @@ +extern crate k4a_sys; +use std::ptr; +use k4a_sys::*; + +fn main() { + unsafe { + let mut device: k4a_sys::k4a_device_t = ptr::null_mut(); + + let device_count = k4a_device_get_installed_count(); + println!("Found {} connected devices:", device_count); + for device_idx in 0..device_count { + if k4a_device_open(device_idx, &mut device) != k4a_buffer_result_t_K4A_BUFFER_RESULT_SUCCEEDED { + println!("Failed to open device #{}", device_idx); + continue; + } + let mut serial_number_length: usize = 0; + + if k4a_device_get_serialnum(device, ptr::null_mut(), &mut serial_number_length) != + k4a_buffer_result_t_K4A_BUFFER_RESULT_TOO_SMALL { + println!("{}: Failed to get serial number length", device_idx); + k4a_device_close(device); + device = ptr::null_mut(); + continue; + } + + let mut serial_number = vec![0i8; serial_number_length]; + let serial_number_ptr = (&mut serial_number).as_mut_ptr(); + + if k4a_device_get_serialnum(device, serial_number_ptr, &mut serial_number_length) != + k4a_buffer_result_t_K4A_BUFFER_RESULT_SUCCEEDED { + println!("{}: Failed to get serial number", device_idx); + k4a_device_close(device); + device = ptr::null_mut(); + continue; + } + println!("{}: Device \"{:?}\"\n", device_idx, serial_number); + k4a_device_close(device); + } + } +}