Skip to content

Commit

Permalink
Added device ID override for VIVE wand support! (#51)
Browse files Browse the repository at this point in the history
* Added device ID override for VIVE wand support!

* Pass override bool to ControllerPose
  • Loading branch information
lucas-vrtech committed Apr 13, 2021
1 parent 59c9853 commit 61bfbab
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 16 deletions.
6 changes: 5 additions & 1 deletion LucidGloves/include/ControllerPose.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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;
Expand Down
6 changes: 6 additions & 0 deletions LucidGloves/include/DeviceConfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,17 @@ struct VRDeviceConfiguration_t {
vr::HmdVector3_t offsetVector,
vr::HmdVector3_t angleOffsetVector,
float poseOffset,
int controllerIdOverride,
bool isControllerOverride,
VREncodingProtocol encodingProtocol,
VRCommunicationProtocol communicationProtocol,
VRDeviceDriver deviceDriver) :
role(role),
enabled(enabled),
offsetVector(offsetVector),
angleOffsetVector(angleOffsetVector),
controllerIdOverride(controllerIdOverride),
isControllerOverride(isControllerOverride),
poseOffset(poseOffset),
communicationProtocol(communicationProtocol),
deviceDriver(deviceDriver) {};
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 21 additions & 11 deletions LucidGloves/src/ControllerPose.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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]));
Expand Down Expand Up @@ -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;
}
}
2 changes: 1 addition & 1 deletion LucidGloves/src/DeviceDriver/KnuckleDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<ControllerPose>(m_configuration.role, std::string(knuckleDevice::c_deviceManufacturer), m_configuration.offsetVector, m_configuration.angleOffsetVector, m_driverId);
m_controllerPose = std::make_unique<ControllerPose>(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

Expand Down
2 changes: 1 addition & 1 deletion LucidGloves/src/DeviceDriver/LucidGloveDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<ControllerPose>(m_configuration.role, std::string(lucidGlove::c_deviceManufacturer), m_configuration.offsetVector, m_configuration.angleOffsetVector, m_driverId);
m_controllerPose = std::make_unique<ControllerPose>(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

Expand Down
5 changes: 4 additions & 1 deletion LucidGloves/src/DeviceProvider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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() {}
Expand Down

0 comments on commit 61bfbab

Please sign in to comment.