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;