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

Part-of: <https://gitlab.freedesktop.org/monado/monado/-/merge_requests/2569>
This commit is contained in:
Beyley Cardellio authored and Marge Bot committed 2025-09-24 15:54:47 +00:00
1 parent 7722196d4e
commit f0254aa40c
5 files changed
+124 -27

No files matched your search

+83 -17
View File
@@ -4,9 +4,33 @@
* @file
* @brief SteamVR driver device implementation.
* @author Shawn Wallace <yungwallace@live.com>
* @author Beyley Cardellio <ep1cm1n10n123@gmail.com>
* @ingroup drv_steamvr_lh
*/
#include "math/m_api.h"
#include "math/m_relation_history.h"
#include "math/m_space.h"
#include "interfaces/context.hpp"
#include "util/u_debug.h"
#include "util/u_device.h"
#include "util/u_hand_simulation.h"
#include "util/u_hand_tracking.h"
#include "util/u_logging.h"
#include "util/u_json.hpp"
#include "xrt/xrt_defines.h"
#include "xrt/xrt_device.h"
#include "xrt/xrt_prober.h"
#include "vive/vive_poses.h"
#include "openvr_driver.h"
#include "device.hpp"
#include <cmath>
#include <functional>
#include <cstring>
@@ -14,22 +38,6 @@
#include <algorithm>
#include <map>
#include "math/m_api.h"
#include "math/m_relation_history.h"
#include "math/m_space.h"
#include "device.hpp"
#include "interfaces/context.hpp"
#include "util/u_debug.h"
#include "util/u_device.h"
#include "util/u_hand_simulation.h"
#include "util/u_hand_tracking.h"
#include "util/u_logging.h"
#include "util/u_json.hpp"
#include "xrt/xrt_defines.h"
#include "xrt/xrt_device.h"
#include "vive/vive_poses.h"
#include "openvr_driver.h"
#define DEV_ERR(...) U_LOG_IFL_E(ctx->log_level, __VA_ARGS__)
#define DEV_WARN(...) U_LOG_IFL_W(ctx->log_level, __VA_ARGS__)
@@ -947,12 +955,70 @@ Device::handle_property_write(const vr::PropertyWrite_t &prop)
return handle_generic_property_write(prop);
}
bool
HmdDevice::init_vive_pro_2(struct xrt_prober *xp)
{
xrt_result_t xret;
int ret = 0;
struct xrt_prober_device **devices = nullptr;
size_t device_count;
xret = xrt_prober_lock_list(xp, &devices, &device_count);
if (xret != XRT_SUCCESS) {
DEV_ERR("Failed to lock prober device list");
return false;
}
for (size_t i = 0; i < device_count; i++) {
struct xrt_prober_device *dev = devices[i];
if (dev->vendor_id == VP2_VID && dev->product_id == VP2_PID) {
DEV_INFO("Found Vive Pro 2 HID device");
struct os_hid_device *hid_dev = nullptr;
ret = xrt_prober_open_hid_interface(xp, dev, 0, &hid_dev);
if (ret != 0) {
DEV_ERR("Failed to open Vive Pro 2 HID interface");
break;
}
ret = vp2_hid_open(hid_dev, &this->vp2.hid);
if (ret != 0) {
DEV_ERR("Failed to open Vive Pro 2 HID device");
break;
}
break;
}
}
xrt_prober_unlock_list(xp, &devices);
int width, height;
vp2_resolution_get_extents(vp2_get_resolution(this->vp2.hid), &width, &height);
for (int i = 0; i < 2; i++) {
this->hmd_parts->base.views[i].display.w_pixels = width / 2;
this->hmd_parts->base.views[i].display.h_pixels = height;
this->hmd_parts->base.views[i].viewport.w_pixels = width / 2;
this->hmd_parts->base.views[i].viewport.h_pixels = height;
}
this->hmd_parts->base.views[1].viewport.x_pixels = width / 2;
this->hmd_parts->base.screens[0].w_pixels = width;
this->hmd_parts->base.screens[0].h_pixels = height;
return ret == 0;
}
vr::ETrackedPropertyError
HmdDevice::handle_property_write(const vr::PropertyWrite_t &prop)
{
switch (prop.prop) {
case vr::Prop_ModelNumber_String: {
auto model_number = std::string(static_cast<char *>(prop.pvBuffer), prop.unBufferSize);
std::string model_number(static_cast<char *>(prop.pvBuffer), prop.unBufferSize);
this->variant = vive_determine_variant(model_number.c_str());
+33 -7
View File
@@ -7,6 +7,18 @@
* @ingroup drv_steamvr_lh
*/
#include "interfaces/context.hpp"
#include "math/m_relation_history.h"
#include "xrt/xrt_device.h"
#include "vive/vive_common.h"
#include "vp2/vp2_hid.h"
#include "openvr_driver.h"
#include <string>
#include <vector>
#include <memory>
@@ -15,12 +27,6 @@
#include <condition_variable>
#include <mutex>
#include "interfaces/context.hpp"
#include "math/m_relation_history.h"
#include "xrt/xrt_device.h"
#include "openvr_driver.h"
#include "vive/vive_common.h"
class Context;
struct InputClass;
@@ -122,9 +128,23 @@ private:
init_chaperone(const std::string &steam_install);
};
struct VivePro2Data
{
vp2_hid *hid{nullptr};
~VivePro2Data()
{
if (hid != nullptr) {
vp2_hid_destroy(hid);
hid = nullptr;
}
}
};
class HmdDevice : public Device
{
public:
VIVE_VARIANT variant{VIVE_UNKNOWN};
xrt_pose eye[2];
float ipd{0.063}; // meters
struct Parts
@@ -139,6 +159,10 @@ public:
float max{1.0f};
};
struct VivePro2Data vp2
{
};
HmdDevice(const DeviceBuilder &builder);
xrt_result_t
@@ -174,6 +198,9 @@ public:
xrt_result_t
set_brightness(float brightness, bool relative);
bool
init_vive_pro_2(struct xrt_prober *xp);
private:
std::unique_ptr<Parts> hmd_parts{nullptr};
@@ -187,7 +214,6 @@ private:
std::mutex hmd_parts_mut;
float brightness{1.0f};
AnalogGainRange analog_gain_range{};
VIVE_VARIANT variant{VIVE_UNKNOWN};
};
class ControllerDevice : public Device
+6 -1
View File
@@ -237,6 +237,7 @@ Context::setup_hmd(const char *serial, vr::ITrackedDeviceServerDriver *driver)
hmd_parts->display = display;
hmd->set_hmd_parts(std::move(hmd_parts));
return true;
}
@@ -770,7 +771,7 @@ destroy(struct xrt_system_devices *xsysd)
}
extern "C" enum xrt_result
steamvr_lh_create_devices(struct xrt_system_devices **out_xsysd)
steamvr_lh_create_devices(struct xrt_prober *xp, struct xrt_system_devices **out_xsysd)
{
u_logging_level level = debug_get_log_option_lh_log();
// The driver likes to create a bunch of transient folders -
@@ -861,6 +862,10 @@ steamvr_lh_create_devices(struct xrt_system_devices **out_xsysd)
// Include the HMD
if (svrs->ctx->hmd) {
if (svrs->ctx->hmd->variant == VIVE_VARIANT_PRO2 && !svrs->ctx->hmd->init_vive_pro_2(xp)) {
U_LOG_IFL_W(level, "Found Vive Pro 2, but failed to initialize.");
}
// Always have a head at index 0 and iterate dev count.
xsysd->xdevs[xsysd->xdev_count] = svrs->ctx->hmd;
xsysd->static_roles.head = xsysd->xdevs[xsysd->xdev_count++];
@@ -34,7 +34,7 @@ extern "C" {
* @ingroup drv_steamvr_lh
*/
enum xrt_result
steamvr_lh_create_devices(struct xrt_system_devices **out_xsysd);
steamvr_lh_create_devices(struct xrt_prober *xp, struct xrt_system_devices **out_xsysd);
#ifdef __cplusplus
@@ -140,7 +140,7 @@ steamvr_open_system(struct xrt_builder *xb,
assert(out_xsysd != NULL);
assert(*out_xsysd == NULL);
enum xrt_result result = steamvr_lh_create_devices(out_xsysd);
enum xrt_result result = steamvr_lh_create_devices(xp, out_xsysd);
if (result != XRT_SUCCESS) {
SVR_ERROR("Unable to create devices");