wrapping leap lib
This commit is contained in:
parent
a621a28acf
commit
f777647757
6
Cargo.toml
Normal file
6
Cargo.toml
Normal file
@ -0,0 +1,6 @@
|
||||
[workspace]
|
||||
members = [
|
||||
"libleap",
|
||||
"libodm",
|
||||
"snapscan",
|
||||
]
|
@ -1,2 +1,6 @@
|
||||
# OpenDepthMap
|
||||
Point cloud streams from Leap Motion cameras
|
||||
```
|
||||
clang libclang-dev libopencv-dev
|
||||
|
||||
```
|
||||
|
10
libleap/Cargo.toml
Normal file
10
libleap/Cargo.toml
Normal file
@ -0,0 +1,10 @@
|
||||
[package]
|
||||
name = "libleap"
|
||||
version = "0.1.0"
|
||||
authors = ["Evan Pratten <ewpratten@gmail.com>"]
|
||||
edition = "2018"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
leap-sys = "0.1.1"
|
84
libleap/src/event.rs
Normal file
84
libleap/src/event.rs
Normal file
@ -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<LEAP_CONNECTION_MESSAGE> 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,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
71
libleap/src/leap_compat.rs
Normal file
71
libleap/src/leap_compat.rs
Normal file
@ -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<LEAP_CONNECTION> 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<eLeapRS> 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<LeapConnection, GenericLeapError> {
|
||||
// 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());
|
||||
}
|
||||
}
|
15
libleap/src/lib.rs
Normal file
15
libleap/src/lib.rs
Normal file
@ -0,0 +1,15 @@
|
||||
|
||||
|
||||
// pub mod leap_compat;
|
||||
|
||||
pub mod event;
|
||||
|
||||
|
||||
pub struct LeapDevice {
|
||||
}
|
||||
|
||||
impl LeapDevice {
|
||||
|
||||
|
||||
|
||||
}
|
11
libodm/Cargo.toml
Normal file
11
libodm/Cargo.toml
Normal file
@ -0,0 +1,11 @@
|
||||
[package]
|
||||
name = "libodm"
|
||||
version = "0.1.0"
|
||||
authors = ["Evan Pratten <ewpratten@gmail.com>"]
|
||||
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"
|
0
libodm/src/lib.rs
Normal file
0
libodm/src/lib.rs
Normal file
9
snapscan/Cargo.toml
Normal file
9
snapscan/Cargo.toml
Normal file
@ -0,0 +1,9 @@
|
||||
[package]
|
||||
name = "snapscan"
|
||||
version = "0.1.0"
|
||||
authors = ["Evan Pratten <ewpratten@gmail.com>"]
|
||||
edition = "2018"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
3
snapscan/src/main.rs
Normal file
3
snapscan/src/main.rs
Normal file
@ -0,0 +1,3 @@
|
||||
fn main() {
|
||||
println!("Hello, world!");
|
||||
}
|
Reference in New Issue
Block a user