diff --git a/src/xrt/drivers/psvr/psvr_device.c b/src/xrt/drivers/psvr/psvr_device.c index 96e87acec..7f0808b70 100644 --- a/src/xrt/drivers/psvr/psvr_device.c +++ b/src/xrt/drivers/psvr/psvr_device.c @@ -965,10 +965,10 @@ psvr_compute_distortion(struct xrt_device *xdev, int view, float u, float v, str */ struct xrt_device * -psvr_device_create(struct hid_device_info *sensor_hid_info, - struct hid_device_info *control_hid_info, - struct xrt_prober *xp, - enum u_logging_level log_level) +psvr_device_create_auto_prober(struct hid_device_info *sensor_hid_info, + struct hid_device_info *control_hid_info, + struct xrt_tracked_psvr *tracker, + enum u_logging_level log_level) { enum u_device_alloc_flags flags = (enum u_device_alloc_flags)(U_DEVICE_ALLOC_HMD | U_DEVICE_ALLOC_TRACKING_NONE); @@ -1101,10 +1101,8 @@ psvr_device_create(struct hid_device_info *sensor_hid_info, u_device_dump_config(&psvr->base, __func__, "Sony PSVR"); } - // If there is a tracking factory use it. - if (xp->tracking != NULL) { - xp->tracking->create_tracked_psvr(xp->tracking, &psvr->tracker); - } + // Did we get a tracker, use it! + psvr->tracker = tracker; // Use the new origin if we got a tracking system. if (psvr->tracker != NULL) { @@ -1112,7 +1110,7 @@ psvr_device_create(struct hid_device_info *sensor_hid_info, } psvr->base.orientation_tracking_supported = true; - psvr->base.position_tracking_supported = xp->tracking != NULL; + psvr->base.position_tracking_supported = psvr->tracker != NULL; psvr->base.device_type = XRT_DEVICE_TYPE_HMD; PSVR_DEBUG(psvr, "YES!"); diff --git a/src/xrt/drivers/psvr/psvr_device.h b/src/xrt/drivers/psvr/psvr_device.h index d56f38ed4..fad84874e 100644 --- a/src/xrt/drivers/psvr/psvr_device.h +++ b/src/xrt/drivers/psvr/psvr_device.h @@ -31,9 +31,6 @@ extern "C" { * */ -#define PSVR_VID 0x054c -#define PSVR_PID 0x09af - #define PSVR_HANDLE_IFACE 4 #define PSVR_CONTROL_IFACE 5 @@ -74,6 +71,8 @@ enum psvr_status_bits * */ +struct xrt_tracked_psvr; + /*! * A parsed single gyro, accel and tick sample. * @@ -124,10 +123,10 @@ struct psvr_parsed_status */ struct xrt_device * -psvr_device_create(struct hid_device_info *sensor_hid_info, - struct hid_device_info *control_hid_info, - struct xrt_prober *xp, - enum u_logging_level log_level); +psvr_device_create_auto_prober(struct hid_device_info *sensor_hid_info, + struct hid_device_info *control_hid_info, + struct xrt_tracked_psvr *tracker, + enum u_logging_level log_level); bool psvr_parse_sensor_packet(struct psvr_parsed_sensor *sensor, const uint8_t *buffer, int size); diff --git a/src/xrt/drivers/psvr/psvr_interface.h b/src/xrt/drivers/psvr/psvr_interface.h index 16780fc7b..973fdf82d 100644 --- a/src/xrt/drivers/psvr/psvr_interface.h +++ b/src/xrt/drivers/psvr/psvr_interface.h @@ -9,10 +9,16 @@ #pragma once +#include "xrt/xrt_compiler.h" + + #ifdef __cplusplus extern "C" { #endif +struct xrt_tracked_psvr; + + /*! * @defgroup drv_psvr PSVR driver * @ingroup drv @@ -20,6 +26,28 @@ extern "C" { * @brief Driver for the Sony PSVR HMD. */ +/*! + * Vendor id for PSVR. + * + * @ingroup drv_psvr + */ +#define PSVR_VID 0x054c + +/*! + * Product id for PSVR. + * + * @ingroup drv_psvr + */ +#define PSVR_PID 0x09af + +/*! + * Create PSVR device, with a optional tracker. + * + * @ingroup drv_psvr + */ +struct xrt_device * +psvr_device_create(struct xrt_tracked_psvr *tracker); + /*! * Create a probe for PSVR devices. * diff --git a/src/xrt/drivers/psvr/psvr_prober.c b/src/xrt/drivers/psvr/psvr_prober.c index 63eb86d79..1246cc81b 100644 --- a/src/xrt/drivers/psvr/psvr_prober.c +++ b/src/xrt/drivers/psvr/psvr_prober.c @@ -14,6 +14,7 @@ #include #include "xrt/xrt_prober.h" +#include "xrt/xrt_tracking.h" #include "util/u_misc.h" #include "util/u_debug.h" @@ -106,7 +107,13 @@ psvr_prober_autoprobe(struct xrt_auto_prober *xap, if (info_control != NULL && info_handle != NULL) { if (ppsvr->enabled) { - dev = psvr_device_create(info_handle, info_control, xp, ppsvr->log_level); + // If there is a tracking factory use it. + struct xrt_tracked_psvr *tracker = NULL; + if (xp->tracking != NULL) { + xp->tracking->create_tracked_psvr(xp->tracking, &tracker); + } + + dev = psvr_device_create_auto_prober(info_handle, info_control, tracker, ppsvr->log_level); } else { PSVR_DEBUG(ppsvr, "Found a PSVR hmd but driver is disabled"); } @@ -141,3 +148,41 @@ psvr_create_auto_prober(void) return &ppsvr->base; } + +struct xrt_device * +psvr_device_create(struct xrt_tracked_psvr *tracker) +{ + struct hid_device_info *info_control = NULL; + struct hid_device_info *info_handle = NULL; + struct hid_device_info *cur_dev = NULL; + struct hid_device_info *devs = NULL; + struct xrt_device *xdev = NULL; + enum u_logging_level log_level = debug_get_log_option_psvr_log(); + + devs = hid_enumerate(PSVR_VID, PSVR_PID); + cur_dev = devs; + + for (; cur_dev != NULL; cur_dev = cur_dev->next) { + switch (cur_dev->interface_number) { + case PSVR_HANDLE_IFACE: info_handle = cur_dev; break; + case PSVR_CONTROL_IFACE: info_control = cur_dev; break; + default: break; + } + } + + if (info_handle == NULL) { + U_LOG_IFL_W(log_level, "PSVR_HANDLE_IFACE: could not be opened!"); + } + + if (info_control == NULL) { + U_LOG_IFL_W(log_level, "PSVR_CONTROL_IFACE: could not be opened!"); + } + + if (info_control != NULL && info_handle != NULL) { + xdev = psvr_device_create_auto_prober(info_handle, info_control, tracker, log_level); + } + + hid_free_enumeration(devs); + + return xdev; +}