diff --git a/libodm/Cargo.toml b/libodm/Cargo.toml index 32f627e..e1277e2 100644 --- a/libodm/Cargo.toml +++ b/libodm/Cargo.toml @@ -8,3 +8,7 @@ build = "build.rs" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] + + +[build-dependencies] +cc = "1.0" \ No newline at end of file diff --git a/libodm/build.rs b/libodm/build.rs index e69de29..cda7aee 100644 --- a/libodm/build.rs +++ b/libodm/build.rs @@ -0,0 +1,3 @@ +fn main() { + cc::Build::new().file("cpp/wrapper.cc").flag("-Wno-deprecated").flag("-Wno-deprecated-copy").compile("foo"); +} diff --git a/libodm/cpp/listener.cc b/libodm/cpp/listener.cc new file mode 100644 index 0000000..f92de2d --- /dev/null +++ b/libodm/cpp/listener.cc @@ -0,0 +1,28 @@ +class LeapEventListener : public Listener +{ +public: + virtual void onConnect(const Controller &); + virtual void onDisconnect(const Controller &); + virtual void onFrame(const Controller &); +}; + +void LeapEventListener::onConnect(const Controller &controller) +{ + std::cout << "LeapMotion Controller: Connected" << std::endl; +} + +//Not dispatched when running in a debugger +void LeapEventListener::onDisconnect(const Controller &controller) +{ + std::cout << "LeapMotion Controller: Disconnected" << std::endl; +} + +void LeapEventListener::onFrame(const Controller &controller) +{ + std::cout << "New frame available" << std::endl; + Frame frame = controller.frame(); + + // Get the camera images + images = frame.images(); + +} \ No newline at end of file diff --git a/libodm/cpp/wrapper.cc b/libodm/cpp/wrapper.cc index ce5b5ac..6585d1f 100644 --- a/libodm/cpp/wrapper.cc +++ b/libodm/cpp/wrapper.cc @@ -3,66 +3,60 @@ using namespace Leap; -class LeapEventListener : public Listener +//---- Start Public Functions ----// +extern "C" { -public: - virtual void onConnect(const Controller &); - virtual void onDisconnect(const Controller &); - virtual void onFrame(const Controller &); -}; - -void LeapEventListener::onConnect(const Controller &controller) -{ - std::cout << "Connected" << std::endl; - // Enable gestures, set Config values: - controller.enableGesture(Gesture::TYPE_SWIPE); - controller.config().setFloat("Gesture.Swipe.MinLength", 200.0); - controller.config().save(); + void beginEventLoop(); + bool isControllerCreated(); + void endEventLoop(); + bool imageExists(); + int getImageHeight(); + int getImageWidth(); + int getImageBPP(); + const unsigned char *getImageLeft(); + const unsigned char *getImageRight(); } +//---- End Public Functions ----// -//Not dispatched when running in a debugger -void LeapEventListener::onDisconnect(const Controller &controller) +//---- Start Globals ----// +Controller *controller = nullptr; +ImageList images; +//---- End Globals ----// + +#include "listener.cc" + +//---- Start Public Function Impls ----// + +void beginEventLoop() { - std::cout << "Disconnected" << std::endl; -} + if (controller == nullptr) + { + // Create a controller + controller = new Controller(); -void LeapEventListener::onFrame(const Controller &controller) -{ - std::cout << "New frame available" << std::endl; - Frame frame = controller.frame(); - - // Get the camera images - ImageList images = frame.images(); + // Set device policy + controller->setPolicyFlags(Controller::POLICY_IMAGES); - // We require two images - if (images.count() != 2){ - std::cout << "Not enough images received" << std::endl; - return; + // Set up event handling + LeapEventListener listener; + controller->addListener(listener); } - - // Build a protobuf repr of the image data - FrameStreamMessage message; - message.set_frame_height(images[0].height()); - message.set_frame_width(images[0].width()); - message.set_pixel_bytes(images[0].bytesPerPixel()); - message.set_left_image((char*) images[0].data()); - message.set_right_image((char*) images[1].data()); - - } -int main() +void endEventLoop() { - - // Access to the LeapMotion device along with callback setup - Controller controller; - LeapEventListener listener; - controller.addListener(listener); - controller.setPolicy(Leap::Controller::POLICY_IMAGES); - - while(true){ - + if (controller != nullptr) + { + delete controller; } +} - return 0; -} \ No newline at end of file +bool isControllerCreated() { return controller != nullptr; } +bool imageExists() { return images.count() == 2; } +int getImageHeight() { return images[0].height(); } +int getImageWidth() { return images[0].width(); } +int getImageBPP() { return images[0].bytesPerPixel(); } +const unsigned char *getImageLeft() { return images[0].data(); } +const unsigned char *getImageRight() { return images[1].data(); } + +//---- End Public Function Impls ----//