From 0d986b8dc26073b3c2ddb12e30c7886ff4e3e4ba Mon Sep 17 00:00:00 2001 From: David Rowe Date: Sat, 17 Jun 2017 14:43:32 +1200 Subject: [PATCH] Signal when Leap Motion is connected --- plugins/hifiLeapMotion/src/LeapMotionPlugin.cpp | 14 ++++++++++++++ plugins/hifiLeapMotion/src/LeapMotionPlugin.h | 2 ++ 2 files changed, 16 insertions(+) diff --git a/plugins/hifiLeapMotion/src/LeapMotionPlugin.cpp b/plugins/hifiLeapMotion/src/LeapMotionPlugin.cpp index 34913cb415..b60c2f69cf 100644 --- a/plugins/hifiLeapMotion/src/LeapMotionPlugin.cpp +++ b/plugins/hifiLeapMotion/src/LeapMotionPlugin.cpp @@ -32,7 +32,21 @@ void LeapMotionPlugin::pluginUpdate(float deltaTime, const controller::InputCali return; } + const auto frame = _controller.frame(); + const auto frameID = frame.id(); + if (_lastFrameID >= frameID) { + // Leap Motion not connected or duplicate frame. + return; + } + + if (!_hasLeapMotionBeenConnected) { + emit deviceConnected(getName()); + _hasLeapMotionBeenConnected = true; + } + // TODO + + _lastFrameID = frameID; } controller::Input::NamedVector LeapMotionPlugin::InputDevice::getAvailableInputs() const { diff --git a/plugins/hifiLeapMotion/src/LeapMotionPlugin.h b/plugins/hifiLeapMotion/src/LeapMotionPlugin.h index 7db4f4d8d7..ed5a3c94fe 100644 --- a/plugins/hifiLeapMotion/src/LeapMotionPlugin.h +++ b/plugins/hifiLeapMotion/src/LeapMotionPlugin.h @@ -63,6 +63,8 @@ private: Leap::Controller _controller; + bool _hasLeapMotionBeenConnected { false }; + int64_t _lastFrameID { -1 }; }; #endif // hifi_LeapMotionPlugin_h