The open source OpenXR runtime
0
fork

Configure Feed

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

d/psmv: Refactor device creation in preperation of builders

+54 -21
+38 -21
src/xrt/drivers/psmv/psmv_driver.c
··· 1000 1000 cJSON *attached_data, 1001 1001 struct xrt_device **out_xdevs) 1002 1002 { 1003 - struct os_hid_device *hid = NULL; 1004 - int ret; 1005 - 1006 1003 // We do not receive any sensor packages on USB. 1007 1004 if (devices[index]->bus != XRT_BUS_TYPE_BLUETOOTH) { 1008 1005 return 0; ··· 1015 1012 default: return -1; 1016 1013 } 1017 1014 1018 - ret = xrt_prober_open_hid_interface(xp, devices[index], 0, &hid); 1019 - if (ret != 0) { 1015 + struct xrt_tracked_psmv *tracker = NULL; 1016 + if (xp->tracking != NULL) { 1017 + xp->tracking->create_tracked_psmv(xp->tracking, &tracker); 1018 + } 1019 + 1020 + struct xrt_device *xdev = psmv_device_create(xp, devices[index], tracker); 1021 + if (xdev != NULL) { 1020 1022 return -1; 1021 1023 } 1022 1024 1025 + *out_xdevs = xdev; 1026 + 1027 + return 1; 1028 + } 1029 + 1030 + struct xrt_device * 1031 + psmv_device_create(struct xrt_prober *xp, struct xrt_prober_device *xpdev, struct xrt_tracked_psmv *tracker) 1032 + { 1033 + struct os_hid_device *hid = NULL; 1034 + int ret = 0; 1035 + 1036 + ret = xrt_prober_open_hid_interface(xp, xpdev, 0, &hid); 1037 + if (ret != 0) { 1038 + return NULL; 1039 + } 1040 + 1023 1041 enum u_device_alloc_flags flags = U_DEVICE_ALLOC_TRACKING_NONE; 1024 1042 struct psmv_device *psmv = U_DEVICE_ALLOCATE(struct psmv_device, flags, 13, 1); 1025 1043 psmv->base.destroy = psmv_device_destroy; ··· 1032 1050 psmv->fusion.rot.w = 1.0f; 1033 1051 psmv->fusion.fusion = imu_fusion_create(); 1034 1052 psmv->log_level = debug_get_log_option_psmv_log(); 1035 - psmv->pid = devices[index]->product_id; 1053 + psmv->pid = xpdev->product_id; 1036 1054 psmv->hid = hid; 1037 1055 1038 - struct xrt_prober_device *dev = devices[index]; 1039 - int str_serial_ret = xrt_prober_get_string_descriptor(xp, dev, XRT_PROBER_STRING_SERIAL_NUMBER, 1040 - (unsigned char *)psmv->base.serial, XRT_DEVICE_NAME_LEN); 1056 + int str_serial_ret = xrt_prober_get_string_descriptor( // 1057 + xp, // 1058 + xpdev, // 1059 + XRT_PROBER_STRING_SERIAL_NUMBER, // 1060 + (unsigned char *)psmv->base.serial, // 1061 + XRT_DEVICE_NAME_LEN); // 1041 1062 1042 1063 static int controller_num = 0; 1043 1064 if (str_serial_ret <= 0) { ··· 1050 1071 m_imu_pre_filter_init(&psmv->calibration.prefilter, 1.f, 1.f); 1051 1072 1052 1073 // Default variance 1053 - switch (devices[index]->product_id) { 1074 + switch (xpdev->product_id) { 1054 1075 case PSMV_PID_ZCM1: 1055 1076 // Note that there is one axis "weird" in each - this model has 1056 1077 // 2-axis sensors. ··· 1072 1093 break; 1073 1094 default: 1074 1095 //! @todo cleanup to not leak 1075 - return -1; 1096 + return NULL; 1076 1097 } 1077 1098 1078 1099 // Setup inputs. ··· 1098 1119 if (ret != 0) { 1099 1120 PSMV_ERROR(psmv, "Failed to init mutex!"); 1100 1121 psmv_device_destroy(&psmv->base); 1101 - return ret; 1122 + return NULL; 1102 1123 } 1103 1124 1104 1125 // Thread and other state. ··· 1106 1127 if (ret != 0) { 1107 1128 PSMV_ERROR(psmv, "Failed to init threading!"); 1108 1129 psmv_device_destroy(&psmv->base); 1109 - return ret; 1130 + return NULL; 1110 1131 } 1111 1132 // Get calibration data. 1112 1133 ret = psmv_get_calibration(psmv); 1113 1134 if (ret != 0) { 1114 1135 PSMV_ERROR(psmv, "Failed to get calibration data!"); 1115 1136 psmv_device_destroy(&psmv->base); 1116 - return ret; 1137 + return NULL; 1117 1138 } 1118 1139 1119 1140 #if 1 1120 1141 // 45mm 1121 1142 float diameter = PSMV_BALL_DIAMETER_M; 1122 1143 (void)diameter; 1123 - if (xp->tracking != NULL) { 1124 - xp->tracking->create_tracked_psmv(xp->tracking, &psmv->ball); 1125 - } 1144 + psmv->ball = tracker; 1126 1145 #endif 1127 1146 1128 1147 if (psmv->ball != NULL) { ··· 1155 1174 if (ret != 0) { 1156 1175 PSMV_ERROR(psmv, "Failed to start thread!"); 1157 1176 psmv_device_destroy(&psmv->base); 1158 - return ret; 1177 + return NULL; 1159 1178 } 1160 1179 1161 1180 // Start the variable tracking now that everything is in place. ··· 1220 1239 psmv->base.device_type = XRT_DEVICE_TYPE_ANY_HAND_CONTROLLER; 1221 1240 1222 1241 // And finally done 1223 - *out_xdevs = &psmv->base; 1224 - 1225 - return 1; 1242 + return &psmv->base; 1226 1243 } 1227 1244 1228 1245
+16
src/xrt/drivers/psmv/psmv_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 18 + 19 + 20 + struct xrt_device; 21 + struct xrt_tracked_psmv; 15 22 16 23 /*! 17 24 * @defgroup drv_psmv PS Move driver ··· 24 31 #define PSMV_VID 0x054c 25 32 #define PSMV_PID_ZCM1 0x03d5 26 33 #define PSMV_PID_ZCM2 0x0c5e 34 + 35 + /*! 36 + * Function to create a PSMV device. 37 + * 38 + * @ingroup drv_psmv 39 + * @see xrt_builder 40 + */ 41 + struct xrt_device * 42 + psmv_device_create(struct xrt_prober *xp, struct xrt_prober_device *xpdev, struct xrt_tracked_psmv *tracker); 27 43 28 44 /*! 29 45 * Probing function for the PS Move devices.