From f77764775713e51859a0ec52883d1fa6b71dbb50 Mon Sep 17 00:00:00 2001 From: Evan Pratten Date: Fri, 28 May 2021 13:15:20 -0400 Subject: [PATCH] wrapping leap lib --- Cargo.toml | 6 +++ README.md | 4 ++ libleap/Cargo.toml | 10 +++++ libleap/src/event.rs | 84 ++++++++++++++++++++++++++++++++++++++ libleap/src/leap_compat.rs | 71 ++++++++++++++++++++++++++++++++ libleap/src/lib.rs | 15 +++++++ libodm/Cargo.toml | 11 +++++ libodm/src/lib.rs | 0 snapscan/Cargo.toml | 9 ++++ snapscan/src/main.rs | 3 ++ 10 files changed, 213 insertions(+) create mode 100644 Cargo.toml create mode 100644 libleap/Cargo.toml create mode 100644 libleap/src/event.rs create mode 100644 libleap/src/leap_compat.rs create mode 100644 libleap/src/lib.rs create mode 100644 libodm/Cargo.toml create mode 100644 libodm/src/lib.rs create mode 100644 snapscan/Cargo.toml create mode 100644 snapscan/src/main.rs diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..e5ffdb6 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,6 @@ +[workspace] +members = [ + "libleap", + "libodm", + "snapscan", +] \ No newline at end of file diff --git a/README.md b/README.md index ab0551c..b2d2067 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,6 @@ # OpenDepthMap Point cloud streams from Leap Motion cameras +``` +clang libclang-dev libopencv-dev + +``` diff --git a/libleap/Cargo.toml b/libleap/Cargo.toml new file mode 100644 index 0000000..b4f28b1 --- /dev/null +++ b/libleap/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "libleap" +version = "0.1.0" +authors = ["Evan Pratten "] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +leap-sys = "0.1.1" \ No newline at end of file diff --git a/libleap/src/event.rs b/libleap/src/event.rs new file mode 100644 index 0000000..a2b52d1 --- /dev/null +++ b/libleap/src/event.rs @@ -0,0 +1,84 @@ +use leap_sys::{ + LEAP_CONFIG_CHANGE_EVENT, LEAP_CONFIG_RESPONSE_EVENT, LEAP_CONNECTION_EVENT, + LEAP_CONNECTION_LOST_EVENT, LEAP_CONNECTION_MESSAGE, LEAP_DEVICE_EVENT, + LEAP_DEVICE_FAILURE_EVENT, LEAP_HEAD_POSE_EVENT, LEAP_IMAGE_EVENT, LEAP_LOG_EVENT, + LEAP_LOG_EVENTS, LEAP_POINT_MAPPING_CHANGE_EVENT, LEAP_POLICY_EVENT, LEAP_TRACKING_EVENT, +}; + +#[derive(Debug)] +pub enum EventType { + Invalid, + Connection(*const LEAP_CONNECTION_EVENT), + ConnectionLost(*const LEAP_CONNECTION_LOST_EVENT), + Device(*const LEAP_DEVICE_EVENT), + DeviceLost(*const LEAP_DEVICE_EVENT), + DeviceFailure(*const LEAP_DEVICE_FAILURE_EVENT), + Tracking(*const LEAP_TRACKING_EVENT), + ImageComplete, + ImageRequestError, + LogEvent(*const LEAP_LOG_EVENT), + Policy(*const LEAP_POLICY_EVENT), + ConfigChange(*const LEAP_CONFIG_CHANGE_EVENT), + ConfigResponse(*const LEAP_CONFIG_RESPONSE_EVENT), + Image(*const LEAP_IMAGE_EVENT), + PointMappingChange(*const LEAP_POINT_MAPPING_CHANGE_EVENT), + LogEvents(*const LEAP_LOG_EVENTS), + HeadPose(*const LEAP_HEAD_POSE_EVENT), +} + +impl From for EventType { + #[allow(non_snake_case)] + fn from(message: LEAP_CONNECTION_MESSAGE) -> Self { + unsafe { + match message.type_ { + leap_sys::_eLeapEventType_eLeapEventType_Connection => { + Self::Connection(message.__bindgen_anon_1.connection_event) + } + leap_sys::_eLeapEventType_eLeapEventType_ConnectionLost => { + Self::ConnectionLost(message.__bindgen_anon_1.connection_lost_event) + } + leap_sys::_eLeapEventType_eLeapEventType_Device => { + Self::Device(message.__bindgen_anon_1.device_event) + } + leap_sys::_eLeapEventType_eLeapEventType_DeviceLost => { + Self::DeviceLost(message.__bindgen_anon_1.device_event) + } + leap_sys::_eLeapEventType_eLeapEventType_DeviceFailure => { + Self::DeviceFailure(message.__bindgen_anon_1.device_failure_event) + } + leap_sys::_eLeapEventType_eLeapEventType_Tracking => { + Self::Tracking(message.__bindgen_anon_1.tracking_event) + } + leap_sys::_eLeapEventType_eLeapEventType_ImageComplete => Self::ImageComplete, + leap_sys::_eLeapEventType_eLeapEventType_ImageRequestError => { + Self::ImageRequestError + } + leap_sys::_eLeapEventType_eLeapEventType_LogEvent => { + Self::LogEvent(message.__bindgen_anon_1.log_event) + } + leap_sys::_eLeapEventType_eLeapEventType_Policy => { + Self::Policy(message.__bindgen_anon_1.policy_event) + } + leap_sys::_eLeapEventType_eLeapEventType_ConfigChange => { + Self::ConfigChange(message.__bindgen_anon_1.config_change_event) + } + leap_sys::_eLeapEventType_eLeapEventType_ConfigResponse => { + Self::ConfigResponse(message.__bindgen_anon_1.config_response_event) + } + leap_sys::_eLeapEventType_eLeapEventType_Image => { + Self::Image(message.__bindgen_anon_1.image_event) + } + leap_sys::_eLeapEventType_eLeapEventType_PointMappingChange => { + Self::PointMappingChange(message.__bindgen_anon_1.point_mapping_change_event) + } + leap_sys::_eLeapEventType_eLeapEventType_LogEvents => { + Self::LogEvents(message.__bindgen_anon_1.log_events) + } + leap_sys::_eLeapEventType_eLeapEventType_HeadPose => { + Self::HeadPose(message.__bindgen_anon_1.head_pose_event) + } + _ => Self::Invalid, + } + } + } +} diff --git a/libleap/src/leap_compat.rs b/libleap/src/leap_compat.rs new file mode 100644 index 0000000..50e0821 --- /dev/null +++ b/libleap/src/leap_compat.rs @@ -0,0 +1,71 @@ +//! Some cleanup and tweaks to the LeapMotion bindings +//! +//! Since this library binds directly to `leap-sys`, some code +//! is not exactly fun to use. This file contains a few small shorthands +//! and typedefs and stuff + +pub mod types { + use std::ops::{Deref, DerefMut}; + + use leap_sys::LEAP_CONNECTION; + + /// A thin wrapper around `_LEAP_CONNECTION` + pub struct LeapConnection(LEAP_CONNECTION); + + impl Deref for LeapConnection { + type Target = LEAP_CONNECTION; + + fn deref(&self) -> &Self::Target { + &self.0 + } + } + + impl DerefMut for LeapConnection { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.0 + } + } + + impl From for LeapConnection { + fn from(c: LEAP_CONNECTION) -> Self { + Self { 0: c } + } + } +} + +pub mod errors { + use leap_sys::eLeapRS; + + /// A generic error, wrapping LeapMotion's `eLeapRS` + #[derive(Debug)] + pub struct GenericLeapError { + pub error: eLeapRS, + } + + impl From for GenericLeapError { + fn from(error: eLeapRS) -> Self { + Self { error } + } + } +} + +pub mod wrappers { + use leap_sys::{LeapCreateConnection, _eLeapRS_eLeapRS_Success}; + + use super::{errors::GenericLeapError, types::LeapConnection}; + + pub unsafe fn create_connection() -> Result { + // Create a handle for the connection + let connection_handle = std::ptr::null_mut(); + + // Call the leap driver + let result = LeapCreateConnection(std::ptr::null(), connection_handle); + + // Handle errors + if result != _eLeapRS_eLeapRS_Success { + return Err(result.into()); + } + + return Ok((*connection_handle).into()); + } +} diff --git a/libleap/src/lib.rs b/libleap/src/lib.rs new file mode 100644 index 0000000..fadc4d0 --- /dev/null +++ b/libleap/src/lib.rs @@ -0,0 +1,15 @@ + + +// pub mod leap_compat; + +pub mod event; + + +pub struct LeapDevice { +} + +impl LeapDevice { + + + +} diff --git a/libodm/Cargo.toml b/libodm/Cargo.toml new file mode 100644 index 0000000..f36da71 --- /dev/null +++ b/libodm/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "libodm" +version = "0.1.0" +authors = ["Evan Pratten "] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +opencv = "0.53.0" +leap-sys = "0.1.1" \ No newline at end of file diff --git a/libodm/src/lib.rs b/libodm/src/lib.rs new file mode 100644 index 0000000..e69de29 diff --git a/snapscan/Cargo.toml b/snapscan/Cargo.toml new file mode 100644 index 0000000..35386bf --- /dev/null +++ b/snapscan/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "snapscan" +version = "0.1.0" +authors = ["Evan Pratten "] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/snapscan/src/main.rs b/snapscan/src/main.rs new file mode 100644 index 0000000..e7a11a9 --- /dev/null +++ b/snapscan/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + println!("Hello, world!"); +}