diff --git a/interface/resources/controllers/standard.json b/interface/resources/controllers/standard.json index 69193b40c5..4ef0a1b90f 100644 --- a/interface/resources/controllers/standard.json +++ b/interface/resources/controllers/standard.json @@ -6,7 +6,7 @@ { "from": "Standard.RX", "to": "Actions.Yaw" }, { "from": "Standard.RY", "to": "Actions.Pitch" }, - { "from": [ "Standard.DU", "Standard.DU", "Standard.DU", "Standard.DD" ], "to": "Standard.LeftPrimaryThumb" }, + { "from": [ "Standard.DU", "Standard.DL", "Standard.DR", "Standard.DD" ], "to": "Standard.LeftPrimaryThumb" }, { "from": "Standard.Back", "to": "Standard.LeftSecondaryThumb" }, { "from": [ "Standard.A", "Standard.B", "Standard.X", "Standard.Y" ], "to": "Standard.RightPrimaryThumb" }, diff --git a/libraries/input-plugins/src/input-plugins/SixenseManager.cpp b/libraries/input-plugins/src/input-plugins/SixenseManager.cpp index 008645abfe..d5ff4c93a8 100644 --- a/libraries/input-plugins/src/input-plugins/SixenseManager.cpp +++ b/libraries/input-plugins/src/input-plugins/SixenseManager.cpp @@ -67,11 +67,7 @@ const float DEFAULT_REACH_LENGTH = 1.5f; SixenseManager::SixenseManager() : InputDevice("Hydra"), - _reachLength(DEFAULT_REACH_LENGTH), -#ifdef __APPLE__ - _sixenseLibrary(nullptr), -#endif - _hydrasConnected(false) + _reachLength(DEFAULT_REACH_LENGTH) { } @@ -94,6 +90,9 @@ void SixenseManager::activate() { [this] (bool clicked) { this->setSixenseFilter(clicked); }, true, true); + auto userInputMapper = DependencyManager::get(); + userInputMapper->registerDevice(this); + #ifdef __APPLE__ if (!_sixenseLibrary) { @@ -121,9 +120,6 @@ void SixenseManager::activate() { #endif loadSettings(); sixenseInit(); - _activated = true; - auto userInputMapper = DependencyManager::get(); - userInputMapper->registerDevice(this); #endif } @@ -134,13 +130,19 @@ void SixenseManager::deactivate() { CONTAINER->removeMenu(MENU_PATH); _poseStateMap.clear(); + _collectedSamples.clear(); + + if (_deviceID != controller::Input::INVALID_DEVICE) { + auto userInputMapper = DependencyManager::get(); + userInputMapper->removeDevice(_deviceID); + _deviceID = controller::Input::INVALID_DEVICE; + } #ifdef __APPLE__ SixenseBaseFunction sixenseExit = (SixenseBaseFunction)_sixenseLibrary->resolve("sixenseExit"); #endif sixenseExit(); - _activated = false; #ifdef __APPLE__ delete _sixenseLibrary; @@ -176,30 +178,32 @@ void SixenseManager::update(float deltaTime, bool jointsCaptured) { auto userInputMapper = DependencyManager::get(); + static const float MAX_DISCONNECTED_TIME = 2.0f; + static bool disconnected { false }; + static float disconnectedInterval { 0.0f }; if (sixenseGetNumActiveControllers() == 0) { - if (_hydrasConnected) { - qCDebug(inputplugins) << "hydra disconnected" << _badDataCount; - if (_badDataCount++ < _allowedBadDataCount) { // gotta get some no-active in a row before we shut things down - return; - } + if (!disconnected) { + disconnectedInterval += deltaTime; } - _hydrasConnected = false; - if (_deviceID != 0) { - userInputMapper->removeDevice(_deviceID); - _deviceID = 0; + if (disconnectedInterval > MAX_DISCONNECTED_TIME) { + disconnected = true; + _axisStateMap.clear(); + _buttonPressedMap.clear(); _poseStateMap.clear(); _collectedSamples.clear(); } return; } - PerformanceTimer perfTimer("sixense"); - if (!_hydrasConnected) { - _hydrasConnected = true; - _badDataCount = 0; - UserActivityLogger::getInstance().connectedDevice("spatial_controller", "hydra"); + if (disconnected) { + disconnected = 0; + disconnectedInterval = 0.0f; } + PerformanceTimer perfTimer("sixense"); + // FIXME send this message once when we've positively identified hydra hardware + //UserActivityLogger::getInstance().connectedDevice("spatial_controller", "hydra"); + #ifdef __APPLE__ SixenseBaseFunction sixenseGetMaxControllers = (SixenseBaseFunction) _sixenseLibrary->resolve("sixenseGetMaxControllers"); @@ -600,7 +604,6 @@ void SixenseManager::saveSettings() const { settings.setVec3Value(QString("avatarPosition"), _avatarPosition); settings.setQuatValue(QString("avatarRotation"), _avatarRotation); settings.setValue(QString("reachLength"), QVariant(_reachLength)); - settings.setValue(QString("allowedHydraFailures"), 120); } settings.endGroup(); } @@ -613,7 +616,6 @@ void SixenseManager::loadSettings() { settings.getVec3ValueIfValid(QString("avatarPosition"), _avatarPosition); settings.getQuatValueIfValid(QString("avatarRotation"), _avatarRotation); settings.getFloatValueIfValid(QString("reachLength"), _reachLength); - _allowedBadDataCount = settings.value(QString("allowedHydraFailures"), 120).toInt(); } settings.endGroup(); } diff --git a/libraries/input-plugins/src/input-plugins/SixenseManager.h b/libraries/input-plugins/src/input-plugins/SixenseManager.h index aab475963c..a44f527238 100644 --- a/libraries/input-plugins/src/input-plugins/SixenseManager.h +++ b/libraries/input-plugins/src/input-plugins/SixenseManager.h @@ -104,18 +104,11 @@ private: MovingAverageMap _collectedSamples; #ifdef __APPLE__ - QLibrary* _sixenseLibrary; + QLibrary* _sixenseLibrary { nullptr }; #endif - bool _hydrasConnected; - int _badDataCount; - int _allowedBadDataCount; - static const QString NAME; static const QString HYDRA_ID_STRING; - - bool _activated = false; - }; #endif // hifi_SixenseManager_h