The open source OpenXR runtime
0
fork

Configure Feed

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

d/ohmd: Support generic trackers and clean up

authored by

Christoph Haag and committed by
Jakob Bornecrantz
2be4cbf4 dcbdcede

+145 -98
+145 -98
src/xrt/drivers/ohmd/oh_device.c
··· 48 48 // khronos simple inputs for generic controllers 49 49 SIMPLE_SELECT_CLICK = 0, 50 50 SIMPLE_MENU_CLICK, 51 - SIMPLE_GRIP_POSE, 52 - SIMPLE_AIM_POSE, 51 + 52 + // use same input field for touch controller, simple controller, and tracker 53 + GRIP_POSE, 54 + AIM_POSE, 53 55 54 56 // longest list of aliased enums has to start last for INPUT_INDICES_LAST to get the biggest value 55 57 OCULUS_TOUCH_X_CLICK = 0, ··· 69 71 OCULUS_TOUCH_THUMBSTICK_TOUCH, 70 72 OCULUS_TOUCH_THUMBSTICK, 71 73 OCULUS_TOUCH_THUMBREST_TOUCH, 72 - OCULUS_TOUCH_GRIP_POSE, 73 - OCULUS_TOUCH_AIM_POSE, 74 74 75 75 INPUT_INDICES_LAST 76 76 }; ··· 93 93 OPENHMD_GENERIC_CONTROLLER, 94 94 OPENHMD_OCULUS_RIFT_HMD, 95 95 OPENHMD_OCULUS_RIFT_CONTROLLER, 96 + OPENHMD_GENERIC_TRACKER, 96 97 }; 97 98 98 99 struct openhmd_values ··· 104 105 float warp_scale; 105 106 }; 106 107 108 + enum OHMD_DEVICE_INDEX 109 + { 110 + OHMD_HMD_INDEX = 0, 111 + OHMD_LEFT_INDEX, 112 + OHMD_RIGHT_INDEX, 113 + OHMD_FIRST_TRACKER_INDEX, 114 + }; 115 + 107 116 struct oh_device; 108 117 struct oh_system 109 118 { 110 119 struct xrt_tracking_origin base; 120 + 111 121 struct oh_device *devices[XRT_MAX_DEVICES_PER_PROBE]; 112 - 113 - //! index into oh_system::devices 114 - int hmd_idx; 115 - int left_idx; 116 - int right_idx; 117 122 }; 118 123 119 124 /*! ··· 322 327 //! @todo OpenHMD haptic API not finished 323 328 } 324 329 330 + static bool 331 + check_head_pose(struct oh_device *ohd, enum xrt_input_name name) 332 + { 333 + return (ohd->ohmd_device_type == OPENHMD_OCULUS_RIFT_HMD || ohd->ohmd_device_type == OPENHMD_GENERIC_HMD) && 334 + name == XRT_INPUT_GENERIC_HEAD_POSE; 335 + } 336 + 337 + static bool 338 + check_controller_pose(struct oh_device *ohd, enum xrt_input_name name) 339 + { 340 + bool touch_pose = (ohd->ohmd_device_type == OPENHMD_OCULUS_RIFT_CONTROLLER && 341 + (name == XRT_INPUT_TOUCH_AIM_POSE || name == XRT_INPUT_TOUCH_GRIP_POSE)); 342 + bool generic_pose = ohd->ohmd_device_type == OPENHMD_GENERIC_CONTROLLER && 343 + (name == XRT_INPUT_SIMPLE_AIM_POSE || name == XRT_INPUT_SIMPLE_GRIP_POSE); 344 + return touch_pose || generic_pose; 345 + } 346 + 347 + static bool 348 + check_tracker_pose(struct oh_device *ohd, enum xrt_input_name name) 349 + { 350 + return (ohd->ohmd_device_type == OPENHMD_GENERIC_TRACKER) && name == XRT_INPUT_GENERIC_TRACKER_POSE; 351 + } 352 + 325 353 static void 326 354 oh_device_get_tracked_pose(struct xrt_device *xdev, 327 355 enum xrt_input_name name, ··· 332 360 struct xrt_quat quat = XRT_QUAT_IDENTITY; 333 361 struct xrt_vec3 pos = XRT_VEC3_ZERO; 334 362 335 - // support generic head pose for all hmds, 336 - // support rift poses for rift controllers, and simple poses for generic controller 337 - if (name != XRT_INPUT_GENERIC_HEAD_POSE && 338 - (ohd->ohmd_device_type == OPENHMD_OCULUS_RIFT_CONTROLLER && 339 - (name != XRT_INPUT_TOUCH_AIM_POSE && name != XRT_INPUT_TOUCH_GRIP_POSE)) && 340 - ohd->ohmd_device_type == OPENHMD_GENERIC_CONTROLLER && 341 - (name != XRT_INPUT_SIMPLE_AIM_POSE && name != XRT_INPUT_SIMPLE_GRIP_POSE)) { 342 - OHMD_ERROR(ohd, "unknown input name"); 363 + if (!check_head_pose(ohd, name) && !check_controller_pose(ohd, name) && !check_tracker_pose(ohd, name)) { 364 + OHMD_ERROR(ohd, "unknown input name: %d", name); 343 365 return; 344 366 } 345 367 ··· 423 445 } 424 446 425 447 // Update state within driver 426 - ohd->last_update = now; 448 + ohd->last_update = (int64_t)now; 427 449 ohd->last_relation = *out_relation; 428 450 } 429 451 ··· 1041 1063 ohd->ohmd_device_type = OPENHMD_OCULUS_RIFT_CONTROLLER; 1042 1064 ohd->base.name = XRT_DEVICE_TOUCH_CONTROLLER; 1043 1065 } else { 1044 - ohd->ohmd_device_type = OPENHMD_GENERIC_CONTROLLER; 1045 - ohd->base.name = XRT_DEVICE_GENERIC_HMD; //! @todo generic tracker 1066 + if (device_type == XRT_DEVICE_TYPE_GENERIC_TRACKER) { 1067 + ohd->ohmd_device_type = OPENHMD_GENERIC_TRACKER; 1068 + } else { 1069 + ohd->ohmd_device_type = OPENHMD_GENERIC_CONTROLLER; 1070 + } 1071 + ohd->base.name = XRT_DEVICE_SIMPLE_CONTROLLER; //! @todo Generic tracker input profile? 1046 1072 } 1047 1073 ohd->ctx = ctx; 1048 1074 ohd->dev = dev; ··· 1053 1079 ohd->controls_mapping[i] = 0; 1054 1080 } 1055 1081 1056 - if (oculus_touch) { 1057 - SET_TOUCH_INPUT(X_CLICK); 1058 - SET_TOUCH_INPUT(X_TOUCH); 1059 - SET_TOUCH_INPUT(Y_CLICK); 1060 - SET_TOUCH_INPUT(Y_TOUCH); 1061 - SET_TOUCH_INPUT(MENU_CLICK); 1062 - SET_TOUCH_INPUT(A_CLICK); 1063 - SET_TOUCH_INPUT(A_TOUCH); 1064 - SET_TOUCH_INPUT(B_CLICK); 1065 - SET_TOUCH_INPUT(B_TOUCH); 1066 - SET_TOUCH_INPUT(SYSTEM_CLICK); 1067 - SET_TOUCH_INPUT(SQUEEZE_VALUE); 1068 - SET_TOUCH_INPUT(TRIGGER_TOUCH); 1069 - SET_TOUCH_INPUT(TRIGGER_VALUE); 1070 - SET_TOUCH_INPUT(THUMBSTICK_CLICK); 1071 - SET_TOUCH_INPUT(THUMBSTICK_TOUCH); 1072 - SET_TOUCH_INPUT(THUMBSTICK); 1073 - SET_TOUCH_INPUT(THUMBREST_TOUCH); 1074 - SET_TOUCH_INPUT(GRIP_POSE); 1075 - SET_TOUCH_INPUT(AIM_POSE); 1082 + if (device_type == XRT_DEVICE_TYPE_LEFT_HAND_CONTROLLER || 1083 + device_type == XRT_DEVICE_TYPE_RIGHT_HAND_CONTROLLER || 1084 + device_type == XRT_DEVICE_TYPE_ANY_HAND_CONTROLLER) { 1085 + if (oculus_touch) { 1086 + SET_TOUCH_INPUT(X_CLICK); 1087 + SET_TOUCH_INPUT(X_TOUCH); 1088 + SET_TOUCH_INPUT(Y_CLICK); 1089 + SET_TOUCH_INPUT(Y_TOUCH); 1090 + SET_TOUCH_INPUT(MENU_CLICK); 1091 + SET_TOUCH_INPUT(A_CLICK); 1092 + SET_TOUCH_INPUT(A_TOUCH); 1093 + SET_TOUCH_INPUT(B_CLICK); 1094 + SET_TOUCH_INPUT(B_TOUCH); 1095 + SET_TOUCH_INPUT(SYSTEM_CLICK); 1096 + SET_TOUCH_INPUT(SQUEEZE_VALUE); 1097 + SET_TOUCH_INPUT(TRIGGER_TOUCH); 1098 + SET_TOUCH_INPUT(TRIGGER_VALUE); 1099 + SET_TOUCH_INPUT(THUMBSTICK_CLICK); 1100 + SET_TOUCH_INPUT(THUMBSTICK_TOUCH); 1101 + SET_TOUCH_INPUT(THUMBSTICK); 1102 + SET_TOUCH_INPUT(THUMBREST_TOUCH); 1103 + ohd->base.inputs[GRIP_POSE].name = XRT_INPUT_TOUCH_GRIP_POSE; 1104 + ohd->base.inputs[AIM_POSE].name = XRT_INPUT_TOUCH_AIM_POSE; 1076 1105 1077 - ohd->make_trigger_digital = false; 1106 + 1107 + ohd->make_trigger_digital = false; 1108 + 1109 + ohd->base.outputs[0].name = XRT_OUTPUT_NAME_TOUCH_HAPTIC; 1078 1110 1079 - ohd->base.outputs[0].name = XRT_OUTPUT_NAME_TOUCH_HAPTIC; 1111 + ohd->controls_mapping[OHMD_TRIGGER] = OCULUS_TOUCH_TRIGGER_VALUE; 1112 + ohd->controls_mapping[OHMD_SQUEEZE] = OCULUS_TOUCH_SQUEEZE_VALUE; 1113 + ohd->controls_mapping[OHMD_MENU] = OCULUS_TOUCH_MENU_CLICK; 1114 + ohd->controls_mapping[OHMD_HOME] = OCULUS_TOUCH_SYSTEM_CLICK; 1115 + ohd->controls_mapping[OHMD_ANALOG_X] = OCULUS_TOUCH_THUMBSTICK; 1116 + ohd->controls_mapping[OHMD_ANALOG_Y] = OCULUS_TOUCH_THUMBSTICK; 1117 + ohd->controls_mapping[OHMD_ANALOG_PRESS] = OCULUS_TOUCH_THUMBSTICK_CLICK; 1118 + ohd->controls_mapping[OHMD_BUTTON_A] = OCULUS_TOUCH_A_CLICK; 1119 + ohd->controls_mapping[OHMD_BUTTON_B] = OCULUS_TOUCH_B_CLICK; 1120 + ohd->controls_mapping[OHMD_BUTTON_X] = OCULUS_TOUCH_X_CLICK; 1121 + ohd->controls_mapping[OHMD_BUTTON_Y] = OCULUS_TOUCH_Y_CLICK; 1122 + } else { 1123 + ohd->base.inputs[SIMPLE_SELECT_CLICK].name = XRT_INPUT_SIMPLE_SELECT_CLICK; 1124 + ohd->base.inputs[SIMPLE_MENU_CLICK].name = XRT_INPUT_SIMPLE_MENU_CLICK; 1125 + ohd->base.inputs[GRIP_POSE].name = XRT_INPUT_SIMPLE_GRIP_POSE; 1126 + ohd->base.inputs[AIM_POSE].name = XRT_INPUT_SIMPLE_AIM_POSE; 1080 1127 1081 - ohd->controls_mapping[OHMD_TRIGGER] = OCULUS_TOUCH_TRIGGER_VALUE; 1082 - ohd->controls_mapping[OHMD_SQUEEZE] = OCULUS_TOUCH_SQUEEZE_VALUE; 1083 - ohd->controls_mapping[OHMD_MENU] = OCULUS_TOUCH_MENU_CLICK; 1084 - ohd->controls_mapping[OHMD_HOME] = OCULUS_TOUCH_SYSTEM_CLICK; 1085 - ohd->controls_mapping[OHMD_ANALOG_X] = OCULUS_TOUCH_THUMBSTICK; 1086 - ohd->controls_mapping[OHMD_ANALOG_Y] = OCULUS_TOUCH_THUMBSTICK; 1087 - ohd->controls_mapping[OHMD_ANALOG_PRESS] = OCULUS_TOUCH_THUMBSTICK_CLICK; 1088 - ohd->controls_mapping[OHMD_BUTTON_A] = OCULUS_TOUCH_A_CLICK; 1089 - ohd->controls_mapping[OHMD_BUTTON_B] = OCULUS_TOUCH_B_CLICK; 1090 - ohd->controls_mapping[OHMD_BUTTON_X] = OCULUS_TOUCH_X_CLICK; 1091 - ohd->controls_mapping[OHMD_BUTTON_Y] = OCULUS_TOUCH_Y_CLICK; 1092 - } else { 1093 - ohd->base.inputs[SIMPLE_SELECT_CLICK].name = XRT_INPUT_SIMPLE_SELECT_CLICK; 1094 - ohd->base.inputs[SIMPLE_MENU_CLICK].name = XRT_INPUT_SIMPLE_MENU_CLICK; 1095 - ohd->base.inputs[SIMPLE_GRIP_POSE].name = XRT_INPUT_SIMPLE_GRIP_POSE; 1096 - ohd->base.inputs[SIMPLE_AIM_POSE].name = XRT_INPUT_SIMPLE_AIM_POSE; 1128 + // XRT_INPUT_SIMPLE_SELECT_CLICK is digital input. 1129 + // in case the hardware is an analog trigger, change the input after a half pulled trigger. 1130 + ohd->make_trigger_digital = true; 1097 1131 1098 - // XRT_INPUT_SIMPLE_SELECT_CLICK is digital input. 1099 - // in case the hardware is an analog trigger, change the input after a half pulled trigger. 1100 - ohd->make_trigger_digital = true; 1132 + if (output_count > 0) { 1133 + ohd->base.outputs[0].name = XRT_OUTPUT_NAME_SIMPLE_VIBRATION; 1134 + } 1101 1135 1102 - if (output_count > 0) { 1103 - ohd->base.outputs[0].name = XRT_OUTPUT_NAME_SIMPLE_VIBRATION; 1136 + ohd->controls_mapping[OHMD_TRIGGER] = SIMPLE_SELECT_CLICK; 1137 + ohd->controls_mapping[OHMD_MENU] = SIMPLE_MENU_CLICK; 1104 1138 } 1105 - 1106 - ohd->controls_mapping[OHMD_TRIGGER] = SIMPLE_SELECT_CLICK; 1107 - ohd->controls_mapping[OHMD_MENU] = SIMPLE_MENU_CLICK; 1139 + } else if (device_type == XRT_DEVICE_TYPE_GENERIC_TRACKER) { 1140 + ohd->base.inputs[GRIP_POSE].name = XRT_INPUT_GENERIC_TRACKER_POSE; 1141 + ohd->base.inputs[AIM_POSE].name = XRT_INPUT_GENERIC_TRACKER_POSE; 1108 1142 } 1109 1143 1110 1144 snprintf(ohd->base.str, XRT_DEVICE_NAME_LEN, "%s (OpenHMD)", prod); ··· 1133 1167 int right_idx = -1; 1134 1168 int right_flags = 0; 1135 1169 1136 - if (no_hmds) { 1137 - return 0; 1138 - } 1170 + int trackers[XRT_MAX_DEVICES_PER_PROBE]; 1171 + ohmd_device_flags tracker_flags[XRT_MAX_DEVICES_PER_PROBE]; 1172 + uint32_t tracker_count = 0; 1173 + 1139 1174 1140 1175 /* Probe for devices */ 1141 1176 int device_count = ohmd_ctx_probe(ctx); 1142 1177 1143 - /* Then loop */ 1178 + // clamp device_count to XRT_MAX_DEVICES_PER_PROBE 1179 + if (device_count > XRT_MAX_DEVICES_PER_PROBE) { 1180 + U_LOG_W("Too many devices from OpenHMD, ignoring %d devices!", 1181 + device_count - XRT_MAX_DEVICES_PER_PROBE); 1182 + device_count = XRT_MAX_DEVICES_PER_PROBE; 1183 + } 1184 + 1185 + /* Find first HMD, first left controller, first right controller, and all trackers */ 1144 1186 for (int i = 0; i < device_count; i++) { 1145 1187 int device_class = 0, device_flags = 0; 1146 1188 const char *prod = NULL; ··· 1148 1190 ohmd_list_geti(ctx, i, OHMD_DEVICE_CLASS, &device_class); 1149 1191 ohmd_list_geti(ctx, i, OHMD_DEVICE_FLAGS, &device_flags); 1150 1192 1193 + if (device_flags & OHMD_DEVICE_FLAGS_NULL_DEVICE) { 1194 + U_LOG_D("Rejecting device idx %i, is a NULL device.", i); 1195 + continue; 1196 + } 1197 + 1198 + prod = ohmd_list_gets(ctx, i, OHMD_PRODUCT); 1199 + if (strcmp(prod, "External Device") == 0 && !debug_get_bool_option_ohmd_external()) { 1200 + U_LOG_D("Rejecting device idx %i, is a External device.", i); 1201 + continue; 1202 + } 1203 + 1151 1204 if (device_class == OHMD_DEVICE_CLASS_CONTROLLER) { 1152 1205 if ((device_flags & OHMD_DEVICE_FLAGS_LEFT_CONTROLLER) != 0) { 1153 1206 if (left_idx != -1) { ··· 1167 1220 } 1168 1221 1169 1222 continue; 1170 - } 1171 - 1172 - if (device_class == OHMD_DEVICE_CLASS_HMD) { 1223 + } else if (device_class == OHMD_DEVICE_CLASS_HMD) { 1173 1224 if (hmd_idx != -1) { 1174 1225 continue; 1175 1226 } 1176 1227 U_LOG_D("Selecting hmd idx %i", i); 1177 1228 hmd_idx = i; 1178 1229 hmd_flags = device_flags; 1179 - } 1180 - 1181 - if (device_flags & OHMD_DEVICE_FLAGS_NULL_DEVICE) { 1182 - U_LOG_D("Rejecting device idx %i, is a NULL device.", i); 1183 - continue; 1184 - } 1185 - 1186 - prod = ohmd_list_gets(ctx, i, OHMD_PRODUCT); 1187 - if (strcmp(prod, "External Device") == 0 && !debug_get_bool_option_ohmd_external()) { 1188 - U_LOG_D("Rejecting device idx %i, is a External device.", i); 1189 - continue; 1190 - } 1191 - 1192 - if (hmd_idx != -1 && left_idx != -1 && right_idx != -1) { 1193 - break; 1230 + } else if (device_class == OHMD_DEVICE_CLASS_GENERIC_TRACKER) { 1231 + uint32_t tracker_index = tracker_count++; 1232 + trackers[tracker_index] = i; 1233 + tracker_flags[tracker_index] = device_flags; 1194 1234 } 1195 1235 } 1196 1236 ··· 1201 1241 struct oh_system *sys = U_TYPED_CALLOC(struct oh_system); 1202 1242 sys->base.type = XRT_TRACKING_TYPE_NONE; 1203 1243 sys->base.offset.orientation.w = 1.0f; 1204 - sys->hmd_idx = -1; 1205 - sys->left_idx = -1; 1206 - sys->right_idx = -1; 1207 1244 1208 1245 u_var_add_root(sys, "OpenHMD Wrapper", false); 1209 1246 ··· 1214 1251 hmd->sys = sys; 1215 1252 hmd->base.tracking_origin = &sys->base; 1216 1253 1217 - sys->hmd_idx = created; 1218 - sys->devices[sys->hmd_idx] = hmd; 1254 + sys->devices[OHMD_HMD_INDEX] = hmd; 1219 1255 1220 1256 if (hmd->base.position_tracking_supported) { 1221 1257 sys->base.type = XRT_TRACKING_TYPE_OTHER; ··· 1232 1268 left->sys = sys; 1233 1269 left->base.tracking_origin = &sys->base; 1234 1270 1235 - sys->left_idx = created; 1236 - sys->devices[sys->left_idx] = left; 1271 + sys->devices[OHMD_LEFT_INDEX] = left; 1237 1272 1238 1273 out_xdevs[created++] = &left->base; 1239 1274 } ··· 1246 1281 right->sys = sys; 1247 1282 right->base.tracking_origin = &sys->base; 1248 1283 1249 - sys->right_idx = created; 1250 - sys->devices[sys->right_idx] = right; 1284 + sys->devices[OHMD_RIGHT_INDEX] = right; 1251 1285 1252 1286 out_xdevs[created++] = &right->base; 1253 1287 } 1254 1288 } 1255 1289 1290 + for (uint32_t i = 0; i < tracker_count; i++) { 1291 + struct oh_device *tracker = 1292 + create_controller(ctx, trackers[i], tracker_flags[i], XRT_DEVICE_TYPE_GENERIC_TRACKER); 1293 + if (tracker) { 1294 + tracker->sys = sys; 1295 + tracker->base.tracking_origin = &sys->base; 1296 + 1297 + sys->devices[OHMD_FIRST_TRACKER_INDEX + i] = tracker; 1298 + 1299 + out_xdevs[created++] = &tracker->base; 1300 + } 1301 + } 1302 + 1256 1303 for (int i = 0; i < XRT_MAX_DEVICES_PER_PROBE; i++) { 1257 1304 if (sys->devices[i] != NULL) { 1258 1305 u_var_add_ro_text(sys, sys->devices[i]->base.str, "OpenHMD Device"); 1259 1306 } 1260 1307 } 1261 1308 1262 - //! @todo initialize more devices like generic trackers (nolo) 1309 + ohmd_device_settings_destroy(settings); 1263 1310 1264 1311 return created; 1265 1312 }