Skip to content

Commit ad8a940

Browse files
authored
Driver cleanup (#71)
* Don't copy events in GetOpenVREvents * Don't log if HMD doesn't have chaperone props + default chap is missing * Remove useless properties Most of these are now set in the input profile. We don't need to set Prop_CurrentUniverseId_Uint64, that should only be set for HMD. * Set Prop_ManufacturerName_String * Specify hand in SteamVR for handed trackers * Add comment about role hint not applying until SteamVR restart * Set device icons in driver.vrresources * Remove unnecessary comments, add comment about input profile
1 parent d0d1ca1 commit ad8a940

File tree

6 files changed

+33
-35
lines changed

6 files changed

+33
-35
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"jsonid" : "vrresources",
3+
"statusicons" : {
4+
"Tracker" : {
5+
"Prop_NamedIconPathDeviceOff_String": "{slimevr}/icons/tracker_status_off.png",
6+
"Prop_NamedIconPathDeviceSearching_String": "{slimevr}/icons/tracker_status_ready.png",
7+
"Prop_NamedIconPathDeviceSearchingAlert_String": "{slimevr}/icons/tracker_status_ready_alert.png",
8+
"Prop_NamedIconPathDeviceReady_String": "{slimevr}/icons/tracker_status_ready.png",
9+
"Prop_NamedIconPathDeviceReadyAlert_String": "{slimevr}/icons/tracker_status_ready_alert.png",
10+
"Prop_NamedIconPathDeviceNotReady_String": "{slimevr}/icons/tracker_status_error.png",
11+
"Prop_NamedIconPathDeviceStandby_String": "{slimevr}/icons/tracker_status_standby.png",
12+
"Prop_NamedIconPathDeviceAlertLow_String": "{slimevr}/icons/tracker_status_ready_low.png"
13+
}
14+
}
15+
}

src/IVRDriver.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ namespace SlimeVRDriver {
3434
*
3535
* @return A vector of current frame's OpenVR events.
3636
*/
37-
virtual std::vector<vr::VREvent_t> GetOpenVREvents() = 0;
37+
virtual const std::vector<vr::VREvent_t>& GetOpenVREvents() = 0;
3838

3939
/**
4040
* Returns the milliseconds between last frame and this frame.

src/TrackerDevice.cpp

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ void SlimeVRDriver::TrackerDevice::Update() {
1616
if (device_index_ == vr::k_unTrackedDeviceIndexInvalid) return;
1717

1818
// Check if this device was asked to be identified
19-
auto events = GetDriver()->GetOpenVREvents();
20-
for (auto event : events) {
19+
auto& events = GetDriver()->GetOpenVREvents();
20+
for (const auto& event : events) {
2121
// Note here, event.trackedDeviceIndex does not necessarily equal device_index_, not sure why, but the component handle will match so we can just use that instead
2222
//if (event.trackedDeviceIndex == device_index_) {
2323
if (event.eventType == vr::EVREventType::VREvent_Input_HapticVibration) {
@@ -153,38 +153,18 @@ vr::EVRInitError SlimeVRDriver::TrackerDevice::Activate(uint32_t unObjectId) {
153153

154154
logger_->Log("Activating tracker {}", serial_);
155155

156-
// Get the properties handle
157156
auto props = GetDriver()->GetProperties()->TrackedDeviceToPropertyContainer(device_index_);
158-
159-
// Set some universe ID (Must be 2 or higher)
160-
GetDriver()->GetProperties()->SetUint64Property(props, vr::Prop_CurrentUniverseId_Uint64, 4);
161157

162-
// Set up a model "number" (not needed but good to have)
158+
GetDriver()->GetProperties()->SetStringProperty(props, vr::Prop_ManufacturerName_String, "SlimeVR");
163159
GetDriver()->GetProperties()->SetStringProperty(props, vr::Prop_ModelNumber_String, "SlimeVR Virtual Tracker");
164160

165-
// Opt out of hand selection
166-
GetDriver()->GetProperties()->SetInt32Property(props, vr::Prop_ControllerRoleHint_Int32, vr::ETrackedControllerRole::TrackedControllerRole_OptOut);
167-
vr::VRProperties()->SetInt32Property(props, vr::Prop_DeviceClass_Int32, vr::TrackedDeviceClass_GenericTracker);
168-
vr::VRProperties()->SetInt32Property(props, vr::Prop_ControllerHandSelectionPriority_Int32, -1);
169-
170-
// Set up a render model path
171161
GetDriver()->GetProperties()->SetStringProperty(props, vr::Prop_RenderModelName_String, "{htc}/rendermodels/vr_tracker_vive_1_0");
172162

173-
// Set the icon
174-
GetDriver()->GetProperties()->SetStringProperty(props, vr::Prop_NamedIconPathDeviceReady_String, "{slimevr}/icons/tracker_status_ready.png");
175-
176-
GetDriver()->GetProperties()->SetStringProperty(props, vr::Prop_NamedIconPathDeviceOff_String, "{slimevr}/icons/tracker_status_off.png");
177-
GetDriver()->GetProperties()->SetStringProperty(props, vr::Prop_NamedIconPathDeviceSearching_String, "{slimevr}/icons/tracker_status_ready.png");
178-
GetDriver()->GetProperties()->SetStringProperty(props, vr::Prop_NamedIconPathDeviceSearchingAlert_String, "{slimevr}/icons/tracker_status_ready_alert.png");
179-
GetDriver()->GetProperties()->SetStringProperty(props, vr::Prop_NamedIconPathDeviceReadyAlert_String, "{slimevr}/icons/tracker_status_ready_alert.png");
180-
GetDriver()->GetProperties()->SetStringProperty(props, vr::Prop_NamedIconPathDeviceNotReady_String, "{slimevr}/icons/tracker_status_error.png");
181-
GetDriver()->GetProperties()->SetStringProperty(props, vr::Prop_NamedIconPathDeviceStandby_String, "{slimevr}/icons/tracker_status_standby.png");
182-
GetDriver()->GetProperties()->SetStringProperty(props, vr::Prop_NamedIconPathDeviceAlertLow_String, "{slimevr}/icons/tracker_status_ready_low.png");
183-
163+
// Some device properties will be derived at runtime by SteamVR
164+
// using the profile, such as the device class and controller type
184165
GetDriver()->GetProperties()->SetStringProperty(props, vr::Prop_InputProfilePath_String, "{slimevr}/input/slimevr_tracker_profile.json");
185166

186-
GetDriver()->GetProperties()->SetStringProperty(props, vr::Prop_ControllerType_String, "slimevr_tracker");
187-
167+
// Doesn't apply until restart of SteamVR
188168
auto role = GetViveRole(tracker_role_);
189169
if (role != "") {
190170
vr::VRSettings()->SetString(vr::k_pch_Trackers_Section, ("/devices/slimevr/" + serial_).c_str(), role.c_str());

src/TrackerRole.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,14 @@ std::string GetViveRoleHint(TrackerRole role) {
6060

6161
std::string GetViveRole(TrackerRole role) {
6262
switch (role) {
63-
case LEFT_CONTROLLER:
64-
case RIGHT_CONTROLLER:
6563
case GENERIC_CONTROLLER:
64+
return "TrackerRole_Handed";
65+
case LEFT_CONTROLLER:
6666
case LEFT_HAND:
67+
return "TrackerRole_Handed,TrackedControllerRole_LeftHand";
68+
case RIGHT_CONTROLLER:
6769
case RIGHT_HAND:
68-
return "TrackerRole_Handed";
70+
return "TrackerRole_Handed,TrackedControllerRole_RightHand";
6971
case LEFT_FOOT:
7072
return "TrackerRole_LeftFoot";
7173
case RIGHT_FOOT:
@@ -97,7 +99,9 @@ std::string GetViveRole(TrackerRole role) {
9799
DeviceType GetDeviceType(TrackerRole role) {
98100
switch (role) {
99101
case LEFT_CONTROLLER:
102+
case LEFT_HAND:
100103
case RIGHT_CONTROLLER:
104+
case RIGHT_HAND:
101105
case GENERIC_CONTROLLER:
102106
return DeviceType::CONTROLLER;
103107
case HMD:

src/VRDriver.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,6 @@ void SlimeVRDriver::VRDriver::RunPoseRequestThread() {
109109
if (result.has_value()) {
110110
current_universe_.emplace(universe, result.value());
111111
logger_->Log("Found current universe");
112-
} else {
113-
logger_->Log("Failed to find current universe!");
114112
}
115113
}
116114
} else if (universe_error != last_universe_error_) {
@@ -216,6 +214,7 @@ void SlimeVRDriver::VRDriver::OnBridgeMessage(const messages::ProtobufMessage& m
216214
messages::TrackerAdded ta = message.tracker_added();
217215
switch(GetDeviceType(static_cast<TrackerRole>(ta.tracker_role()))) {
218216
case DeviceType::TRACKER:
217+
case DeviceType::CONTROLLER:
219218
AddDevice(std::make_shared<TrackerDevice>(ta.tracker_serial(), ta.tracker_id(), static_cast<TrackerRole>(ta.tracker_role())));
220219
break;
221220
}
@@ -266,7 +265,7 @@ std::vector<std::shared_ptr<SlimeVRDriver::IVRDevice>> SlimeVRDriver::VRDriver::
266265
return devices;
267266
}
268267

269-
std::vector<vr::VREvent_t> SlimeVRDriver::VRDriver::GetOpenVREvents() {
268+
const std::vector<vr::VREvent_t>& SlimeVRDriver::VRDriver::GetOpenVREvents() {
270269
return openvr_events_;
271270
}
272271

@@ -455,7 +454,7 @@ std::optional<SlimeVRDriver::UniverseTranslation> SlimeVRDriver::VRDriver::Searc
455454
}
456455
}
457456

458-
if (default_chap_path_.has_value()) {
457+
if (default_chap_path_.has_value() && std::filesystem::exists(default_chap_path_.value())) {
459458
try {
460459
return SearchUniverse(simdjson::padded_string::load(default_chap_path_.value()).take_value(), target);
461460
}

src/VRDriver.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ namespace SlimeVRDriver {
2020
public:
2121
// Inherited via IVRDriver
2222
virtual std::vector<std::shared_ptr<IVRDevice>> GetDevices() override;
23-
virtual std::vector<vr::VREvent_t> GetOpenVREvents() override;
23+
virtual const std::vector<vr::VREvent_t>& GetOpenVREvents() override;
2424
virtual std::chrono::milliseconds GetLastFrameTime() override;
2525
virtual bool AddDevice(std::shared_ptr<IVRDevice> device) override;
2626
virtual SettingsValue GetSettingsValue(std::string key) override;

0 commit comments

Comments
 (0)