From 0986f86c349417fc61a2598043bc9fbaf803e8d7 Mon Sep 17 00:00:00 2001 From: Brad Hefta-Gaub Date: Sun, 11 Oct 2015 14:55:07 -0700 Subject: [PATCH 1/4] implement StandardController and expose it to JS as Controller.Standard.* --- .../scripts/controllerScriptingExamples.js | 9 +++++++-- .../scripting/ControllerScriptingInterface.cpp | 13 +++++++++++++ .../src/input-plugins/UserInputMapper.cpp | 15 +++++++++++++++ .../src/input-plugins/UserInputMapper.h | 14 +++++++++++++- 4 files changed, 48 insertions(+), 3 deletions(-) diff --git a/examples/example/scripts/controllerScriptingExamples.js b/examples/example/scripts/controllerScriptingExamples.js index 88c4ae2daa..6db7b38705 100644 --- a/examples/example/scripts/controllerScriptingExamples.js +++ b/examples/example/scripts/controllerScriptingExamples.js @@ -11,14 +11,19 @@ // Assumes you only have the default keyboard connected + +Object.keys(Controller.Standard).forEach(function (input) { + print("Controller.Standard." + input + ":" + Controller.Standard[input]); +}); + Object.keys(Controller.Hardware).forEach(function (deviceName) { Object.keys(Controller.Hardware[deviceName]).forEach(function (input) { - print(deviceName + "." + input + ":" + Controller.Hardware[deviceName][input]); + print("Controller.Hardware." + deviceName + "." + input + ":" + Controller.Hardware[deviceName][input]); }); }); Object.keys(Controller.Actions).forEach(function (actionName) { - print(actionName + ":" + Controller.Actions[actionName]); + print("Controller.Actions." + actionName + ":" + Controller.Actions[actionName]); }); // Resets every device to its default key bindings: diff --git a/interface/src/scripting/ControllerScriptingInterface.cpp b/interface/src/scripting/ControllerScriptingInterface.cpp index 4db482b6d4..9bdf8d1a4a 100644 --- a/interface/src/scripting/ControllerScriptingInterface.cpp +++ b/interface/src/scripting/ControllerScriptingInterface.cpp @@ -391,6 +391,19 @@ QString ControllerScriptingInterface::sanatizeName(const QString& name) { void ControllerScriptingInterface::wireUpControllers(ScriptEngine* engine) { + // Controller.Standard.* + auto standardDevice = DependencyManager::get()->getStandardDevice(); + if (standardDevice) { + auto deviceName = sanatizeName(standardDevice->getName()); + auto deviceInputs = standardDevice->getAvailabeInputs(); + for (const auto& inputMapping : deviceInputs) { + auto input = inputMapping.first; + auto inputName = sanatizeName(inputMapping.second); + QString deviceInputName{ "Controller." + deviceName + "." + inputName }; + engine->registerValue(deviceInputName, input.getID()); + } + } + // Controller.Hardware.* auto devices = DependencyManager::get()->getDevices(); for(const auto& deviceMapping : devices) { diff --git a/libraries/input-plugins/src/input-plugins/UserInputMapper.cpp b/libraries/input-plugins/src/input-plugins/UserInputMapper.cpp index 5c51db9410..82f90fc5dc 100755 --- a/libraries/input-plugins/src/input-plugins/UserInputMapper.cpp +++ b/libraries/input-plugins/src/input-plugins/UserInputMapper.cpp @@ -10,13 +10,20 @@ // #include "UserInputMapper.h" +#include "StandardController.h" // Default contruct allocate the poutput size with the current hardcoded action channels UserInputMapper::UserInputMapper() { + registerStandardDevice(); assignDefaulActionScales(); createActionNames(); } +UserInputMapper::~UserInputMapper() { + delete _standardController; +} + + bool UserInputMapper::registerDevice(uint16 deviceID, const DeviceProxy::Pointer& proxy){ proxy->_name += " (" + QString::number(deviceID) + ")"; _registeredDevices[deviceID] = proxy; @@ -322,3 +329,11 @@ void UserInputMapper::createActionNames() { _actionNames[CONTEXT_MENU] = "CONTEXT_MENU"; _actionNames[TOGGLE_MUTE] = "TOGGLE_MUTE"; } + +void UserInputMapper::registerStandardDevice() { + _standardController = new StandardController; + _standardController->registerToUserInputMapper(*this); + + //mapper.registerDevice(_deviceID, proxy); + //_standardDevice = proxy; +} \ No newline at end of file diff --git a/libraries/input-plugins/src/input-plugins/UserInputMapper.h b/libraries/input-plugins/src/input-plugins/UserInputMapper.h index 1ad4294e0c..8995d3544b 100755 --- a/libraries/input-plugins/src/input-plugins/UserInputMapper.h +++ b/libraries/input-plugins/src/input-plugins/UserInputMapper.h @@ -19,13 +19,16 @@ #include #include #include - + +class StandardController; class UserInputMapper : public QObject, public Dependency { Q_OBJECT SINGLETON_DEPENDENCY Q_ENUMS(Action) public: + ~UserInputMapper(); + typedef unsigned short uint16; typedef unsigned int uint32; @@ -123,6 +126,7 @@ public: // GetFreeDeviceID should be called before registering a device to use an ID not used by a different device. uint16 getFreeDeviceID() { return _nextFreeDeviceID++; } bool registerDevice(uint16 deviceID, const DeviceProxy::Pointer& device); + bool registerStandardDevice(const DeviceProxy::Pointer& device) { _standardDevice = device; return true; } DeviceProxy::Pointer getDeviceProxy(const Input& input); QString getDeviceName(uint16 deviceID); QVector getAvailableInputs(uint16 deviceID) { return _registeredDevices[deviceID]->getAvailabeInputs(); } @@ -238,11 +242,19 @@ public: typedef std::map DevicesMap; DevicesMap getDevices() { return _registeredDevices; } + uint16 getStandardDeviceID() const { return _standardDeviceID; } + DeviceProxy::Pointer getStandardDevice() { return _standardDevice; } + signals: void actionEvent(int action, float state); protected: + void registerStandardDevice(); + uint16 _standardDeviceID = 0; + DeviceProxy::Pointer _standardDevice; + StandardController* _standardController = nullptr; + DevicesMap _registeredDevices; uint16 _nextFreeDeviceID = 1; From 9667a103aa6295a36aaafd2bb62889c7732bbc2d Mon Sep 17 00:00:00 2001 From: Brad Hefta-Gaub Date: Sun, 11 Oct 2015 15:02:11 -0700 Subject: [PATCH 2/4] actually add new files --- .../src/input-plugins/StandardController.cpp | 156 ++++++++++++++++++ .../src/input-plugins/StandardController.h | 69 ++++++++ 2 files changed, 225 insertions(+) create mode 100644 libraries/input-plugins/src/input-plugins/StandardController.cpp create mode 100644 libraries/input-plugins/src/input-plugins/StandardController.h diff --git a/libraries/input-plugins/src/input-plugins/StandardController.cpp b/libraries/input-plugins/src/input-plugins/StandardController.cpp new file mode 100644 index 0000000000..ba5b5baa19 --- /dev/null +++ b/libraries/input-plugins/src/input-plugins/StandardController.cpp @@ -0,0 +1,156 @@ +// +// StandardController.cpp +// input-plugins/src/input-plugins +// +// Created by Stephen Birarda on 2014-09-23. +// Copyright 2014 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#include + +#include + +#include "StandardController.h" + +const float CONTROLLER_THRESHOLD = 0.3f; + +const float MAX_AXIS = 32768.0f; + +StandardController::~StandardController() { +} + +void StandardController::update(float deltaTime, bool jointsCaptured) { + for (auto axisState : _axisStateMap) { + if (fabsf(axisState.second) < CONTROLLER_THRESHOLD) { + _axisStateMap[axisState.first] = 0.0f; + } + } +} + +void StandardController::focusOutEvent() { + _axisStateMap.clear(); + _buttonPressedMap.clear(); +}; + +void StandardController::registerToUserInputMapper(UserInputMapper& mapper) { + // Grab the current free device ID + _deviceID = mapper.getStandardDeviceID(); + + auto proxy = std::make_shared(_name); + proxy->getButton = [this] (const UserInputMapper::Input& input, int timestamp) -> bool { return this->getButton(input.getChannel()); }; + proxy->getAxis = [this] (const UserInputMapper::Input& input, int timestamp) -> float { return this->getAxis(input.getChannel()); }; + proxy->getAvailabeInputs = [this] () -> QVector { + QVector availableInputs; + availableInputs.append(UserInputMapper::InputPair(makeInput(STANDARD_CONTROLLER_BUTTON_A), "Bottom Button")); + availableInputs.append(UserInputMapper::InputPair(makeInput(STANDARD_CONTROLLER_BUTTON_B), "Right Button")); + availableInputs.append(UserInputMapper::InputPair(makeInput(STANDARD_CONTROLLER_BUTTON_X), "Left Button")); + availableInputs.append(UserInputMapper::InputPair(makeInput(STANDARD_CONTROLLER_BUTTON_Y), "Top Button")); + + availableInputs.append(UserInputMapper::InputPair(makeInput(STANDARD_CONTROLLER_BUTTON_DPAD_UP), "DPad Up")); + availableInputs.append(UserInputMapper::InputPair(makeInput(STANDARD_CONTROLLER_BUTTON_DPAD_DOWN), "DPad Down")); + availableInputs.append(UserInputMapper::InputPair(makeInput(STANDARD_CONTROLLER_BUTTON_DPAD_LEFT), "DPad Left")); + availableInputs.append(UserInputMapper::InputPair(makeInput(STANDARD_CONTROLLER_BUTTON_DPAD_RIGHT), "DPad Right")); + + availableInputs.append(UserInputMapper::InputPair(makeInput(STANDARD_CONTROLLER_BUTTON_LEFTSHOULDER), "L1")); + availableInputs.append(UserInputMapper::InputPair(makeInput(STANDARD_CONTROLLER_BUTTON_RIGHTSHOULDER), "R1")); + availableInputs.append(UserInputMapper::InputPair(makeInput(RIGHT_SHOULDER), "L2")); + availableInputs.append(UserInputMapper::InputPair(makeInput(LEFT_SHOULDER), "R2")); + + availableInputs.append(UserInputMapper::InputPair(makeInput(LEFT_AXIS_Y_NEG), "Left Stick Up")); + availableInputs.append(UserInputMapper::InputPair(makeInput(LEFT_AXIS_Y_POS), "Left Stick Down")); + availableInputs.append(UserInputMapper::InputPair(makeInput(LEFT_AXIS_X_POS), "Left Stick Right")); + availableInputs.append(UserInputMapper::InputPair(makeInput(LEFT_AXIS_X_NEG), "Left Stick Left")); + availableInputs.append(UserInputMapper::InputPair(makeInput(RIGHT_AXIS_Y_NEG), "Right Stick Up")); + availableInputs.append(UserInputMapper::InputPair(makeInput(RIGHT_AXIS_Y_POS), "Right Stick Down")); + availableInputs.append(UserInputMapper::InputPair(makeInput(RIGHT_AXIS_X_POS), "Right Stick Right")); + availableInputs.append(UserInputMapper::InputPair(makeInput(RIGHT_AXIS_X_NEG), "Right Stick Left")); + + return availableInputs; + }; + proxy->resetDeviceBindings = [this, &mapper] () -> bool { + mapper.removeAllInputChannelsForDevice(_deviceID); + this->assignDefaultInputMapping(mapper); + return true; + }; + mapper.registerStandardDevice(proxy); +} + +void StandardController::assignDefaultInputMapping(UserInputMapper& mapper) { + const float JOYSTICK_MOVE_SPEED = 1.0f; + const float DPAD_MOVE_SPEED = 0.5f; + const float JOYSTICK_YAW_SPEED = 0.5f; + const float JOYSTICK_PITCH_SPEED = 0.25f; + const float BOOM_SPEED = 0.1f; + + // Y axes are flipped (up is negative) + // Left StandardController: Movement, strafing + mapper.addInputChannel(UserInputMapper::LONGITUDINAL_FORWARD, makeInput(LEFT_AXIS_Y_NEG), JOYSTICK_MOVE_SPEED); + mapper.addInputChannel(UserInputMapper::LONGITUDINAL_BACKWARD, makeInput(LEFT_AXIS_Y_POS), JOYSTICK_MOVE_SPEED); + mapper.addInputChannel(UserInputMapper::LATERAL_RIGHT, makeInput(LEFT_AXIS_X_POS), JOYSTICK_MOVE_SPEED); + mapper.addInputChannel(UserInputMapper::LATERAL_LEFT, makeInput(LEFT_AXIS_X_NEG), JOYSTICK_MOVE_SPEED); + + // Right StandardController: Camera orientation + mapper.addInputChannel(UserInputMapper::YAW_RIGHT, makeInput(RIGHT_AXIS_X_POS), JOYSTICK_YAW_SPEED); + mapper.addInputChannel(UserInputMapper::YAW_LEFT, makeInput(RIGHT_AXIS_X_NEG), JOYSTICK_YAW_SPEED); + mapper.addInputChannel(UserInputMapper::PITCH_UP, makeInput(RIGHT_AXIS_Y_NEG), JOYSTICK_PITCH_SPEED); + mapper.addInputChannel(UserInputMapper::PITCH_DOWN, makeInput(RIGHT_AXIS_Y_POS), JOYSTICK_PITCH_SPEED); + + // Dpad movement + mapper.addInputChannel(UserInputMapper::LONGITUDINAL_FORWARD, makeInput(STANDARD_CONTROLLER_BUTTON_DPAD_UP), DPAD_MOVE_SPEED); + mapper.addInputChannel(UserInputMapper::LONGITUDINAL_BACKWARD, makeInput(STANDARD_CONTROLLER_BUTTON_DPAD_DOWN), DPAD_MOVE_SPEED); + mapper.addInputChannel(UserInputMapper::LATERAL_RIGHT, makeInput(STANDARD_CONTROLLER_BUTTON_DPAD_RIGHT), DPAD_MOVE_SPEED); + mapper.addInputChannel(UserInputMapper::LATERAL_LEFT, makeInput(STANDARD_CONTROLLER_BUTTON_DPAD_LEFT), DPAD_MOVE_SPEED); + + // Button controls + mapper.addInputChannel(UserInputMapper::VERTICAL_UP, makeInput(STANDARD_CONTROLLER_BUTTON_Y), DPAD_MOVE_SPEED); + mapper.addInputChannel(UserInputMapper::VERTICAL_DOWN, makeInput(STANDARD_CONTROLLER_BUTTON_X), DPAD_MOVE_SPEED); + + // Zoom + mapper.addInputChannel(UserInputMapper::BOOM_IN, makeInput(RIGHT_SHOULDER), BOOM_SPEED); + mapper.addInputChannel(UserInputMapper::BOOM_OUT, makeInput(LEFT_SHOULDER), BOOM_SPEED); + + + // Hold front right shoulder button for precision controls + // Left StandardController: Movement, strafing + mapper.addInputChannel(UserInputMapper::LONGITUDINAL_FORWARD, makeInput(LEFT_AXIS_Y_NEG), makeInput(STANDARD_CONTROLLER_BUTTON_RIGHTSHOULDER), JOYSTICK_MOVE_SPEED/2.0f); + mapper.addInputChannel(UserInputMapper::LONGITUDINAL_BACKWARD, makeInput(LEFT_AXIS_Y_POS), makeInput(STANDARD_CONTROLLER_BUTTON_RIGHTSHOULDER), JOYSTICK_MOVE_SPEED/2.0f); + mapper.addInputChannel(UserInputMapper::LATERAL_RIGHT, makeInput(LEFT_AXIS_X_POS), makeInput(STANDARD_CONTROLLER_BUTTON_RIGHTSHOULDER), JOYSTICK_MOVE_SPEED/2.0f); + mapper.addInputChannel(UserInputMapper::LATERAL_LEFT, makeInput(LEFT_AXIS_X_NEG), makeInput(STANDARD_CONTROLLER_BUTTON_RIGHTSHOULDER), JOYSTICK_MOVE_SPEED/2.0f); + + // Right StandardController: Camera orientation + mapper.addInputChannel(UserInputMapper::YAW_RIGHT, makeInput(RIGHT_AXIS_X_POS), makeInput(STANDARD_CONTROLLER_BUTTON_RIGHTSHOULDER), JOYSTICK_YAW_SPEED/2.0f); + mapper.addInputChannel(UserInputMapper::YAW_LEFT, makeInput(RIGHT_AXIS_X_NEG), makeInput(STANDARD_CONTROLLER_BUTTON_RIGHTSHOULDER), JOYSTICK_YAW_SPEED/2.0f); + mapper.addInputChannel(UserInputMapper::PITCH_UP, makeInput(RIGHT_AXIS_Y_NEG), makeInput(STANDARD_CONTROLLER_BUTTON_RIGHTSHOULDER), JOYSTICK_PITCH_SPEED/2.0f); + mapper.addInputChannel(UserInputMapper::PITCH_DOWN, makeInput(RIGHT_AXIS_Y_POS), makeInput(STANDARD_CONTROLLER_BUTTON_RIGHTSHOULDER), JOYSTICK_PITCH_SPEED/2.0f); + + // Dpad movement + mapper.addInputChannel(UserInputMapper::LONGITUDINAL_FORWARD, makeInput(STANDARD_CONTROLLER_BUTTON_DPAD_UP), makeInput(STANDARD_CONTROLLER_BUTTON_RIGHTSHOULDER), DPAD_MOVE_SPEED/2.0f); + mapper.addInputChannel(UserInputMapper::LONGITUDINAL_BACKWARD, makeInput(STANDARD_CONTROLLER_BUTTON_DPAD_DOWN), makeInput(STANDARD_CONTROLLER_BUTTON_RIGHTSHOULDER), DPAD_MOVE_SPEED/2.0f); + mapper.addInputChannel(UserInputMapper::LATERAL_RIGHT, makeInput(STANDARD_CONTROLLER_BUTTON_DPAD_RIGHT), makeInput(STANDARD_CONTROLLER_BUTTON_RIGHTSHOULDER), DPAD_MOVE_SPEED/2.0f); + mapper.addInputChannel(UserInputMapper::LATERAL_LEFT, makeInput(STANDARD_CONTROLLER_BUTTON_DPAD_LEFT), makeInput(STANDARD_CONTROLLER_BUTTON_RIGHTSHOULDER), DPAD_MOVE_SPEED/2.0f); + + // Button controls + mapper.addInputChannel(UserInputMapper::VERTICAL_UP, makeInput(STANDARD_CONTROLLER_BUTTON_Y), makeInput(STANDARD_CONTROLLER_BUTTON_RIGHTSHOULDER), DPAD_MOVE_SPEED/2.0f); + mapper.addInputChannel(UserInputMapper::VERTICAL_DOWN, makeInput(STANDARD_CONTROLLER_BUTTON_X), makeInput(STANDARD_CONTROLLER_BUTTON_RIGHTSHOULDER), DPAD_MOVE_SPEED/2.0f); + + // Zoom + mapper.addInputChannel(UserInputMapper::BOOM_IN, makeInput(RIGHT_SHOULDER), makeInput(STANDARD_CONTROLLER_BUTTON_RIGHTSHOULDER), BOOM_SPEED/2.0f); + mapper.addInputChannel(UserInputMapper::BOOM_OUT, makeInput(LEFT_SHOULDER), makeInput(STANDARD_CONTROLLER_BUTTON_RIGHTSHOULDER), BOOM_SPEED/2.0f); + + mapper.addInputChannel(UserInputMapper::SHIFT, makeInput(STANDARD_CONTROLLER_BUTTON_LEFTSHOULDER)); + + mapper.addInputChannel(UserInputMapper::ACTION1, makeInput(STANDARD_CONTROLLER_BUTTON_B)); + mapper.addInputChannel(UserInputMapper::ACTION2, makeInput(STANDARD_CONTROLLER_BUTTON_A)); +} + +UserInputMapper::Input StandardController::makeInput(StandardController::StandardControllerButtonChannel button) { + return UserInputMapper::Input(_deviceID, button, UserInputMapper::ChannelType::BUTTON); +} + +UserInputMapper::Input StandardController::makeInput(StandardController::StandardControllerAxisChannel axis) { + return UserInputMapper::Input(_deviceID, axis, UserInputMapper::ChannelType::AXIS); +} + diff --git a/libraries/input-plugins/src/input-plugins/StandardController.h b/libraries/input-plugins/src/input-plugins/StandardController.h new file mode 100644 index 0000000000..ac89bca581 --- /dev/null +++ b/libraries/input-plugins/src/input-plugins/StandardController.h @@ -0,0 +1,69 @@ +// +// StandardController.h +// input-plugins/src/input-plugins +// +// Created by Stephen Birarda on 2014-09-23. +// Copyright 2014 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#ifndef hifi_StandardController_h +#define hifi_StandardController_h + +#include +#include + +#include "InputDevice.h" + +class StandardController : public QObject, public InputDevice { + Q_OBJECT + Q_PROPERTY(QString name READ getName) + +public: + enum StandardControllerAxisChannel { + LEFT_AXIS_X_POS = 0, + LEFT_AXIS_X_NEG, + LEFT_AXIS_Y_POS, + LEFT_AXIS_Y_NEG, + RIGHT_AXIS_X_POS, + RIGHT_AXIS_X_NEG, + RIGHT_AXIS_Y_POS, + RIGHT_AXIS_Y_NEG, + RIGHT_SHOULDER, + LEFT_SHOULDER, + }; + enum StandardControllerButtonChannel { + STANDARD_CONTROLLER_BUTTON_A = 0, + STANDARD_CONTROLLER_BUTTON_B, + STANDARD_CONTROLLER_BUTTON_X, + STANDARD_CONTROLLER_BUTTON_Y, + + STANDARD_CONTROLLER_BUTTON_DPAD_UP, + STANDARD_CONTROLLER_BUTTON_DPAD_DOWN, + STANDARD_CONTROLLER_BUTTON_DPAD_LEFT, + STANDARD_CONTROLLER_BUTTON_DPAD_RIGHT, + + STANDARD_CONTROLLER_BUTTON_LEFTSHOULDER, + STANDARD_CONTROLLER_BUTTON_RIGHTSHOULDER, + }; + + const QString& getName() const { return _name; } + + // Device functions + virtual void registerToUserInputMapper(UserInputMapper& mapper) override; + virtual void assignDefaultInputMapping(UserInputMapper& mapper) override; + virtual void update(float deltaTime, bool jointsCaptured) override; + virtual void focusOutEvent() override; + + StandardController() : InputDevice("Standard") {} + ~StandardController(); + + UserInputMapper::Input makeInput(StandardController::StandardControllerButtonChannel button); + UserInputMapper::Input makeInput(StandardController::StandardControllerAxisChannel axis); + +private: +}; + +#endif // hifi_StandardController_h From 312bbf6167871c4020e52e5a27cab630df6fc8f0 Mon Sep 17 00:00:00 2001 From: Brad Hefta-Gaub Date: Sun, 11 Oct 2015 15:15:20 -0700 Subject: [PATCH 3/4] CR feedback --- .../src/input-plugins/StandardController.cpp | 10 ++++++++-- .../src/input-plugins/StandardController.h | 10 ++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/libraries/input-plugins/src/input-plugins/StandardController.cpp b/libraries/input-plugins/src/input-plugins/StandardController.cpp index ba5b5baa19..4fb4a23654 100644 --- a/libraries/input-plugins/src/input-plugins/StandardController.cpp +++ b/libraries/input-plugins/src/input-plugins/StandardController.cpp @@ -2,8 +2,8 @@ // StandardController.cpp // input-plugins/src/input-plugins // -// Created by Stephen Birarda on 2014-09-23. -// Copyright 2014 High Fidelity, Inc. +// Created by Brad Hefta-Gaub on 2015-10-11. +// Copyright 2015 High Fidelity, Inc. // // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html @@ -68,6 +68,9 @@ void StandardController::registerToUserInputMapper(UserInputMapper& mapper) { availableInputs.append(UserInputMapper::InputPair(makeInput(RIGHT_AXIS_X_POS), "Right Stick Right")); availableInputs.append(UserInputMapper::InputPair(makeInput(RIGHT_AXIS_X_NEG), "Right Stick Left")); + availableInputs.append(UserInputMapper::InputPair(makeInput(LEFT_HAND), "Left Hand")); + availableInputs.append(UserInputMapper::InputPair(makeInput(RIGHT_HAND), "Right Hand")); + return availableInputs; }; proxy->resetDeviceBindings = [this, &mapper] () -> bool { @@ -154,3 +157,6 @@ UserInputMapper::Input StandardController::makeInput(StandardController::Standar return UserInputMapper::Input(_deviceID, axis, UserInputMapper::ChannelType::AXIS); } +UserInputMapper::Input StandardController::makeInput(StandardController::StandardControllerPoseChannel pose) { + return UserInputMapper::Input(_deviceID, pose, UserInputMapper::ChannelType::POSE); +} diff --git a/libraries/input-plugins/src/input-plugins/StandardController.h b/libraries/input-plugins/src/input-plugins/StandardController.h index ac89bca581..7f13b61783 100644 --- a/libraries/input-plugins/src/input-plugins/StandardController.h +++ b/libraries/input-plugins/src/input-plugins/StandardController.h @@ -2,8 +2,8 @@ // StandardController.h // input-plugins/src/input-plugins // -// Created by Stephen Birarda on 2014-09-23. -// Copyright 2014 High Fidelity, Inc. +// Created by Brad Hefta-Gaub on 2015-10-11. +// Copyright 2015 High Fidelity, Inc. // // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html @@ -49,6 +49,11 @@ public: STANDARD_CONTROLLER_BUTTON_RIGHTSHOULDER, }; + enum StandardControllerPoseChannel { + LEFT_HAND = 0, + RIGHT_HAND, + }; + const QString& getName() const { return _name; } // Device functions @@ -62,6 +67,7 @@ public: UserInputMapper::Input makeInput(StandardController::StandardControllerButtonChannel button); UserInputMapper::Input makeInput(StandardController::StandardControllerAxisChannel axis); + UserInputMapper::Input makeInput(StandardController::StandardControllerPoseChannel pose); private: }; From 21a473035e2b60d7f854f1abe432cf6e2cd7c586 Mon Sep 17 00:00:00 2001 From: Brad Hefta-Gaub Date: Sun, 11 Oct 2015 15:37:17 -0700 Subject: [PATCH 4/4] more CR feedback --- .../input-plugins/src/input-plugins/StandardController.h | 2 ++ .../input-plugins/src/input-plugins/UserInputMapper.cpp | 6 +----- libraries/input-plugins/src/input-plugins/UserInputMapper.h | 3 ++- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/libraries/input-plugins/src/input-plugins/StandardController.h b/libraries/input-plugins/src/input-plugins/StandardController.h index 7f13b61783..f7a4215242 100644 --- a/libraries/input-plugins/src/input-plugins/StandardController.h +++ b/libraries/input-plugins/src/input-plugins/StandardController.h @@ -17,6 +17,8 @@ #include "InputDevice.h" +typedef std::shared_ptr StandardControllerPointer; + class StandardController : public QObject, public InputDevice { Q_OBJECT Q_PROPERTY(QString name READ getName) diff --git a/libraries/input-plugins/src/input-plugins/UserInputMapper.cpp b/libraries/input-plugins/src/input-plugins/UserInputMapper.cpp index 82f90fc5dc..fad962345c 100755 --- a/libraries/input-plugins/src/input-plugins/UserInputMapper.cpp +++ b/libraries/input-plugins/src/input-plugins/UserInputMapper.cpp @@ -20,7 +20,6 @@ UserInputMapper::UserInputMapper() { } UserInputMapper::~UserInputMapper() { - delete _standardController; } @@ -331,9 +330,6 @@ void UserInputMapper::createActionNames() { } void UserInputMapper::registerStandardDevice() { - _standardController = new StandardController; + _standardController = std::make_shared(); _standardController->registerToUserInputMapper(*this); - - //mapper.registerDevice(_deviceID, proxy); - //_standardDevice = proxy; } \ No newline at end of file diff --git a/libraries/input-plugins/src/input-plugins/UserInputMapper.h b/libraries/input-plugins/src/input-plugins/UserInputMapper.h index 8995d3544b..1d64638ee1 100755 --- a/libraries/input-plugins/src/input-plugins/UserInputMapper.h +++ b/libraries/input-plugins/src/input-plugins/UserInputMapper.h @@ -21,6 +21,7 @@ #include class StandardController; +typedef std::shared_ptr StandardControllerPointer; class UserInputMapper : public QObject, public Dependency { Q_OBJECT @@ -253,7 +254,7 @@ protected: void registerStandardDevice(); uint16 _standardDeviceID = 0; DeviceProxy::Pointer _standardDevice; - StandardController* _standardController = nullptr; + StandardControllerPointer _standardController; DevicesMap _registeredDevices; uint16 _nextFreeDeviceID = 1;