diff --git a/interface/resources/qml/hifi/tablet/InputConfiguration.qml b/interface/resources/qml/hifi/tablet/InputConfiguration.qml index 8c183986b2..b26134c7fd 100644 --- a/interface/resources/qml/hifi/tablet/InputConfiguration.qml +++ b/interface/resources/qml/hifi/tablet/InputConfiguration.qml @@ -162,7 +162,7 @@ Rectangle { onLoaded: { - if (loader.item.hasOwnProeprty("pluginName")) { + if (loader.item.hasOwnProperty("pluginName")) { loader.item.pluginName = box.currentText } } diff --git a/interface/resources/qml/hifi/tablet/OpenVrConfiguration.qml b/interface/resources/qml/hifi/tablet/OpenVrConfiguration.qml index 434ee12f28..26ca0c644f 100644 --- a/interface/resources/qml/hifi/tablet/OpenVrConfiguration.qml +++ b/interface/resources/qml/hifi/tablet/OpenVrConfiguration.qml @@ -24,6 +24,15 @@ Rectangle { property int leftMargin: 75 property string pluginName: "" + readonly property bool feetChecked: feetBox.checked + readonly property bool hipsChecked: hipBox.checked + readonly property bool chestChecked: chestBox.checked + readonly property bool shouldersChecked: shoulderBox.checked + readonly property bool hmdHead: headBox.checked + readonly property bool headPuck: headPuckBox.checked + readonly property bool handController: handBox.checked + readonly property bool handPuck: handPuckBox.checked + HifiConstants { id: hifi } color: hifi.colors.baseGray @@ -53,6 +62,15 @@ Rectangle { width: 15 height: 15 boxRadius: 7 + + onClicked: { + if (checked) { + headPuckBox.checked = false; + } else { + checked = true; + } + composeConfigurationSettings(); + } } RalewayBold { @@ -66,6 +84,15 @@ Rectangle { width: 15 height: 15 boxRadius: 7 + + onClicked: { + if (checked) { + headBox.checked = false; + } else { + checked = true; + } + composeConfigurationSettings(); + } } RalewayBold { @@ -102,6 +129,15 @@ Rectangle { width: 15 height: 15 boxRadius: 7 + + onClicked: { + if (checked) { + handPuckBox.checked = false; + } else { + checked = true; + } + composeConfigurationSettings(); + } } RalewayBold { @@ -115,6 +151,15 @@ Rectangle { width: 12 height: 15 boxRadius: 7 + + onClicked: { + if (checked) { + handBox.checked = false; + } else { + checked = true; + } + composeConfigurationSettings(); + } } RalewayBold { @@ -151,6 +196,13 @@ Rectangle { width: 15 height: 15 boxRadius: 7 + + onClicked: { + if (hipsChecked) { + checked = true; + } + composeConfigurationSettings(); + } } RalewayBold { @@ -173,6 +225,17 @@ Rectangle { width: 15 height: 15 boxRadius: 7 + + onClicked: { + if (checked) { + feetBox.checked = true; + } + + if (chestChecked) { + checked = true; + } + composeConfigurationSettings(); + } } RalewayBold { @@ -202,6 +265,14 @@ Rectangle { width: 15 height: 15 boxRadius: 7 + + onClicked: { + if (checked) { + hipBox.checked = true; + feetBox.checked = true; + } + composeConfigurationSettings(); + } } RalewayBold { @@ -231,6 +302,14 @@ Rectangle { width: 15 height: 15 boxRadius: 7 + + onClicked: { + if (checked) { + hipBox.checked = true; + feetBox.checked = true; + } + composeConfigurationSettings(); + } } RalewayBold { @@ -300,6 +379,60 @@ Rectangle { } } + HifiControls.SpinBox { + id: timeToCalibrate + + anchors.top: calibrationButton.bottom + anchors.topMargin: 40 + anchors.left: parent.left + anchors.leftMargin: leftMargin + + label: "Time til calibration ( in seconds )" + colorScheme: hifi.colorSchemes.dark + } + + Component.onCompleted: { + var settings = InputConfiguration.configurationSettings(pluginName); + } + function composeConfigurationSettings() { + var trackerConfiguration = ""; + var overrideHead = false; + var overrideHandController = false; + + if (shouldersChecked && chestChecked) { + trackerConfiguration = "FeetHipsChestAndShoulders"; + } else if (shouldersChecked) { + trackerConfiguration = "FeetHipsAndShoulders"; + } else if (chestChecked) { + trackerConfiguration = "FeetHipsChest"; + } else if (hipsChecked) { + trackerConfiguration = "FeetAndHips"; + } else if (feetChecked) { + trackerConfiguration = "Feet"; + } + + if (headPuck) { + overrideHead = true; + } else if (hmdHead) { + overrideHead = false; + } + + if (handController) { + overrideHandController = false; + } else if (handPuck) { + overrideHandController = true; + } + + + var settingsObject = { + "trackerConfiguration": trackerConfiguration, + "overrideHead": overrideHead, + "overrideHandController": overrideHandController + } + + InputConfiguration.setConfigurationSettings(settingsObject, pluginName); + + } } diff --git a/libraries/plugins/src/plugins/InputConfiguration.cpp b/libraries/plugins/src/plugins/InputConfiguration.cpp index fcafb51c35..515033bf7b 100644 --- a/libraries/plugins/src/plugins/InputConfiguration.cpp +++ b/libraries/plugins/src/plugins/InputConfiguration.cpp @@ -45,14 +45,25 @@ QString InputConfiguration::configurationLayout(QString pluginName) { return sourcePath; } -void InputConfiguration::configurationSettings(QJsonObject configurationSettings, QString pluginName) { - qDebug() << configurationSettings["Test"]; +void InputConfiguration::setConfigurationSettings(QJsonObject configurationSettings, QString pluginName) { + for (auto plugin : PluginManager::getInstance()->getInputPlugins()) { + if (plugin->getName() == pluginName) { + plugin->setConfigurationSettings(configurationSettings); + } + } +} + +QJsonObject InputConfiguration::configurationSettings(QString pluginName) { + return QJsonObject(); } void InputConfiguration::calibratePlugin(QString pluginName) { for (auto plugin : PluginManager::getInstance()->getInputPlugins()) { if (plugin->getName() == pluginName) { - //calibrtate plugin + plugin->calibrate(); } } } + +void InputConfiguration::calibrated() { +} diff --git a/libraries/plugins/src/plugins/InputConfiguration.h b/libraries/plugins/src/plugins/InputConfiguration.h index a560c02e5a..2171afca34 100644 --- a/libraries/plugins/src/plugins/InputConfiguration.h +++ b/libraries/plugins/src/plugins/InputConfiguration.h @@ -25,8 +25,10 @@ public: Q_INVOKABLE QStringList inputPlugins(); Q_INVOKABLE QStringList activeInputPlugins(); Q_INVOKABLE QString configurationLayout(QString pluginName); - Q_INVOKABLE void configurationSettings(QJsonObject configurationSettings, QString pluginName); + Q_INVOKABLE void setConfigurationSettings(QJsonObject configurationSettings, QString pluginName); Q_INVOKABLE void calibratePlugin(QString pluginName); + Q_INVOKABLE QJsonObject configurationSettings(QString pluginName); + void calibrated(); }; #endif diff --git a/libraries/plugins/src/plugins/InputPlugin.h b/libraries/plugins/src/plugins/InputPlugin.h index 1850dcbc18..e73a047efa 100644 --- a/libraries/plugins/src/plugins/InputPlugin.h +++ b/libraries/plugins/src/plugins/InputPlugin.h @@ -26,8 +26,9 @@ public: // If an input plugin is only a single device, it will only return it's primary name. virtual QStringList getSubdeviceNames() { return { getName() }; }; virtual bool isHandController() const = 0; - virtual void configurationSettings(const QJsonObject configurationSettings) { } + virtual void setConfigurationSettings(const QJsonObject configurationSettings) { } + virtual QJsonObject configurationSettings() { return QJsonObject(); } virtual QString configurationLayout() { return QString(); } - virtual void calibrate() {} + virtual bool calibrate() { return false; } virtual bool configurable() { return false; } }; diff --git a/plugins/openvr/src/ViveControllerManager.cpp b/plugins/openvr/src/ViveControllerManager.cpp index 2337c6161b..87bd8ac1a5 100644 --- a/plugins/openvr/src/ViveControllerManager.cpp +++ b/plugins/openvr/src/ViveControllerManager.cpp @@ -120,7 +120,18 @@ bool ViveControllerManager::isSupported() const { return openVrSupported(); } -void ViveControllerManager::configurationSettings(const QJsonObject configurationSettings) { +void ViveControllerManager::setConfigurationSettings(const QJsonObject configurationSettings) { + if (isSupported()) { + _inputDevice->configureCalibrationSettings(configurationSettings); + } +} + +QJsonObject ViveControllerManager::configurationSettings() { + if (isSupported()) { + return _inputDevice->configurationSettings(); + } + + return QJsonObject(); } QString ViveControllerManager::configurationLayout() { @@ -281,6 +292,44 @@ void ViveControllerManager::InputDevice::update(float deltaTime, const controlle _lastSimPoseData = _nextSimPoseData; } +void ViveControllerManager::InputDevice::configureCalibrationSettings(const QJsonObject configurationSettings) { + Locker locker(_lock); + + if (!configurationSettings.empty()) { + auto iter = configurationSettings.begin(); + auto end = configurationSettings.end(); + while (iter != end) { + if (iter.key() == "trackerConfiguration") { + setConfigFromString(iter.value().toString()); + } else if (iter.key() == "overrideHead") { + bool overrideHead = iter.value().toBool(); + if (overrideHead) { + _headConfig = HeadConfig::Puck; + } else { + _headConfig = HeadConfig::HMD; + } + } else if (iter.key() == "overrideHandController") { + bool overrideHands = iter.value().toBool(); + if (overrideHands) { + _handConfig = HandConfig::Pucks; + } else { + _handConfig = HandConfig::HandController; + } + } + iter++; + } + } +} + +QJsonObject ViveControllerManager::InputDevice::configurationSettings() { + Locker locker(_lock); + QJsonObject configurationSettings; + configurationSettings["trackerConfiguration"] = configToString(_config); + configurationSettings["HMDHead"] = (_headConfig == HeadConfig::HMD) ? true : false; + configurationSettings["handController"] = (_handConfig == HandConfig::HandController) ? true : false; + return configurationSettings; +} + void ViveControllerManager::InputDevice::handleTrackedObject(uint32_t deviceIndex, const controller::InputCalibrationData& inputCalibrationData) { uint32_t poseIndex = controller::TRACKED_OBJECT_00 + deviceIndex; printDeviceTrackingResultChange(deviceIndex); diff --git a/plugins/openvr/src/ViveControllerManager.h b/plugins/openvr/src/ViveControllerManager.h index a4ec35c400..257baf9fb5 100644 --- a/plugins/openvr/src/ViveControllerManager.h +++ b/plugins/openvr/src/ViveControllerManager.h @@ -44,7 +44,8 @@ public: bool configurable() override { return true; } QString configurationLayout() override; - void configurationSettings(const QJsonObject configurationSettings) override; + void setConfigurationSettings(const QJsonObject configurationSettings) override; + QJsonObject configurationSettings() override; bool activate() override; void deactivate() override; @@ -70,6 +71,8 @@ private: void calibrateOrUncalibrate(const controller::InputCalibrationData& inputCalibration); void calibrate(const controller::InputCalibrationData& inputCalibration); void uncalibrate(); + void configureCalibrationSettings(const QJsonObject configurationSettings); + QJsonObject configurationSettings(); controller::Pose addOffsetToPuckPose(int joint) const; glm::mat4 recalculateDefaultToReferenceForHeadPuck(const controller::InputCalibrationData& inputCalibration); void updateCalibratedLimbs(); @@ -128,10 +131,23 @@ private: FeetHipsAndChest, FeetHipsAndShoulders, FeetHipsChestAndHead, - FeetHipsAndHead + FeetHipsAndHead, }; + + enum class HeadConfig { + HMD, + Puck + }; + + enum class HandConfig { + HandController, + Pucks + }; + Config _config { Config::Auto }; Config _preferedConfig { Config::Auto }; + HeadConfig _headConfig { HeadConfig::HMD }; + HandConfig _handConfig { HandConfig::HandController }; FilteredStick _filteredLeftStick; FilteredStick _filteredRightStick; @@ -157,6 +173,7 @@ private: bool _timeTilCalibrationSet { false }; bool _calibrate { false }; bool _overrideHead { false }; + bool _overrideHands { false }; mutable std::recursive_mutex _lock; QString configToString(Config config);