diff --git a/interface/resources/controllers/standard.json b/interface/resources/controllers/standard.json index 8ba9056076..5483da925d 100644 --- a/interface/resources/controllers/standard.json +++ b/interface/resources/controllers/standard.json @@ -3,6 +3,7 @@ "channels": [ { "from": "Standard.LY", "to": "Actions.TranslateZ" }, { "from": "Standard.LX", "to": "Actions.TranslateX" }, + { "from": "Standard.RX", "when": [ "Application.InHMD", "Application.ComfortMode" ], "to": "Actions.StepYaw" }, { "from": "Standard.RX", "to": "Actions.Yaw" }, { "from": "Standard.RY", "to": "Actions.Pitch" }, diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 4e4b4010f0..7f4b5a3c3d 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -637,10 +637,13 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer) : // A new controllerInput device used to reflect current values from the application state _applicationStateDevice = std::make_shared(); - auto InHMDLambda = controller::StateController::ReadLambda([]() -> float { - return (float) qApp->getAvatarUpdater()->isHMDMode(); - }); - _applicationStateDevice->addInputVariant("InHMD", InHMDLambda); + + _applicationStateDevice->addInputVariant(QString("InHMD"), controller::StateController::ReadLambda([]() -> float { + return (float)qApp->getAvatarUpdater()->isHMDMode(); + })); + _applicationStateDevice->addInputVariant(QString("ComfortMode"), controller::StateController::ReadLambda([]() -> float { + return (float)Menu::getInstance()->isOptionChecked(MenuOption::ComfortMode); + })); userInputMapper->registerDevice(_applicationStateDevice); @@ -648,6 +651,8 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer) : userInputMapper->registerDevice(_keyboardMouseDevice); + userInputMapper->loadDefaultMapping(userInputMapper->getStandardDeviceID()); + // check first run... if (_firstRun.get()) { qCDebug(interfaceapp) << "This is a first run..."; diff --git a/libraries/controllers/src/controllers/StateController.cpp b/libraries/controllers/src/controllers/StateController.cpp index efe7a064fc..6f89c6365c 100644 --- a/libraries/controllers/src/controllers/StateController.cpp +++ b/libraries/controllers/src/controllers/StateController.cpp @@ -29,7 +29,7 @@ void StateController::update(float deltaTime, bool jointsCaptured) {} void StateController::focusOutEvent() {} -void StateController::addInputVariant(QString name, ReadLambda& lambda) { +void StateController::addInputVariant(QString name, ReadLambda lambda) { _namedReadLambdas.push_back(NamedReadLambda(name, lambda)); } @@ -43,4 +43,8 @@ Input::NamedVector StateController::getAvailableInputs() const { return availableInputs; } +EndpointPointer StateController::createEndpoint(const Input& input) const { + return std::make_shared(_namedReadLambdas[input.getChannel()].second); +} + } \ No newline at end of file diff --git a/libraries/controllers/src/controllers/StateController.h b/libraries/controllers/src/controllers/StateController.h index d664c6b8d0..12f3e8b2f1 100644 --- a/libraries/controllers/src/controllers/StateController.h +++ b/libraries/controllers/src/controllers/StateController.h @@ -37,7 +37,10 @@ public: using ReadLambda = std::function; using NamedReadLambda = QPair; - void addInputVariant(QString name, ReadLambda& lambda); + void addInputVariant(QString name, ReadLambda lambda); + + virtual EndpointPointer createEndpoint(const Input& input) const override; + protected: QVector _namedReadLambdas; diff --git a/libraries/controllers/src/controllers/UserInputMapper.cpp b/libraries/controllers/src/controllers/UserInputMapper.cpp index 64a2a54ef4..736fa30d37 100755 --- a/libraries/controllers/src/controllers/UserInputMapper.cpp +++ b/libraries/controllers/src/controllers/UserInputMapper.cpp @@ -129,6 +129,27 @@ void UserInputMapper::removeDevice(int deviceID) { } +void UserInputMapper::loadDefaultMapping(uint16 deviceID) { + Locker locker(_lock); + auto proxyEntry = _registeredDevices.find(deviceID); + if (_registeredDevices.end() == proxyEntry) { + qCWarning(controllers) << "Unknown deviceID " << deviceID; + return; + } + + + auto mapping = loadMapping(proxyEntry->second->getDefaultMappingConfig()); + if (mapping) { + auto prevMapping = _mappingsByDevice[deviceID]; + disableMapping(prevMapping); + + _mappingsByDevice[deviceID] = mapping; + enableMapping(mapping); + } + + emit hardwareChanged(); +} + InputDevice::Pointer UserInputMapper::getDevice(const Input& input) { Locker locker(_lock); auto device = _registeredDevices.find(input.getDevice()); @@ -711,6 +732,8 @@ Mapping::Pointer UserInputMapper::loadMapping(const QString& jsonFile) { return parseMapping(json); } + + static const QString JSON_NAME = QStringLiteral("name"); static const QString JSON_CHANNELS = QStringLiteral("channels"); static const QString JSON_CHANNEL_FROM = QStringLiteral("from"); diff --git a/libraries/controllers/src/controllers/UserInputMapper.h b/libraries/controllers/src/controllers/UserInputMapper.h index 884e303fc6..a32c3f3649 100644 --- a/libraries/controllers/src/controllers/UserInputMapper.h +++ b/libraries/controllers/src/controllers/UserInputMapper.h @@ -108,6 +108,7 @@ namespace controller { MappingPointer parseMapping(const QString& json); MappingPointer loadMapping(const QString& jsonFile); + void loadDefaultMapping(uint16 deviceID); void enableMapping(const QString& mappingName, bool enable = true); float getValue(const Input& input) const; Pose getPose(const Input& input) const;