diff --git a/LucidGloves/include/ControllerPose.h b/LucidGloves/include/ControllerPose.h index 61e8f6e4..54f29f9f 100644 --- a/LucidGloves/include/ControllerPose.h +++ b/LucidGloves/include/ControllerPose.h @@ -9,7 +9,9 @@ class ControllerPose { ControllerPose(vr::ETrackedControllerRole shadowDeviceOfRole, std::string thisDeviceManufacturer, vr::HmdVector3_t offsetVector, - vr::HmdVector3_t angleOffsetVector, + vr::HmdVector3_t angleOffsetVector, + int controllerIdOverride, + bool isControllerOverride, uint32_t driverId); vr::DriverPose_t UpdatePose(); private: @@ -21,6 +23,8 @@ class ControllerPose { //This member variable is the id of the controller we are "shadowing" and receiving positioning from. short int m_shadowControllerId = -1; + int m_controllerIdOverride; + bool m_isControllerOverride; vr::HmdQuaternion_t m_offsetQuaternion; vr::ETrackedControllerRole m_shadowDeviceOfRole = vr::TrackedControllerRole_Invalid; diff --git a/LucidGloves/include/DeviceConfiguration.h b/LucidGloves/include/DeviceConfiguration.h index 4ef308df..73c641f3 100644 --- a/LucidGloves/include/DeviceConfiguration.h +++ b/LucidGloves/include/DeviceConfiguration.h @@ -34,6 +34,8 @@ struct VRDeviceConfiguration_t { vr::HmdVector3_t offsetVector, vr::HmdVector3_t angleOffsetVector, float poseOffset, + int controllerIdOverride, + bool isControllerOverride, VREncodingProtocol encodingProtocol, VRCommunicationProtocol communicationProtocol, VRDeviceDriver deviceDriver) : @@ -41,6 +43,8 @@ struct VRDeviceConfiguration_t { enabled(enabled), offsetVector(offsetVector), angleOffsetVector(angleOffsetVector), + controllerIdOverride(controllerIdOverride), + isControllerOverride(isControllerOverride), poseOffset(poseOffset), communicationProtocol(communicationProtocol), deviceDriver(deviceDriver) {}; @@ -50,6 +54,8 @@ struct VRDeviceConfiguration_t { vr::HmdVector3_t offsetVector; vr::HmdVector3_t angleOffsetVector; float poseOffset; + int controllerIdOverride; + bool isControllerOverride; VREncodingProtocol encodingProtocol; VRCommunicationProtocol communicationProtocol; diff --git a/LucidGloves/lucidgloves/resources/settings/default.vrsettings b/LucidGloves/lucidgloves/resources/settings/default.vrsettings index d402ec00..696daa39 100644 --- a/LucidGloves/lucidgloves/resources/settings/default.vrsettings +++ b/LucidGloves/lucidgloves/resources/settings/default.vrsettings @@ -32,7 +32,10 @@ "left_flipped_pos_z": false, "left_flipped_rot_x": false, "left_flipped_rot_y": false, - "left_flipped_rot_z": true + "left_flipped_rot_z": true, + "controller_override": false, + "controller_override_left": 3, + "controller_override_right": 4 }, //communication_protocol = 0 diff --git a/LucidGloves/src/ControllerPose.cpp b/LucidGloves/src/ControllerPose.cpp index 295c253b..5f10213e 100644 --- a/LucidGloves/src/ControllerPose.cpp +++ b/LucidGloves/src/ControllerPose.cpp @@ -5,11 +5,15 @@ ControllerPose::ControllerPose(vr::ETrackedControllerRole shadowDeviceOfRole, std::string thisDeviceManufacturer, vr::HmdVector3_t offsetVector, vr::HmdVector3_t angleOffsetVector, + int controllerIdOverride, + bool isControllerOverride, uint32_t driverId) : m_shadowDeviceOfRole(shadowDeviceOfRole), m_driverId(driverId), m_thisDeviceManufacturer(thisDeviceManufacturer), - m_offsetVector(offsetVector) { + m_offsetVector(offsetVector), + m_controllerIdOverride(controllerIdOverride), + m_isControllerOverride(isControllerOverride){ const vr::HmdVector3_t angleOffset = angleOffsetVector; m_offsetQuaternion = EulerToQuaternion(DegToRad(angleOffset.v[0]), DegToRad(angleOffset.v[1]), DegToRad(angleOffset.v[2])); @@ -79,19 +83,25 @@ vr::DriverPose_t ControllerPose::UpdatePose() { } void ControllerPose::DiscoverController() { //omit id 0, as this is always the headset pose - for (int i = 1; i < vr::k_unMaxTrackedDeviceCount; i++) { - vr::ETrackedPropertyError err; + if (!m_isControllerOverride) { + for (int i = 1; i < vr::k_unMaxTrackedDeviceCount; i++) { + vr::ETrackedPropertyError err; - vr::PropertyContainerHandle_t container = vr::VRProperties()->TrackedDeviceToPropertyContainer(i); + vr::PropertyContainerHandle_t container = vr::VRProperties()->TrackedDeviceToPropertyContainer(i); - std::string foundDeviceManufacturer = vr::VRProperties()->GetStringProperty(container, vr::Prop_ManufacturerName_String, &err); - int32_t deviceControllerRole = vr::VRProperties()->GetInt32Property(container, vr::ETrackedDeviceProperty::Prop_ControllerRoleHint_Int32, &err); + std::string foundDeviceManufacturer = vr::VRProperties()->GetStringProperty(container, vr::Prop_ManufacturerName_String, &err); + int32_t deviceControllerRole = vr::VRProperties()->GetInt32Property(container, vr::ETrackedDeviceProperty::Prop_ControllerRoleHint_Int32, &err); - //We have a device which identifies itself as a tracked device that we want to be searching for, and that device is not this one. - if (deviceControllerRole == m_shadowDeviceOfRole && foundDeviceManufacturer != m_thisDeviceManufacturer) { - DebugDriverLog("Discovered a controller! Id: %i, Manufacturer: %s", i, foundDeviceManufacturer.c_str()); - m_shadowControllerId = i; - break; + //We have a device which identifies itself as a tracked device that we want to be searching for, and that device is not this one. + if (deviceControllerRole == m_shadowDeviceOfRole && foundDeviceManufacturer != m_thisDeviceManufacturer) { + DebugDriverLog("Discovered a controller! Id: %i, Manufacturer: %s", i, foundDeviceManufacturer.c_str()); + m_shadowControllerId = i; + break; + } } } + else { + DebugDriverLog("Controller ID override set! Id: %i", m_controllerIdOverride); + m_shadowControllerId = m_controllerIdOverride; + } } \ No newline at end of file diff --git a/LucidGloves/src/DeviceDriver/KnuckleDriver.cpp b/LucidGloves/src/DeviceDriver/KnuckleDriver.cpp index e529bc75..f4ddda82 100644 --- a/LucidGloves/src/DeviceDriver/KnuckleDriver.cpp +++ b/LucidGloves/src/DeviceDriver/KnuckleDriver.cpp @@ -60,7 +60,7 @@ vr::EVRInitError KnuckleDeviceDriver::Activate(uint32_t unObjectId) { DebugDriverLog("Activating lucidgloves... ID: %d, role: %d, enabled: %s", unObjectId, m_configuration.role, m_configuration.enabled ? "true" : "false"); const bool isRightHand = IsRightHand(); m_driverId = unObjectId; //unique ID for your driver - m_controllerPose = std::make_unique(m_configuration.role, std::string(knuckleDevice::c_deviceManufacturer), m_configuration.offsetVector, m_configuration.angleOffsetVector, m_driverId); + m_controllerPose = std::make_unique(m_configuration.role, std::string(knuckleDevice::c_deviceManufacturer), m_configuration.offsetVector, m_configuration.angleOffsetVector, m_configuration.controllerIdOverride, m_configuration.isControllerOverride, m_driverId); vr::PropertyContainerHandle_t props = vr::VRProperties()->TrackedDeviceToPropertyContainer(m_driverId); //this gets a container object where you store all the information about your driver diff --git a/LucidGloves/src/DeviceDriver/LucidGloveDriver.cpp b/LucidGloves/src/DeviceDriver/LucidGloveDriver.cpp index 88cbad34..78e7e9ce 100644 --- a/LucidGloves/src/DeviceDriver/LucidGloveDriver.cpp +++ b/LucidGloves/src/DeviceDriver/LucidGloveDriver.cpp @@ -57,7 +57,7 @@ vr::EVRInitError LucidGloveDeviceDriver::Activate(uint32_t unObjectId) { const bool isRightHand = IsRightHand(); m_driverId = unObjectId; //unique ID for your driver - m_controllerPose = std::make_unique(m_configuration.role, std::string(lucidGlove::c_deviceManufacturer), m_configuration.offsetVector, m_configuration.angleOffsetVector, m_driverId); + m_controllerPose = std::make_unique(m_configuration.role, std::string(lucidGlove::c_deviceManufacturer), m_configuration.offsetVector, m_configuration.angleOffsetVector, m_configuration.controllerIdOverride, m_configuration.isControllerOverride, m_driverId); vr::PropertyContainerHandle_t props = vr::VRProperties()->TrackedDeviceToPropertyContainer(m_driverId); //this gets a container object where you store all the information about your driver diff --git a/LucidGloves/src/DeviceProvider.cpp b/LucidGloves/src/DeviceProvider.cpp index d23256d1..66898b7f 100644 --- a/LucidGloves/src/DeviceProvider.cpp +++ b/LucidGloves/src/DeviceProvider.cpp @@ -97,6 +97,9 @@ VRDeviceConfiguration_t DeviceProvider::GetDeviceConfiguration(vr::ETrackedContr const bool isRightHand = role == vr::TrackedControllerRole_RightHand; + const bool isControllerOverride = vr::VRSettings()->GetBool(c_poseSettingsSection, "controller_override"); + const int controllerIdOverride = isControllerOverride?vr::VRSettings()->GetInt32(c_poseSettingsSection, isRightHand?"controller_override_right":"controller_override_left"):-1; + const bool isEnabled = vr::VRSettings()->GetBool(c_driverSettingsSection, isRightHand ? "right_enabled" : "left_enabled"); //x axis may be flipped for the different hands @@ -113,7 +116,7 @@ VRDeviceConfiguration_t DeviceProvider::GetDeviceConfiguration(vr::ETrackedContr const float poseOffset = vr::VRSettings()->GetFloat(c_poseSettingsSection, "pose_offset"); - return VRDeviceConfiguration_t(role, isEnabled, offsetVector, angleOffsetVector, poseOffset, encodingProtocol, communicationProtocol, deviceDriver); + return VRDeviceConfiguration_t(role, isEnabled, offsetVector, angleOffsetVector, poseOffset, controllerIdOverride, isControllerOverride, encodingProtocol, communicationProtocol, deviceDriver); } void DeviceProvider::Cleanup() {}