Make Vive PRO Eye code Windows-only

This commit is contained in:
David Rowe 2020-06-29 11:12:22 +12:00
parent 901b3f5234
commit cc73528d0b
3 changed files with 32 additions and 5 deletions

View file

@ -15,9 +15,9 @@ if ((WIN32 OR UNIX AND NOT APPLE) AND NOT USE_GLES)
include_hifi_library_headers(octree) include_hifi_library_headers(octree)
target_openvr() target_openvr()
target_sranipal()
target_aristo()
if (WIN32) if (WIN32)
target_sranipal()
target_aristo()
target_link_libraries(${TARGET_NAME} Winmm.lib) target_link_libraries(${TARGET_NAME} Winmm.lib)
endif() endif()
endif() endif()

View file

@ -19,10 +19,12 @@
#pragma warning( disable : 4334 ) #pragma warning( disable : 4334 )
#endif #endif
#ifdef VIVE_PRO_EYE
#include <SRanipal.h> #include <SRanipal.h>
#include <SRanipal_Eye.h> #include <SRanipal_Eye.h>
#include <SRanipal_Enums.h> #include <SRanipal_Enums.h>
#include <interface_gesture.hpp> #include <interface_gesture.hpp>
#endif
#ifdef _WIN32 #ifdef _WIN32
#pragma warning( pop ) #pragma warning( pop )
@ -74,6 +76,7 @@ static const int SECOND_FOOT = 1;
static const int HIP = 2; static const int HIP = 2;
static const int CHEST = 3; static const int CHEST = 3;
#ifdef VIVE_PRO_EYE
enum ViveHandJointIndex { enum ViveHandJointIndex {
HAND = 0, HAND = 0,
THUMB_1, THUMB_1,
@ -99,6 +102,7 @@ enum ViveHandJointIndex {
Size Size
}; };
#endif
const char* ViveControllerManager::NAME { "OpenVR" }; const char* ViveControllerManager::NAME { "OpenVR" };
@ -168,6 +172,7 @@ static glm::mat4 calculateResetMat() {
return glm::mat4(); return glm::mat4();
} }
#ifdef VIVE_PRO_EYE
class ViveProEyeReadThread : public QThread { class ViveProEyeReadThread : public QThread {
public: public:
ViveProEyeReadThread() { ViveProEyeReadThread() {
@ -211,6 +216,7 @@ public:
QMutex eyeDataMutex; QMutex eyeDataMutex;
EyeDataBuffer eyeDataBuffer; EyeDataBuffer eyeDataBuffer;
}; };
#endif
static QString outOfRangeDataStrategyToString(ViveControllerManager::OutOfRangeDataStrategy strategy) { static QString outOfRangeDataStrategyToString(ViveControllerManager::OutOfRangeDataStrategy strategy) {
@ -323,7 +329,7 @@ bool areBothHandControllersActive(vr::IVRSystem*& system) {
isHandControllerActive(system, vr::TrackedControllerRole_RightHand); isHandControllerActive(system, vr::TrackedControllerRole_RightHand);
} }
#ifdef VIVE_PRO_EYE
void ViveControllerManager::enableGestureDetection() { void ViveControllerManager::enableGestureDetection() {
if (_viveCameraHandTracker) { if (_viveCameraHandTracker) {
return; return;
@ -368,6 +374,7 @@ void ViveControllerManager::disableGestureDetection() {
StopGestureDetection(); StopGestureDetection();
_viveCameraHandTracker = false; _viveCameraHandTracker = false;
} }
#endif
bool ViveControllerManager::activate() { bool ViveControllerManager::activate() {
InputPlugin::activate(); InputPlugin::activate();
@ -389,6 +396,7 @@ bool ViveControllerManager::activate() {
userInputMapper->registerDevice(_inputDevice); userInputMapper->registerDevice(_inputDevice);
_registeredWithInputMapper = true; _registeredWithInputMapper = true;
#ifdef VIVE_PRO_EYE
if (ViveSR::anipal::Eye::IsViveProEye()) { if (ViveSR::anipal::Eye::IsViveProEye()) {
qDebug() << "Vive Pro eye-tracking detected"; qDebug() << "Vive Pro eye-tracking detected";
@ -409,6 +417,7 @@ bool ViveControllerManager::activate() {
_viveProEyeReadThread->start(QThread::HighPriority); _viveProEyeReadThread->start(QThread::HighPriority);
} }
} }
#endif
return true; return true;
} }
@ -431,12 +440,14 @@ void ViveControllerManager::deactivate() {
userInputMapper->removeDevice(_inputDevice->_deviceID); userInputMapper->removeDevice(_inputDevice->_deviceID);
_registeredWithInputMapper = false; _registeredWithInputMapper = false;
#ifdef VIVE_PRO_EYE
if (_viveProEyeReadThread) { if (_viveProEyeReadThread) {
_viveProEyeReadThread->quit = true; _viveProEyeReadThread->quit = true;
_viveProEyeReadThread->wait(); _viveProEyeReadThread->wait();
_viveProEyeReadThread = nullptr; _viveProEyeReadThread = nullptr;
ViveSR::anipal::Release(ViveSR::anipal::Eye::ANIPAL_TYPE_EYE); ViveSR::anipal::Release(ViveSR::anipal::Eye::ANIPAL_TYPE_EYE);
} }
#endif
saveSettings(); saveSettings();
} }
@ -449,6 +460,7 @@ bool ViveControllerManager::isHeadControllerMounted() const {
return activityLevel == vr::k_EDeviceActivityLevel_UserInteraction; return activityLevel == vr::k_EDeviceActivityLevel_UserInteraction;
} }
#ifdef VIVE_PRO_EYE
void ViveControllerManager::invalidateEyeInputs() { void ViveControllerManager::invalidateEyeInputs() {
_inputDevice->_poseStateMap[controller::LEFT_EYE].valid = false; _inputDevice->_poseStateMap[controller::LEFT_EYE].valid = false;
_inputDevice->_poseStateMap[controller::RIGHT_EYE].valid = false; _inputDevice->_poseStateMap[controller::RIGHT_EYE].valid = false;
@ -456,7 +468,6 @@ void ViveControllerManager::invalidateEyeInputs() {
_inputDevice->_axisStateMap[controller::EYEBLINK_R].valid = false; _inputDevice->_axisStateMap[controller::EYEBLINK_R].valid = false;
} }
void ViveControllerManager::updateEyeTracker(float deltaTime, const controller::InputCalibrationData& inputCalibrationData) { void ViveControllerManager::updateEyeTracker(float deltaTime, const controller::InputCalibrationData& inputCalibrationData) {
if (!isHeadControllerMounted()) { if (!isHeadControllerMounted()) {
invalidateEyeInputs(); invalidateEyeInputs();
@ -758,6 +769,7 @@ void ViveControllerManager::updateCameraHandTracker(float deltaTime,
} }
_lastHandTrackerFrameIndex = handTrackerFrameIndex; _lastHandTrackerFrameIndex = handTrackerFrameIndex;
} }
#endif
void ViveControllerManager::pluginUpdate(float deltaTime, const controller::InputCalibrationData& inputCalibrationData) { void ViveControllerManager::pluginUpdate(float deltaTime, const controller::InputCalibrationData& inputCalibrationData) {
@ -796,11 +808,14 @@ void ViveControllerManager::pluginUpdate(float deltaTime, const controller::Inpu
_registeredWithInputMapper = true; _registeredWithInputMapper = true;
} }
#ifdef VIVE_PRO_EYE
if (_viveProEye) { if (_viveProEye) {
updateEyeTracker(deltaTime, inputCalibrationData); updateEyeTracker(deltaTime, inputCalibrationData);
} }
updateCameraHandTracker(deltaTime, inputCalibrationData); updateCameraHandTracker(deltaTime, inputCalibrationData);
#endif
} }
void ViveControllerManager::loadSettings() { void ViveControllerManager::loadSettings() {

View file

@ -25,12 +25,18 @@
#include <plugins/InputPlugin.h> #include <plugins/InputPlugin.h>
#include "OpenVrHelpers.h" #include "OpenVrHelpers.h"
#ifdef Q_OS_WIN
#define VIVE_PRO_EYE
#endif
using PuckPosePair = std::pair<uint32_t, controller::Pose>; using PuckPosePair = std::pair<uint32_t, controller::Pose>;
namespace vr { namespace vr {
class IVRSystem; class IVRSystem;
} }
#ifdef VIVE_PRO_EYE
class ViveProEyeReadThread; class ViveProEyeReadThread;
class EyeDataBuffer { class EyeDataBuffer {
@ -45,7 +51,7 @@ public:
float leftEyeOpenness { 0.0f }; float leftEyeOpenness { 0.0f };
float rightEyeOpenness { 0.0f }; float rightEyeOpenness { 0.0f };
}; };
#endif
class ViveControllerManager : public InputPlugin { class ViveControllerManager : public InputPlugin {
@ -66,8 +72,10 @@ public:
bool isHeadController() const override { return true; } bool isHeadController() const override { return true; }
bool isHeadControllerMounted() const; bool isHeadControllerMounted() const;
#ifdef VIVE_PRO_EYE
void enableGestureDetection(); void enableGestureDetection();
void disableGestureDetection(); void disableGestureDetection();
#endif
bool activate() override; bool activate() override;
void deactivate() override; void deactivate() override;
@ -75,9 +83,11 @@ public:
QString getDeviceName() override { return QString::fromStdString(_inputDevice->_headsetName); } QString getDeviceName() override { return QString::fromStdString(_inputDevice->_headsetName); }
void pluginFocusOutEvent() override { _inputDevice->focusOutEvent(); } void pluginFocusOutEvent() override { _inputDevice->focusOutEvent(); }
#ifdef VIVE_PRO_EYE
void invalidateEyeInputs(); void invalidateEyeInputs();
void updateEyeTracker(float deltaTime, const controller::InputCalibrationData& inputCalibrationData); void updateEyeTracker(float deltaTime, const controller::InputCalibrationData& inputCalibrationData);
void updateCameraHandTracker(float deltaTime, const controller::InputCalibrationData& inputCalibrationData); void updateCameraHandTracker(float deltaTime, const controller::InputCalibrationData& inputCalibrationData);
#endif
void pluginUpdate(float deltaTime, const controller::InputCalibrationData& inputCalibrationData) override; void pluginUpdate(float deltaTime, const controller::InputCalibrationData& inputCalibrationData) override;
virtual void saveSettings() const override; virtual void saveSettings() const override;
@ -252,6 +262,7 @@ private:
vr::IVRSystem* _system { nullptr }; vr::IVRSystem* _system { nullptr };
std::shared_ptr<InputDevice> _inputDevice { std::make_shared<InputDevice>(_system) }; std::shared_ptr<InputDevice> _inputDevice { std::make_shared<InputDevice>(_system) };
#ifdef VIVE_PRO_EYE
bool _viveProEye { false }; bool _viveProEye { false };
std::shared_ptr<ViveProEyeReadThread> _viveProEyeReadThread; std::shared_ptr<ViveProEyeReadThread> _viveProEyeReadThread;
EyeDataBuffer _prevEyeData; EyeDataBuffer _prevEyeData;
@ -268,6 +279,7 @@ private:
void trackFinger(int hand, int jointIndex1, int jointIndex2, int jointIndex3, int jointIndex4, void trackFinger(int hand, int jointIndex1, int jointIndex2, int jointIndex3, int jointIndex4,
controller::StandardPoseChannel joint1, controller::StandardPoseChannel joint2, controller::StandardPoseChannel joint1, controller::StandardPoseChannel joint2,
controller::StandardPoseChannel joint3, controller::StandardPoseChannel joint4); controller::StandardPoseChannel joint3, controller::StandardPoseChannel joint4);
#endif
static const char* NAME; static const char* NAME;
}; };