The open source OpenXR runtime

d/steamvr_lh + t/common: Initialize VP2 HID driver when applicable

Part-of: <https://gitlab.freedesktop.org/monado/monado/-/merge_requests/2569>

authored by

Beyley Cardellio and committed by
Marge Bot
f0254aa4 7722196d

+116 -19
+75 -9
src/xrt/drivers/steamvr_lh/device.cpp
··· 4 4 * @file 5 5 * @brief SteamVR driver device implementation. 6 6 * @author Shawn Wallace <yungwallace@live.com> 7 + * @author Beyley Cardellio <ep1cm1n10n123@gmail.com> 7 8 * @ingroup drv_steamvr_lh 8 9 */ 9 10 10 - #include <cmath> 11 - #include <functional> 12 - #include <cstring> 13 - #include <thread> 14 - #include <algorithm> 15 - #include <map> 16 - 17 11 #include "math/m_api.h" 18 12 #include "math/m_relation_history.h" 19 13 #include "math/m_space.h" 20 - #include "device.hpp" 14 + 21 15 #include "interfaces/context.hpp" 16 + 22 17 #include "util/u_debug.h" 23 18 #include "util/u_device.h" 24 19 #include "util/u_hand_simulation.h" 25 20 #include "util/u_hand_tracking.h" 26 21 #include "util/u_logging.h" 27 22 #include "util/u_json.hpp" 23 + 28 24 #include "xrt/xrt_defines.h" 29 25 #include "xrt/xrt_device.h" 26 + #include "xrt/xrt_prober.h" 30 27 31 28 #include "vive/vive_poses.h" 29 + 32 30 #include "openvr_driver.h" 31 + 32 + #include "device.hpp" 33 + 34 + #include <cmath> 35 + #include <functional> 36 + #include <cstring> 37 + #include <thread> 38 + #include <algorithm> 39 + #include <map> 40 + 33 41 34 42 #define DEV_ERR(...) U_LOG_IFL_E(ctx->log_level, __VA_ARGS__) 35 43 #define DEV_WARN(...) U_LOG_IFL_W(ctx->log_level, __VA_ARGS__) ··· 947 955 return handle_generic_property_write(prop); 948 956 } 949 957 958 + bool 959 + HmdDevice::init_vive_pro_2(struct xrt_prober *xp) 960 + { 961 + xrt_result_t xret; 962 + int ret = 0; 963 + 964 + struct xrt_prober_device **devices = nullptr; 965 + size_t device_count; 966 + 967 + xret = xrt_prober_lock_list(xp, &devices, &device_count); 968 + if (xret != XRT_SUCCESS) { 969 + DEV_ERR("Failed to lock prober device list"); 970 + return false; 971 + } 972 + 973 + for (size_t i = 0; i < device_count; i++) { 974 + struct xrt_prober_device *dev = devices[i]; 975 + 976 + if (dev->vendor_id == VP2_VID && dev->product_id == VP2_PID) { 977 + DEV_INFO("Found Vive Pro 2 HID device"); 978 + struct os_hid_device *hid_dev = nullptr; 979 + ret = xrt_prober_open_hid_interface(xp, dev, 0, &hid_dev); 980 + if (ret != 0) { 981 + DEV_ERR("Failed to open Vive Pro 2 HID interface"); 982 + break; 983 + } 984 + 985 + ret = vp2_hid_open(hid_dev, &this->vp2.hid); 986 + if (ret != 0) { 987 + DEV_ERR("Failed to open Vive Pro 2 HID device"); 988 + break; 989 + } 990 + 991 + break; 992 + } 993 + } 994 + 995 + xrt_prober_unlock_list(xp, &devices); 996 + 997 + int width, height; 998 + vp2_resolution_get_extents(vp2_get_resolution(this->vp2.hid), &width, &height); 999 + 1000 + for (int i = 0; i < 2; i++) { 1001 + this->hmd_parts->base.views[i].display.w_pixels = width / 2; 1002 + this->hmd_parts->base.views[i].display.h_pixels = height; 1003 + 1004 + this->hmd_parts->base.views[i].viewport.w_pixels = width / 2; 1005 + this->hmd_parts->base.views[i].viewport.h_pixels = height; 1006 + } 1007 + 1008 + this->hmd_parts->base.views[1].viewport.x_pixels = width / 2; 1009 + 1010 + this->hmd_parts->base.screens[0].w_pixels = width; 1011 + this->hmd_parts->base.screens[0].h_pixels = height; 1012 + 1013 + return ret == 0; 1014 + } 1015 + 950 1016 vr::ETrackedPropertyError 951 1017 HmdDevice::handle_property_write(const vr::PropertyWrite_t &prop) 952 1018 { 953 1019 switch (prop.prop) { 954 1020 case vr::Prop_ModelNumber_String: { 955 - auto model_number = std::string(static_cast<char *>(prop.pvBuffer), prop.unBufferSize); 1021 + std::string model_number(static_cast<char *>(prop.pvBuffer), prop.unBufferSize); 956 1022 957 1023 this->variant = vive_determine_variant(model_number.c_str()); 958 1024
+33 -7
src/xrt/drivers/steamvr_lh/device.hpp
··· 7 7 * @ingroup drv_steamvr_lh 8 8 */ 9 9 10 + #include "interfaces/context.hpp" 11 + 12 + #include "math/m_relation_history.h" 13 + 14 + #include "xrt/xrt_device.h" 15 + 16 + #include "vive/vive_common.h" 17 + 18 + #include "vp2/vp2_hid.h" 19 + 20 + #include "openvr_driver.h" 21 + 10 22 #include <string> 11 23 #include <vector> 12 24 #include <memory> ··· 14 26 15 27 #include <condition_variable> 16 28 #include <mutex> 17 - 18 - #include "interfaces/context.hpp" 19 - #include "math/m_relation_history.h" 20 - #include "xrt/xrt_device.h" 21 - #include "openvr_driver.h" 22 - #include "vive/vive_common.h" 23 29 24 30 class Context; 25 31 struct InputClass; ··· 122 128 init_chaperone(const std::string &steam_install); 123 129 }; 124 130 131 + struct VivePro2Data 132 + { 133 + vp2_hid *hid{nullptr}; 134 + 135 + ~VivePro2Data() 136 + { 137 + if (hid != nullptr) { 138 + vp2_hid_destroy(hid); 139 + hid = nullptr; 140 + } 141 + } 142 + }; 143 + 125 144 class HmdDevice : public Device 126 145 { 127 146 public: 147 + VIVE_VARIANT variant{VIVE_UNKNOWN}; 128 148 xrt_pose eye[2]; 129 149 float ipd{0.063}; // meters 130 150 struct Parts ··· 137 157 { 138 158 float min{0.1f}; 139 159 float max{1.0f}; 160 + }; 161 + 162 + struct VivePro2Data vp2 163 + { 140 164 }; 141 165 142 166 HmdDevice(const DeviceBuilder &builder); ··· 174 198 xrt_result_t 175 199 set_brightness(float brightness, bool relative); 176 200 201 + bool 202 + init_vive_pro_2(struct xrt_prober *xp); 203 + 177 204 private: 178 205 std::unique_ptr<Parts> hmd_parts{nullptr}; 179 206 ··· 187 214 std::mutex hmd_parts_mut; 188 215 float brightness{1.0f}; 189 216 AnalogGainRange analog_gain_range{}; 190 - VIVE_VARIANT variant{VIVE_UNKNOWN}; 191 217 }; 192 218 193 219 class ControllerDevice : public Device
+6 -1
src/xrt/drivers/steamvr_lh/steamvr_lh.cpp
··· 237 237 238 238 hmd_parts->display = display; 239 239 hmd->set_hmd_parts(std::move(hmd_parts)); 240 + 240 241 return true; 241 242 } 242 243 ··· 770 771 } 771 772 772 773 extern "C" enum xrt_result 773 - steamvr_lh_create_devices(struct xrt_system_devices **out_xsysd) 774 + steamvr_lh_create_devices(struct xrt_prober *xp, struct xrt_system_devices **out_xsysd) 774 775 { 775 776 u_logging_level level = debug_get_log_option_lh_log(); 776 777 // The driver likes to create a bunch of transient folders - ··· 861 862 862 863 // Include the HMD 863 864 if (svrs->ctx->hmd) { 865 + if (svrs->ctx->hmd->variant == VIVE_VARIANT_PRO2 && !svrs->ctx->hmd->init_vive_pro_2(xp)) { 866 + U_LOG_IFL_W(level, "Found Vive Pro 2, but failed to initialize."); 867 + } 868 + 864 869 // Always have a head at index 0 and iterate dev count. 865 870 xsysd->xdevs[xsysd->xdev_count] = svrs->ctx->hmd; 866 871 xsysd->static_roles.head = xsysd->xdevs[xsysd->xdev_count++];
+1 -1
src/xrt/drivers/steamvr_lh/steamvr_lh_interface.h
··· 34 34 * @ingroup drv_steamvr_lh 35 35 */ 36 36 enum xrt_result 37 - steamvr_lh_create_devices(struct xrt_system_devices **out_xsysd); 37 + steamvr_lh_create_devices(struct xrt_prober *xp, struct xrt_system_devices **out_xsysd); 38 38 39 39 40 40 #ifdef __cplusplus
+1 -1
src/xrt/targets/common/target_builder_steamvr.c
··· 140 140 assert(out_xsysd != NULL); 141 141 assert(*out_xsysd == NULL); 142 142 143 - enum xrt_result result = steamvr_lh_create_devices(out_xsysd); 143 + enum xrt_result result = steamvr_lh_create_devices(xp, out_xsysd); 144 144 145 145 if (result != XRT_SUCCESS) { 146 146 SVR_ERROR("Unable to create devices");