The open source OpenXR runtime
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

d/psvr: Refactor device creation in preperation of builders

+87 -17
+7 -9
src/xrt/drivers/psvr/psvr_device.c
··· 965 965 */ 966 966 967 967 struct xrt_device * 968 - psvr_device_create(struct hid_device_info *sensor_hid_info, 969 - struct hid_device_info *control_hid_info, 970 - struct xrt_prober *xp, 971 - enum u_logging_level log_level) 968 + psvr_device_create_auto_prober(struct hid_device_info *sensor_hid_info, 969 + struct hid_device_info *control_hid_info, 970 + struct xrt_tracked_psvr *tracker, 971 + enum u_logging_level log_level) 972 972 { 973 973 enum u_device_alloc_flags flags = 974 974 (enum u_device_alloc_flags)(U_DEVICE_ALLOC_HMD | U_DEVICE_ALLOC_TRACKING_NONE); ··· 1101 1101 u_device_dump_config(&psvr->base, __func__, "Sony PSVR"); 1102 1102 } 1103 1103 1104 - // If there is a tracking factory use it. 1105 - if (xp->tracking != NULL) { 1106 - xp->tracking->create_tracked_psvr(xp->tracking, &psvr->tracker); 1107 - } 1104 + // Did we get a tracker, use it! 1105 + psvr->tracker = tracker; 1108 1106 1109 1107 // Use the new origin if we got a tracking system. 1110 1108 if (psvr->tracker != NULL) { ··· 1112 1110 } 1113 1111 1114 1112 psvr->base.orientation_tracking_supported = true; 1115 - psvr->base.position_tracking_supported = xp->tracking != NULL; 1113 + psvr->base.position_tracking_supported = psvr->tracker != NULL; 1116 1114 psvr->base.device_type = XRT_DEVICE_TYPE_HMD; 1117 1115 1118 1116 PSVR_DEBUG(psvr, "YES!");
+6 -7
src/xrt/drivers/psvr/psvr_device.h
··· 31 31 * 32 32 */ 33 33 34 - #define PSVR_VID 0x054c 35 - #define PSVR_PID 0x09af 36 - 37 34 #define PSVR_HANDLE_IFACE 4 38 35 #define PSVR_CONTROL_IFACE 5 39 36 ··· 73 70 * Structs 74 71 * 75 72 */ 73 + 74 + struct xrt_tracked_psvr; 76 75 77 76 /*! 78 77 * A parsed single gyro, accel and tick sample. ··· 124 123 */ 125 124 126 125 struct xrt_device * 127 - psvr_device_create(struct hid_device_info *sensor_hid_info, 128 - struct hid_device_info *control_hid_info, 129 - struct xrt_prober *xp, 130 - enum u_logging_level log_level); 126 + psvr_device_create_auto_prober(struct hid_device_info *sensor_hid_info, 127 + struct hid_device_info *control_hid_info, 128 + struct xrt_tracked_psvr *tracker, 129 + enum u_logging_level log_level); 131 130 132 131 bool 133 132 psvr_parse_sensor_packet(struct psvr_parsed_sensor *sensor, const uint8_t *buffer, int size);
+28
src/xrt/drivers/psvr/psvr_interface.h
··· 9 9 10 10 #pragma once 11 11 12 + #include "xrt/xrt_compiler.h" 13 + 14 + 12 15 #ifdef __cplusplus 13 16 extern "C" { 14 17 #endif 15 18 19 + struct xrt_tracked_psvr; 20 + 21 + 16 22 /*! 17 23 * @defgroup drv_psvr PSVR driver 18 24 * @ingroup drv 19 25 * 20 26 * @brief Driver for the Sony PSVR HMD. 21 27 */ 28 + 29 + /*! 30 + * Vendor id for PSVR. 31 + * 32 + * @ingroup drv_psvr 33 + */ 34 + #define PSVR_VID 0x054c 35 + 36 + /*! 37 + * Product id for PSVR. 38 + * 39 + * @ingroup drv_psvr 40 + */ 41 + #define PSVR_PID 0x09af 42 + 43 + /*! 44 + * Create PSVR device, with a optional tracker. 45 + * 46 + * @ingroup drv_psvr 47 + */ 48 + struct xrt_device * 49 + psvr_device_create(struct xrt_tracked_psvr *tracker); 22 50 23 51 /*! 24 52 * Create a probe for PSVR devices.
+46 -1
src/xrt/drivers/psvr/psvr_prober.c
··· 14 14 15 15 #include <hidapi.h> 16 16 #include "xrt/xrt_prober.h" 17 + #include "xrt/xrt_tracking.h" 17 18 18 19 #include "util/u_misc.h" 19 20 #include "util/u_debug.h" ··· 106 107 107 108 if (info_control != NULL && info_handle != NULL) { 108 109 if (ppsvr->enabled) { 109 - dev = psvr_device_create(info_handle, info_control, xp, ppsvr->log_level); 110 + // If there is a tracking factory use it. 111 + struct xrt_tracked_psvr *tracker = NULL; 112 + if (xp->tracking != NULL) { 113 + xp->tracking->create_tracked_psvr(xp->tracking, &tracker); 114 + } 115 + 116 + dev = psvr_device_create_auto_prober(info_handle, info_control, tracker, ppsvr->log_level); 110 117 } else { 111 118 PSVR_DEBUG(ppsvr, "Found a PSVR hmd but driver is disabled"); 112 119 } ··· 141 148 142 149 return &ppsvr->base; 143 150 } 151 + 152 + struct xrt_device * 153 + psvr_device_create(struct xrt_tracked_psvr *tracker) 154 + { 155 + struct hid_device_info *info_control = NULL; 156 + struct hid_device_info *info_handle = NULL; 157 + struct hid_device_info *cur_dev = NULL; 158 + struct hid_device_info *devs = NULL; 159 + struct xrt_device *xdev = NULL; 160 + enum u_logging_level log_level = debug_get_log_option_psvr_log(); 161 + 162 + devs = hid_enumerate(PSVR_VID, PSVR_PID); 163 + cur_dev = devs; 164 + 165 + for (; cur_dev != NULL; cur_dev = cur_dev->next) { 166 + switch (cur_dev->interface_number) { 167 + case PSVR_HANDLE_IFACE: info_handle = cur_dev; break; 168 + case PSVR_CONTROL_IFACE: info_control = cur_dev; break; 169 + default: break; 170 + } 171 + } 172 + 173 + if (info_handle == NULL) { 174 + U_LOG_IFL_W(log_level, "PSVR_HANDLE_IFACE: could not be opened!"); 175 + } 176 + 177 + if (info_control == NULL) { 178 + U_LOG_IFL_W(log_level, "PSVR_CONTROL_IFACE: could not be opened!"); 179 + } 180 + 181 + if (info_control != NULL && info_handle != NULL) { 182 + xdev = psvr_device_create_auto_prober(info_handle, info_control, tracker, log_level); 183 + } 184 + 185 + hid_free_enumeration(devs); 186 + 187 + return xdev; 188 + }