From 43659074624096d9757d508d6b793882f04b5b59 Mon Sep 17 00:00:00 2001 From: Dante Ruiz Date: Wed, 10 May 2017 22:12:11 +0100 Subject: [PATCH 1/2] drop down puck configuration for gernal settings --- .../hifi/tablet/TabletGeneralPreferences.qml | 2 +- .../tabletWindows/TabletPreferencesDialog.qml | 4 +- plugins/openvr/src/ViveControllerManager.cpp | 99 +++++++++++++++++-- plugins/openvr/src/ViveControllerManager.h | 13 ++- 4 files changed, 102 insertions(+), 16 deletions(-) diff --git a/interface/resources/qml/hifi/tablet/TabletGeneralPreferences.qml b/interface/resources/qml/hifi/tablet/TabletGeneralPreferences.qml index 85377aaeda..17d3f1b959 100644 --- a/interface/resources/qml/hifi/tablet/TabletGeneralPreferences.qml +++ b/interface/resources/qml/hifi/tablet/TabletGeneralPreferences.qml @@ -33,6 +33,6 @@ StackView { TabletPreferencesDialog { id: root objectName: "TabletGeneralPreferences" - showCategories: ["UI", "Snapshots", "Scripts", "Privacy", "Octree", "HMD", "Sixense Controllers", "Perception Neuron", "Kinect"] + showCategories: ["UI", "Snapshots", "Scripts", "Privacy", "Octree", "HMD", "Sixense Controllers", "Perception Neuron", "Kinect", "Vive Pucks Configuration"] } } diff --git a/interface/resources/qml/hifi/tablet/tabletWindows/TabletPreferencesDialog.qml b/interface/resources/qml/hifi/tablet/tabletWindows/TabletPreferencesDialog.qml index 2c8f6d9ea0..3e497b053e 100644 --- a/interface/resources/qml/hifi/tablet/tabletWindows/TabletPreferencesDialog.qml +++ b/interface/resources/qml/hifi/tablet/tabletWindows/TabletPreferencesDialog.qml @@ -136,8 +136,8 @@ Item { for (var i = 0; i < sections.length; i++) { totalHeight += sections[i].height + sections[i].getPreferencesHeight(); } - console.log(totalHeight); - return totalHeight; + var bottomPadding = 100; + return (totalHeight + bottomPadding); } } } diff --git a/plugins/openvr/src/ViveControllerManager.cpp b/plugins/openvr/src/ViveControllerManager.cpp index 6e5697730b..5dd4c71194 100644 --- a/plugins/openvr/src/ViveControllerManager.cpp +++ b/plugins/openvr/src/ViveControllerManager.cpp @@ -22,6 +22,8 @@ #include #include #include +#include +#include #include #include #include @@ -262,14 +264,21 @@ void ViveControllerManager::InputDevice::calibrate(const controller::InputCalibr glm::mat4 defaultToReferenceMat = currentHead * glm::inverse(inputCalibration.defaultHeadMat); int puckCount = (int)_validTrackedObjects.size(); - if (puckCount == MIN_PUCK_COUNT) { - _config = Config::Feet; - } else if (puckCount == MIN_FEET_AND_HIPS) { - _config = Config::FeetAndHips; - } else if (puckCount >= MIN_FEET_HIPS_CHEST) { - _config = Config::FeetHipsAndChest; - } else { + _config = _preferedConfig; + if (_config != Config::Auto && puckCount < MIN_PUCK_COUNT) { + uncalibrate(); return; + } else if (_config == Config::Auto){ + if (puckCount == MIN_PUCK_COUNT) { + _config = Config::Feet; + } else if (puckCount == MIN_FEET_AND_HIPS) { + _config = Config::FeetAndHips; + } else if (puckCount >= MIN_FEET_HIPS_CHEST) { + _config = Config::FeetHipsAndChest; + } else { + uncalibrate(); + return; + } } std::sort(_validTrackedObjects.begin(), _validTrackedObjects.end(), sortPucksYPosition); @@ -296,19 +305,23 @@ void ViveControllerManager::InputDevice::calibrate(const controller::InputCalibr if (_config == Config::Feet) { // done - } else if (_config == Config::FeetAndHips) { + } else if (_config == Config::FeetAndHips && puckCount >= MIN_FEET_AND_HIPS) { _jointToPuckMap[controller::HIPS] = _validTrackedObjects[HIP].first; _pucksOffset[_validTrackedObjects[HIP].first] = computeOffset(defaultToReferenceMat, inputCalibration.defaultHips, _validTrackedObjects[HIP].second); - } else if (_config == Config::FeetHipsAndChest) { + } else if (_config == Config::FeetHipsAndChest && puckCount >= MIN_FEET_HIPS_CHEST) { _jointToPuckMap[controller::HIPS] = _validTrackedObjects[HIP].first; _pucksOffset[_validTrackedObjects[HIP].first] = computeOffset(defaultToReferenceMat, inputCalibration.defaultHips, _validTrackedObjects[HIP].second); _jointToPuckMap[controller::SPINE2] = _validTrackedObjects[CHEST].first; _pucksOffset[_validTrackedObjects[CHEST].first] = computeOffset(defaultToReferenceMat, inputCalibration.defaultSpine2, _validTrackedObjects[CHEST].second); + } else { + uncalibrate(); + return; } _calibrated = true; } void ViveControllerManager::InputDevice::uncalibrate() { + _config = Config::Auto; _pucksOffset.clear(); _jointToPuckMap.clear(); _calibrated = false; @@ -544,6 +557,74 @@ void ViveControllerManager::InputDevice::hapticsHelper(float deltaTime, bool lef } } +void ViveControllerManager::InputDevice::loadSettings() { + Settings settings; + settings.beginGroup("PUCK_CONFIG"); + { + _preferedConfig = (Config)settings.value("configuration", QVariant((int)Config::Auto)).toInt(); + } + settings.endGroup(); +} + +void ViveControllerManager::InputDevice::saveSettings() const { + Settings settings; + settings.beginGroup("PUCK_CONFIG"); + { + settings.setValue(QString("configuration"), (int)_preferedConfig); + } + settings.endGroup(); +} + +QString ViveControllerManager::InputDevice::configToString() { + QString currentConfig = ""; + switch (_preferedConfig) { + case Config::Auto: + currentConfig = "Auto"; + break; + + case Config::Feet: + currentConfig = "Feet"; + break; + + case Config::FeetAndHips: + currentConfig = "FeetAndHips"; + break; + + case Config::FeetHipsAndChest: + currentConfig = "FeetHipsAndChest"; + break; + } + return currentConfig; +} + +void ViveControllerManager::InputDevice::setConfigFromString(const QString& value) { + if (value == "Auto") { + _preferedConfig = Config::Auto; + } else if (value == "Feet") { + _preferedConfig = Config::Feet; + } else if (value == "FeetAndHips") { + _preferedConfig = Config::FeetAndHips; + } else if (value == "FeetHipsAndChest") { + _preferedConfig = Config::FeetHipsAndChest; + } +} + +void ViveControllerManager::InputDevice::createPreferences() { + loadSettings(); + auto preferences = DependencyManager::get(); + static const QString VIVE_PUCKS_CONFIG { "Vive Pucks Configuration" }; + + { + auto getter = [this]()->QString { return configToString(); }; + auto setter = [this](const QString& value) { setConfigFromString(value); saveSettings(); }; + auto preference = new ComboBoxPreference(VIVE_PUCKS_CONFIG, "Configuration", getter, setter); + QStringList list = (QStringList() << "Auto" << "Feet" << "FeetAndHips" << "FeetHipsAndChest"); + preference->setItems(list); + preferences->addPreference(preference); + + } +} + controller::Input::NamedVector ViveControllerManager::InputDevice::getAvailableInputs() const { using namespace controller; QVector availableInputs{ diff --git a/plugins/openvr/src/ViveControllerManager.h b/plugins/openvr/src/ViveControllerManager.h index 4e8b2b3a04..9920fb003a 100644 --- a/plugins/openvr/src/ViveControllerManager.h +++ b/plugins/openvr/src/ViveControllerManager.h @@ -50,14 +50,14 @@ public: private: class InputDevice : public controller::InputDevice { public: - InputDevice(vr::IVRSystem*& system) : controller::InputDevice("Vive"), _system(system) {} + InputDevice(vr::IVRSystem*& system) : controller::InputDevice("Vive"), _system(system) { createPreferences(); } private: // Device functions controller::Input::NamedVector getAvailableInputs() const override; QString getDefaultMappingConfig() const override; void update(float deltaTime, const controller::InputCalibrationData& inputCalibrationData) override; void focusOutEvent() override; - + void createPreferences(); bool triggerHapticPulse(float strength, float duration, controller::Hand hand) override; void hapticsHelper(float deltaTime, bool leftHand); void calibrateOrUncalibrate(const controller::InputCalibrationData& inputCalibration); @@ -100,8 +100,9 @@ private: float _timer { 0.0f }; glm::vec2 _stick { 0.0f, 0.0f }; }; - enum class Config { Feet, FeetAndHips, FeetHipsAndChest, NoConfig }; - Config _config { Config::NoConfig }; + enum class Config { Feet, FeetAndHips, FeetHipsAndChest, Auto }; + Config _config { Config::Auto }; + Config _preferedConfig { Config::Auto }; FilteredStick _filteredLeftStick; FilteredStick _filteredRightStick; @@ -125,6 +126,10 @@ private: bool _timeTilCalibrationSet { false }; mutable std::recursive_mutex _lock; + QString configToString(); + void setConfigFromString(const QString& value); + void loadSettings(); + void saveSettings() const; friend class ViveControllerManager; }; From 7687617e912719c4de3455992492dcb73e688c16 Mon Sep 17 00:00:00 2001 From: Dante Ruiz Date: Thu, 11 May 2017 00:32:42 +0100 Subject: [PATCH 2/2] made requested changes --- plugins/openvr/src/ViveControllerManager.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/openvr/src/ViveControllerManager.cpp b/plugins/openvr/src/ViveControllerManager.cpp index 5dd4c71194..e5cd7ffecc 100644 --- a/plugins/openvr/src/ViveControllerManager.cpp +++ b/plugins/openvr/src/ViveControllerManager.cpp @@ -576,7 +576,7 @@ void ViveControllerManager::InputDevice::saveSettings() const { } QString ViveControllerManager::InputDevice::configToString() { - QString currentConfig = ""; + QString currentConfig; switch (_preferedConfig) { case Config::Auto: currentConfig = "Auto"; @@ -601,7 +601,7 @@ void ViveControllerManager::InputDevice::setConfigFromString(const QString& valu if (value == "Auto") { _preferedConfig = Config::Auto; } else if (value == "Feet") { - _preferedConfig = Config::Feet; + _preferedConfig = Config::Feet; } else if (value == "FeetAndHips") { _preferedConfig = Config::FeetAndHips; } else if (value == "FeetHipsAndChest") { @@ -612,7 +612,7 @@ void ViveControllerManager::InputDevice::setConfigFromString(const QString& valu void ViveControllerManager::InputDevice::createPreferences() { loadSettings(); auto preferences = DependencyManager::get(); - static const QString VIVE_PUCKS_CONFIG { "Vive Pucks Configuration" }; + static const QString VIVE_PUCKS_CONFIG = "Vive Pucks Configuration"; { auto getter = [this]()->QString { return configToString(); };