From aa645af744719a665f523f2bd810c7053e2c0785 Mon Sep 17 00:00:00 2001 From: Dante Ruiz Date: Wed, 6 Feb 2019 09:19:36 -0800 Subject: [PATCH] fix quest controllers --- .../src/OculusMobileControllerManager.cpp | 38 ++++++++++++++++++- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/libraries/oculusMobilePlugin/src/OculusMobileControllerManager.cpp b/libraries/oculusMobilePlugin/src/OculusMobileControllerManager.cpp index 8de563ee4c..b995ef1fb3 100644 --- a/libraries/oculusMobilePlugin/src/OculusMobileControllerManager.cpp +++ b/libraries/oculusMobilePlugin/src/OculusMobileControllerManager.cpp @@ -171,6 +171,8 @@ private: void handleHeadPose(float deltaTime, const controller::InputCalibrationData& inputCalibrationData, const ovrRigidBodyPosef& headPose); + void reconnectTouchControllers(ovrMobile* session); + // perform an action when the TouchDevice mutex is acquired. using Locker = std::unique_lock; @@ -637,7 +639,6 @@ controller::Input::NamedVector OculusMobileInputDevice::getAvailableInputs() con makePair(RIGHT_THUMB_UP, "RightThumbUp"), makePair(LEFT_INDEX_POINT, "LeftIndexPoint"), makePair(RIGHT_INDEX_POINT, "RightIndexPoint"), - makePair(BACK, "LeftApplicationMenu"), makePair(START, "RightApplicationMenu"), }; @@ -665,8 +666,41 @@ OculusMobileInputDevice::OculusMobileInputDevice(ovrMobile* session, const std:: void OculusMobileInputDevice::updateHands(ovrMobile* session) { _headTracking = vrapi_GetPredictedTracking2(session, 0.0); + + bool touchControllerNotConnected = false; for (auto& hand : _hands) { hand.update(session); + + if (hand.stateResult < 0 || hand.trackingResult < 0) { + touchControllerNotConnected = true; + } + } + + if (touchControllerNotConnected) { + reconnectTouchControllers(session); + } +} + +void OculusMobileInputDevice::reconnectTouchControllers(ovrMobile* session) { + uint32_t deviceIndex { 0 }; + ovrInputCapabilityHeader capsHeader; + while (vrapi_EnumerateInputDevices(session, deviceIndex, &capsHeader) >= 0) { + if (capsHeader.Type == ovrControllerType_TrackedRemote) { + ovrInputTrackedRemoteCapabilities caps; + caps.Header = capsHeader; + vrapi_GetInputDeviceCapabilities(session, &caps.Header); + + if (caps.ControllerCapabilities & ovrControllerCaps_LeftHand || caps.ControllerCapabilities & ovrControllerCaps_RightHand) { + size_t handIndex = caps.ControllerCapabilities & ovrControllerCaps_LeftHand ? 0 : 1; + HandData& handData = _hands[handIndex]; + handData.state.Header.ControllerType = ovrControllerType_TrackedRemote; + handData.valid = true; + handData.caps = caps; + handData.initialized = true; + handData.update(session); + } + } + ++deviceIndex; } } @@ -691,4 +725,4 @@ InputPluginList getInputPlugins() { } } return result; -} \ No newline at end of file +}