summaryrefslogtreecommitdiffstats
path: root/matleap.h
diff options
context:
space:
mode:
Diffstat (limited to 'matleap.h')
-rwxr-xr-xmatleap.h96
1 files changed, 96 insertions, 0 deletions
diff --git a/matleap.h b/matleap.h
new file mode 100755
index 0000000..24eae30
--- /dev/null
+++ b/matleap.h
@@ -0,0 +1,96 @@
+/// @file matleap.h
+/// @brief leap motion controller interface
+/// @author Jeff Perry <jeffsp@gmail.com>
+/// @version 1.0
+/// @date 2013-09-12
+
+#ifndef MATLEAP_H
+#define MATLEAP_H
+
+#define MAJOR_REVISION 4
+#define MINOR_REVISION 0
+
+#include "Leap.h"
+#include "mex.h"
+
+#include <unistd.h>
+
+namespace matleap {
+
+/// @brief a leap frame
+ struct frame {
+ int64_t id;
+ int64_t timestamp;
+ uint32_t detectedHands;
+ Leap::HandList hands;
+ bool has_gesture;
+ };
+
+/// @brief leap frame grabber interface
+ class frame_grabber {
+ private:
+ bool debug;
+ Leap::Controller controllerConnection;
+ frame current_frame;
+
+ public:
+ /// @brief constructor
+ frame_grabber()
+ : debug(false) {
+ }
+
+ void open_connection() {
+ mexPrintf("Waiting for connection");
+ while (!controllerConnection.isConnected()) {
+ mexPrintf(".");
+ usleep(500000);
+ }
+ //controllerConnection.enableGesture(Leap::Gesture::TYPE_SWIPE);
+ controllerConnection.enableGesture(Leap::Gesture::TYPE_CIRCLE);
+ //controllerConnection.enableGesture(Leap::Gesture::TYPE_KEY_TAP);
+ //controllerConnection.enableGesture(Leap::Gesture::TYPE_SCREEN_TAP);
+ mexPrintf(" Connected!\n");
+ // TODO: check if needed
+ //LeapSetPolicyFlags(*controllerConnection, eLeapPolicyFlag_BackgroundFrames, 0);
+ }
+
+ void close_connection() {
+ mexPrintf("Good bye.");
+ }
+
+ /// @brief destructor
+ ~frame_grabber() {
+ if (debug)
+ mexPrintf("Closing matleap frame grabber\n");
+ }
+
+ /// @brief debug member access
+ ///
+ /// @param flag turn it on/off
+ void set_debug(bool flag) {
+ if (flag == debug)
+ return;
+ if (flag)
+ mexPrintf("Setting debug on\n");
+ debug = flag;
+ }
+
+ /// @brief get a frame from the controller
+ ///
+ /// @return the frame
+ frame const &get_frame() {
+ auto const &frame = controllerConnection.frame();
+ current_frame.id = frame.id();
+ if (debug)
+ mexPrintf("Got frame with id %d\n", current_frame.id);
+ current_frame.timestamp = frame.timestamp();
+ current_frame.detectedHands = frame.hands().count();
+ current_frame.hands = frame.hands();
+ current_frame.has_gesture = !frame.gestures().isEmpty();
+ return current_frame;
+ }
+ };
+
+} // namespace matleap
+
+#endif