From 2a3ac52eb88a685e210c39373f64775eabcc517b Mon Sep 17 00:00:00 2001 From: Pedro Santos Date: Fri, 21 Jul 2023 16:16:23 +0200 Subject: [PATCH] d/vive: Add Vive Pro 2 support --- src/xrt/drivers/vive/vive_device.c | 24 +++++- src/xrt/drivers/vive/vive_prober.c | 83 +++++++++++++++++++ .../common/target_builder_lighthouse.c | 1 + 3 files changed, 106 insertions(+), 2 deletions(-) diff --git a/src/xrt/drivers/vive/vive_device.c b/src/xrt/drivers/vive/vive_device.c index 930cbf007..b69ca4093 100644 --- a/src/xrt/drivers/vive/vive_device.c +++ b/src/xrt/drivers/vive/vive_device.c @@ -397,7 +397,7 @@ update_imu(struct vive_device *d, const void *buffer) angular_velocity.y = -angular_velocity.y; angular_velocity.z = -angular_velocity.z; break; - case VIVE_VARIANT_PRO: + case VIVE_VARIANT_PRO: { // flip all except y axis acceleration.x = -acceleration.x; acceleration.y = +acceleration.y; @@ -407,6 +407,17 @@ update_imu(struct vive_device *d, const void *buffer) angular_velocity.y = +angular_velocity.y; angular_velocity.z = -angular_velocity.z; break; + } + case VIVE_VARIANT_PRO2: { + acceleration.x = -acceleration.x; + acceleration.y = acceleration.y; + acceleration.z = -acceleration.z; + + angular_velocity.x = -angular_velocity.x; + angular_velocity.y = angular_velocity.y; + angular_velocity.z = -angular_velocity.z; + } break; + case VIVE_VARIANT_INDEX: { // Flip all axis and re-order. struct xrt_vec3 acceleration_fixed; @@ -891,7 +902,15 @@ compute_distortion(struct xrt_device *xdev, uint32_t view, float u, float v, str XRT_TRACE_MARKER(); struct vive_device *d = vive_device(xdev); - return u_compute_distortion_vive(&d->config.distortion.values[view], u, v, result); + bool status = u_compute_distortion_vive(&d->config.distortion.values[view], u, v, result); + + if (d->config.variant == VIVE_VARIANT_PRO2) { + // Flip Y coordinates + result->r.y = 1.0f - result->r.y; + result->g.y = 1.0f - result->g.y; + result->b.y = 1.0f - result->b.y; + } + return status; } void @@ -1108,6 +1127,7 @@ vive_device_create(struct os_hid_device *mainboard_dev, switch (d->config.variant) { case VIVE_VARIANT_VIVE: snprintf(d->base.str, XRT_DEVICE_NAME_LEN, "HTC Vive (vive)"); break; case VIVE_VARIANT_PRO: snprintf(d->base.str, XRT_DEVICE_NAME_LEN, "HTC Vive Pro (vive)"); break; + case VIVE_VARIANT_PRO2: snprintf(d->base.str, XRT_DEVICE_NAME_LEN, "HTC Vive Pro 2 (vive)"); break; case VIVE_VARIANT_INDEX: snprintf(d->base.str, XRT_DEVICE_NAME_LEN, "Valve Index (vive)"); break; case VIVE_UNKNOWN: snprintf(d->base.str, XRT_DEVICE_NAME_LEN, "Unknown HMD (vive)"); break; } diff --git a/src/xrt/drivers/vive/vive_prober.c b/src/xrt/drivers/vive/vive_prober.c index f7afb7c9f..94d31af85 100644 --- a/src/xrt/drivers/vive/vive_prober.c +++ b/src/xrt/drivers/vive/vive_prober.c @@ -25,6 +25,7 @@ static const char VIVE_PRODUCT_STRING[] = "HTC Vive"; static const char VIVE_PRO_PRODUCT_STRING[] = "VIVE Pro"; +static const char VIVE_PRO2_PRODUCT_STRING[] = "VIVE Pro 2"; static const char VALVE_INDEX_PRODUCT_STRING[] = "Index HMD"; static const char VALVE_INDEX_MANUFACTURER_STRING[] = "Valve"; static const char VIVE_MANUFACTURER_STRING[] = "HTC"; @@ -212,6 +213,84 @@ init_vive_pro(struct xrt_prober *xp, return; } +static void +init_vive_pro2(struct xrt_prober *xp, + struct xrt_prober_device *dev, + struct xrt_prober_device **devices, + size_t device_count, + enum u_logging_level log_level, + struct vive_tracking_status tstatus, + struct vive_source *vs, + struct vive_device **out_vdev) +{ + XRT_TRACE_MARKER(); + + log_vive_device(log_level, xp, dev); + + if (!u_prober_match_string(xp, dev, XRT_PROBER_STRING_MANUFACTURER, VIVE_MANUFACTURER_STRING) || + !u_prober_match_string(xp, dev, XRT_PROBER_STRING_PRODUCT, VIVE_PRO2_PRODUCT_STRING)) { + U_LOG_D("Vive Pro 2 manufacturer string did not match."); + return; + } + + struct os_hid_device *sensors_dev = NULL; + struct os_hid_device *watchman_dev = NULL; + + for (uint32_t i = 0; i < device_count; i++) { + struct xrt_prober_device *d = devices[i]; + + if (d->vendor_id != VALVE_VID && d->product_id != VIVE_PRO_LHR_PID) + continue; + + log_vive_device(log_level, xp, d); + + int result = xrt_prober_open_hid_interface(xp, d, 0, &sensors_dev); + if (result != 0) { + U_LOG_E("Could not open Vive Pro 2 sensors device."); + return; + } + + result = xrt_prober_open_hid_interface(xp, d, 1, &watchman_dev); + if (result != 0) { + U_LOG_E("Could not open headset watchman device."); + return; + } + + break; + } + + if (sensors_dev == NULL) { + U_LOG_E("Could not find Vive Pro 2 sensors device."); + return; + } + + if (watchman_dev == NULL) { + U_LOG_E("Could not find headset watchman device."); + return; + } + + struct os_hid_device *mainboard_dev = NULL; + + int result = xrt_prober_open_hid_interface(xp, dev, 0, &mainboard_dev); + if (result != 0) { + U_LOG_E("Could not open Vive mainboard device."); + free(sensors_dev); + return; + } + struct vive_device *d = + vive_device_create(mainboard_dev, sensors_dev, watchman_dev, VIVE_VARIANT_PRO, tstatus, vs); + if (d == NULL) { + free(sensors_dev); + free(mainboard_dev); + return; + } + + *out_vdev = d; + + return; +} + + static void init_valve_index(struct xrt_prober *xp, struct xrt_prober_device *dev, @@ -300,6 +379,10 @@ vive_found(struct xrt_prober *xp, init_vive_pro(xp, dev, devices, device_count, log_level, tstatus, vs, &vdev); break; } + case VIVE_PRO2_MAINBOARD_PID: { + init_vive_pro2(xp, dev, devices, device_count, log_level, tstatus, vs, &vdev); + break; + } case VIVE_PRO_LHR_PID: { init_valve_index(xp, dev, devices, device_count, log_level, tstatus, vs, &vdev); break; diff --git a/src/xrt/targets/common/target_builder_lighthouse.c b/src/xrt/targets/common/target_builder_lighthouse.c index 2fb4bbe12..9eb2c3846 100644 --- a/src/xrt/targets/common/target_builder_lighthouse.c +++ b/src/xrt/targets/common/target_builder_lighthouse.c @@ -633,6 +633,7 @@ lighthouse_open_system(struct xrt_builder *xb, switch (device->product_id) { case VIVE_PID: case VIVE_PRO_MAINBOARD_PID: + case VIVE_PRO2_MAINBOARD_PID: case VIVE_PRO_LHR_PID: { struct vive_source *vs = vive_source_create(&usysd->xfctx); int num_devices =