diff --git a/driver/slimevr/resources/driver.vrresources b/driver/slimevr/resources/driver.vrresources new file mode 100644 index 0000000..abc4f09 --- /dev/null +++ b/driver/slimevr/resources/driver.vrresources @@ -0,0 +1,15 @@ +{ + "jsonid" : "vrresources", + "statusicons" : { + "Tracker" : { + "Prop_NamedIconPathDeviceOff_String": "{slimevr}/icons/tracker_status_off.png", + "Prop_NamedIconPathDeviceSearching_String": "{slimevr}/icons/tracker_status_ready.png", + "Prop_NamedIconPathDeviceSearchingAlert_String": "{slimevr}/icons/tracker_status_ready_alert.png", + "Prop_NamedIconPathDeviceReady_String": "{slimevr}/icons/tracker_status_ready.png", + "Prop_NamedIconPathDeviceReadyAlert_String": "{slimevr}/icons/tracker_status_ready_alert.png", + "Prop_NamedIconPathDeviceNotReady_String": "{slimevr}/icons/tracker_status_error.png", + "Prop_NamedIconPathDeviceStandby_String": "{slimevr}/icons/tracker_status_standby.png", + "Prop_NamedIconPathDeviceAlertLow_String": "{slimevr}/icons/tracker_status_ready_low.png" + } + } +} diff --git a/src/IVRDriver.hpp b/src/IVRDriver.hpp index 479f5d3..240cc54 100644 --- a/src/IVRDriver.hpp +++ b/src/IVRDriver.hpp @@ -34,7 +34,7 @@ namespace SlimeVRDriver { * * @return A vector of current frame's OpenVR events. */ - virtual std::vector GetOpenVREvents() = 0; + virtual const std::vector& GetOpenVREvents() = 0; /** * Returns the milliseconds between last frame and this frame. diff --git a/src/TrackerDevice.cpp b/src/TrackerDevice.cpp index 2c27cf3..5efa691 100644 --- a/src/TrackerDevice.cpp +++ b/src/TrackerDevice.cpp @@ -16,8 +16,8 @@ void SlimeVRDriver::TrackerDevice::Update() { if (device_index_ == vr::k_unTrackedDeviceIndexInvalid) return; // Check if this device was asked to be identified - auto events = GetDriver()->GetOpenVREvents(); - for (auto event : events) { + auto& events = GetDriver()->GetOpenVREvents(); + for (const auto& event : events) { // 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 //if (event.trackedDeviceIndex == device_index_) { if (event.eventType == vr::EVREventType::VREvent_Input_HapticVibration) { @@ -153,38 +153,18 @@ vr::EVRInitError SlimeVRDriver::TrackerDevice::Activate(uint32_t unObjectId) { logger_->Log("Activating tracker {}", serial_); - // Get the properties handle auto props = GetDriver()->GetProperties()->TrackedDeviceToPropertyContainer(device_index_); - - // Set some universe ID (Must be 2 or higher) - GetDriver()->GetProperties()->SetUint64Property(props, vr::Prop_CurrentUniverseId_Uint64, 4); - // Set up a model "number" (not needed but good to have) + GetDriver()->GetProperties()->SetStringProperty(props, vr::Prop_ManufacturerName_String, "SlimeVR"); GetDriver()->GetProperties()->SetStringProperty(props, vr::Prop_ModelNumber_String, "SlimeVR Virtual Tracker"); - // Opt out of hand selection - GetDriver()->GetProperties()->SetInt32Property(props, vr::Prop_ControllerRoleHint_Int32, vr::ETrackedControllerRole::TrackedControllerRole_OptOut); - vr::VRProperties()->SetInt32Property(props, vr::Prop_DeviceClass_Int32, vr::TrackedDeviceClass_GenericTracker); - vr::VRProperties()->SetInt32Property(props, vr::Prop_ControllerHandSelectionPriority_Int32, -1); - - // Set up a render model path GetDriver()->GetProperties()->SetStringProperty(props, vr::Prop_RenderModelName_String, "{htc}/rendermodels/vr_tracker_vive_1_0"); - // Set the icon - GetDriver()->GetProperties()->SetStringProperty(props, vr::Prop_NamedIconPathDeviceReady_String, "{slimevr}/icons/tracker_status_ready.png"); - - GetDriver()->GetProperties()->SetStringProperty(props, vr::Prop_NamedIconPathDeviceOff_String, "{slimevr}/icons/tracker_status_off.png"); - GetDriver()->GetProperties()->SetStringProperty(props, vr::Prop_NamedIconPathDeviceSearching_String, "{slimevr}/icons/tracker_status_ready.png"); - GetDriver()->GetProperties()->SetStringProperty(props, vr::Prop_NamedIconPathDeviceSearchingAlert_String, "{slimevr}/icons/tracker_status_ready_alert.png"); - GetDriver()->GetProperties()->SetStringProperty(props, vr::Prop_NamedIconPathDeviceReadyAlert_String, "{slimevr}/icons/tracker_status_ready_alert.png"); - GetDriver()->GetProperties()->SetStringProperty(props, vr::Prop_NamedIconPathDeviceNotReady_String, "{slimevr}/icons/tracker_status_error.png"); - GetDriver()->GetProperties()->SetStringProperty(props, vr::Prop_NamedIconPathDeviceStandby_String, "{slimevr}/icons/tracker_status_standby.png"); - GetDriver()->GetProperties()->SetStringProperty(props, vr::Prop_NamedIconPathDeviceAlertLow_String, "{slimevr}/icons/tracker_status_ready_low.png"); - + // Some device properties will be derived at runtime by SteamVR + // using the profile, such as the device class and controller type GetDriver()->GetProperties()->SetStringProperty(props, vr::Prop_InputProfilePath_String, "{slimevr}/input/slimevr_tracker_profile.json"); - GetDriver()->GetProperties()->SetStringProperty(props, vr::Prop_ControllerType_String, "slimevr_tracker"); - + // Doesn't apply until restart of SteamVR auto role = GetViveRole(tracker_role_); if (role != "") { vr::VRSettings()->SetString(vr::k_pch_Trackers_Section, ("/devices/slimevr/" + serial_).c_str(), role.c_str()); diff --git a/src/TrackerRole.cpp b/src/TrackerRole.cpp index 865a5e6..7f10cb0 100644 --- a/src/TrackerRole.cpp +++ b/src/TrackerRole.cpp @@ -60,12 +60,14 @@ std::string GetViveRoleHint(TrackerRole role) { std::string GetViveRole(TrackerRole role) { switch (role) { - case LEFT_CONTROLLER: - case RIGHT_CONTROLLER: case GENERIC_CONTROLLER: + return "TrackerRole_Handed"; + case LEFT_CONTROLLER: case LEFT_HAND: + return "TrackerRole_Handed,TrackedControllerRole_LeftHand"; + case RIGHT_CONTROLLER: case RIGHT_HAND: - return "TrackerRole_Handed"; + return "TrackerRole_Handed,TrackedControllerRole_RightHand"; case LEFT_FOOT: return "TrackerRole_LeftFoot"; case RIGHT_FOOT: @@ -97,7 +99,9 @@ std::string GetViveRole(TrackerRole role) { DeviceType GetDeviceType(TrackerRole role) { switch (role) { case LEFT_CONTROLLER: + case LEFT_HAND: case RIGHT_CONTROLLER: + case RIGHT_HAND: case GENERIC_CONTROLLER: return DeviceType::CONTROLLER; case HMD: diff --git a/src/VRDriver.cpp b/src/VRDriver.cpp index 19da57b..9d8dcd2 100644 --- a/src/VRDriver.cpp +++ b/src/VRDriver.cpp @@ -109,8 +109,6 @@ void SlimeVRDriver::VRDriver::RunPoseRequestThread() { if (result.has_value()) { current_universe_.emplace(universe, result.value()); logger_->Log("Found current universe"); - } else { - logger_->Log("Failed to find current universe!"); } } } else if (universe_error != last_universe_error_) { @@ -216,6 +214,7 @@ void SlimeVRDriver::VRDriver::OnBridgeMessage(const messages::ProtobufMessage& m messages::TrackerAdded ta = message.tracker_added(); switch(GetDeviceType(static_cast(ta.tracker_role()))) { case DeviceType::TRACKER: + case DeviceType::CONTROLLER: AddDevice(std::make_shared(ta.tracker_serial(), ta.tracker_id(), static_cast(ta.tracker_role()))); break; } @@ -266,7 +265,7 @@ std::vector> SlimeVRDriver::VRDriver:: return devices; } -std::vector SlimeVRDriver::VRDriver::GetOpenVREvents() { +const std::vector& SlimeVRDriver::VRDriver::GetOpenVREvents() { return openvr_events_; } @@ -455,7 +454,7 @@ std::optional SlimeVRDriver::VRDriver::Searc } } - if (default_chap_path_.has_value()) { + if (default_chap_path_.has_value() && std::filesystem::exists(default_chap_path_.value())) { try { return SearchUniverse(simdjson::padded_string::load(default_chap_path_.value()).take_value(), target); } diff --git a/src/VRDriver.hpp b/src/VRDriver.hpp index e6c77ce..a0a6d82 100644 --- a/src/VRDriver.hpp +++ b/src/VRDriver.hpp @@ -20,7 +20,7 @@ namespace SlimeVRDriver { public: // Inherited via IVRDriver virtual std::vector> GetDevices() override; - virtual std::vector GetOpenVREvents() override; + virtual const std::vector& GetOpenVREvents() override; virtual std::chrono::milliseconds GetLastFrameTime() override; virtual bool AddDevice(std::shared_ptr device) override; virtual SettingsValue GetSettingsValue(std::string key) override;