Add enumerate example

This commit is contained in:
Amédée d'Aboville
2020-01-28 18:25:54 -05:00
parent d6359f8bec
commit bf36a9a20f
3 changed files with 75 additions and 1 deletions
+10 -1
View File
@@ -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. Vendors the compiled SDK libs from version 1.3.
At the moment I have compiled the sdk on both Linux and Windows 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, `vendor` folder. It might be possible to compile libk4a from source in the future,
but it looks time consuming. 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. 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 Raise an issue if you'd like dynamic linking, but since `k4a` is such
+25
View File
@@ -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).
+40
View File
@@ -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);
}
}
}