more leap wrapping
This commit is contained in:
parent
8c171957fb
commit
ae0b739e59
10
libodm/src/image.rs
Normal file
10
libodm/src/image.rs
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
#[derive(Debug)]
|
||||||
|
pub struct Image {}
|
||||||
|
|
||||||
|
impl Image {
|
||||||
|
pub fn new(width: i32, height: i32, raw_data: &[u8]) -> Self {
|
||||||
|
Self {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,16 +1,42 @@
|
|||||||
|
//! Defines an interface for LeapMotion cameras
|
||||||
|
|
||||||
use std::time::{Duration, SystemTime};
|
use std::time::{Duration, SystemTime};
|
||||||
|
|
||||||
use crate::leapmotion::ffi::endEventLoop;
|
use crate::image::Image;
|
||||||
|
|
||||||
use super::ffi;
|
use super::ffi;
|
||||||
|
|
||||||
|
/// Defines some errors that can come from the device
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum DeviceError {
|
pub enum DeviceError {
|
||||||
|
/// An error caused by too many instances being created
|
||||||
InstanceError,
|
InstanceError,
|
||||||
|
|
||||||
|
/// An error caused by a timeout being reached
|
||||||
Timeout,
|
Timeout,
|
||||||
|
|
||||||
|
/// An error caused when no data is being sent by the device
|
||||||
|
NoData,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct LeapMotionDevice {}
|
/// Represents a single data frame generated by the LeapMotion device
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct DeviceFrame {
|
||||||
|
/// Number of bytes per pixel
|
||||||
|
pub bytes_per_pixel: u8,
|
||||||
|
|
||||||
|
/// Image from the left camera
|
||||||
|
pub left_camera: Image,
|
||||||
|
|
||||||
|
/// Image from the right camera
|
||||||
|
pub right_camera: Image,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Represents a LeapMotion device, and provides safe wrappers around its FFI
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct LeapMotionDevice {
|
||||||
|
cameras_flipped: bool,
|
||||||
|
}
|
||||||
|
|
||||||
impl LeapMotionDevice {
|
impl LeapMotionDevice {
|
||||||
/// Creates a LeapMotionDevice by talking to the device driver. This can only be called once
|
/// Creates a LeapMotionDevice by talking to the device driver. This can only be called once
|
||||||
@ -50,7 +76,63 @@ impl LeapMotionDevice {
|
|||||||
}
|
}
|
||||||
|
|
||||||
log::debug!("Device created");
|
log::debug!("Device created");
|
||||||
Ok(Self {})
|
Ok(Self {
|
||||||
|
cameras_flipped: false,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Configure the camera to flip its cameras. In normal configuration, the green light is facing the user, while the device is laying flat
|
||||||
|
pub fn set_cameras_flipped(&mut self, flipped: bool) {
|
||||||
|
self.cameras_flipped = flipped;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get if the cameras are flipped
|
||||||
|
pub fn cameras_flipped(&self) -> bool {
|
||||||
|
self.cameras_flipped
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get if the device has a frame to be read
|
||||||
|
pub fn has_frame(&mut self) -> bool {
|
||||||
|
unsafe {
|
||||||
|
return ffi::isControllerCreated() && ffi::imageExists();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get the latest frame from the device
|
||||||
|
pub fn get_frame(&mut self) -> Result<DeviceFrame, DeviceError> {
|
||||||
|
if !self.has_frame() {
|
||||||
|
return Err(DeviceError::NoData);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read raw data from the device
|
||||||
|
let image_width;
|
||||||
|
let image_height;
|
||||||
|
let bytes_per_pixel;
|
||||||
|
let left_image_raw;
|
||||||
|
let right_image_raw;
|
||||||
|
unsafe {
|
||||||
|
image_width = ffi::getImageWidth();
|
||||||
|
image_height = ffi::getImageHeight();
|
||||||
|
bytes_per_pixel = ffi::getImageBPP();
|
||||||
|
left_image_raw = std::slice::from_raw_parts(
|
||||||
|
ffi::getImageLeft(),
|
||||||
|
(image_width * image_height * bytes_per_pixel) as usize,
|
||||||
|
);
|
||||||
|
right_image_raw = std::slice::from_raw_parts(
|
||||||
|
ffi::getImageRight(),
|
||||||
|
(image_width * image_height * bytes_per_pixel) as usize,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Build two images
|
||||||
|
let left_image = Image::new(image_width, image_height, left_image_raw);
|
||||||
|
let right_image = Image::new(image_width, image_height, right_image_raw);
|
||||||
|
|
||||||
|
Ok(DeviceFrame {
|
||||||
|
bytes_per_pixel: bytes_per_pixel as u8,
|
||||||
|
left_camera: left_image,
|
||||||
|
right_camera: right_image,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
#![feature(static_nobundle)]
|
#![feature(static_nobundle)]
|
||||||
|
|
||||||
pub mod leapmotion;
|
pub mod leapmotion;
|
||||||
|
pub mod image;
|
Reference in New Issue
Block a user