The open source OpenXR runtime

d/opengloves: Refactor creation

+41 -41
+5 -2
src/xrt/drivers/opengloves/opengloves_interface.h
··· 22 22 * @brief Driver for OpenGloves VR Gloves Devices 23 23 */ 24 24 25 - int 26 - opengloves_create_devices(struct xrt_device **out_xdevs, const struct xrt_system_devices *sysdevs); 25 + void 26 + opengloves_create_devices(struct xrt_device *old_left, 27 + struct xrt_device *old_right, 28 + struct xrt_device **out_left, 29 + struct xrt_device **out_right); 27 30 28 31 /*! 29 32 * @dir drivers/opengloves
+22 -16
src/xrt/drivers/opengloves/opengloves_prober.c
··· 49 49 return out_config_json; 50 50 } 51 51 52 - int 53 - opengloves_create_devices(struct xrt_device **out_xdevs, const struct xrt_system_devices *sysdevs) 52 + void 53 + opengloves_create_devices(struct xrt_device *old_left, 54 + struct xrt_device *old_right, 55 + struct xrt_device **out_left, 56 + struct xrt_device **out_right) 54 57 { 55 58 struct xrt_device *dev_left = NULL; 56 59 struct xrt_device *dev_right = NULL; ··· 81 84 const cJSON *opengloves_config_json = opengloves_load_config_file(&config_json); 82 85 if (opengloves_config_json == NULL) { 83 86 cJSON_Delete(config_json.root); 84 - return 0; 87 + return; 85 88 } 86 89 87 90 // set up tracking overrides 88 - int cur_dev = 0; 89 - if (dev_left != NULL && sysdevs->roles.left != NULL) { 91 + if (dev_left != NULL && old_left != NULL) { 90 92 struct xrt_quat rot = XRT_QUAT_IDENTITY; 91 93 struct xrt_vec3 pos = XRT_VEC3_ZERO; 92 94 JSON_QUAT(opengloves_config_json, "offset_rot_left", &rot); ··· 94 96 95 97 struct xrt_pose offset_pose = {.orientation = rot, .position = pos}; 96 98 97 - struct xrt_device *dev_wrap = 98 - multi_create_tracking_override(XRT_TRACKING_OVERRIDE_DIRECT, dev_left, sysdevs->roles.left, 99 - XRT_INPUT_GENERIC_TRACKER_POSE, &offset_pose); 99 + struct xrt_device *dev_wrap = multi_create_tracking_override( // 100 + XRT_TRACKING_OVERRIDE_DIRECT, // 101 + dev_left, // 102 + old_left, // 103 + XRT_INPUT_GENERIC_TRACKER_POSE, // 104 + &offset_pose); // 100 105 101 - out_xdevs[cur_dev++] = dev_wrap; 106 + *out_left = dev_wrap; 102 107 } 103 108 104 - if (dev_right != NULL && sysdevs->roles.right != NULL) { 109 + if (dev_right != NULL && old_right != NULL) { 105 110 struct xrt_quat rot = XRT_QUAT_IDENTITY; 106 111 struct xrt_vec3 pos = XRT_VEC3_ZERO; 107 112 JSON_QUAT(opengloves_config_json, "offset_rot_right", &rot); ··· 109 114 110 115 struct xrt_pose offset_pose = {.orientation = rot, .position = pos}; 111 116 112 - struct xrt_device *dev_wrap = 113 - multi_create_tracking_override(XRT_TRACKING_OVERRIDE_DIRECT, dev_right, sysdevs->roles.right, 114 - XRT_INPUT_GENERIC_TRACKER_POSE, &offset_pose); 117 + struct xrt_device *dev_wrap = multi_create_tracking_override( // 118 + XRT_TRACKING_OVERRIDE_DIRECT, // 119 + dev_right, // 120 + old_right, // 121 + XRT_INPUT_GENERIC_TRACKER_POSE, // 122 + &offset_pose); // 115 123 116 - out_xdevs[cur_dev++] = dev_wrap; 124 + *out_right = dev_wrap; 117 125 } 118 126 119 127 cJSON_Delete(config_json.root); 120 - 121 - return cur_dev; 122 128 }
+14 -23
src/xrt/targets/common/target_builder_lighthouse.c
··· 545 545 } 546 546 547 547 static void 548 - try_add_opengloves(struct u_system_devices *usysd) 548 + try_add_opengloves(struct xrt_device *left, 549 + struct xrt_device *right, 550 + struct xrt_device **out_left_ht, 551 + struct xrt_device **out_right_ht) 549 552 { 550 553 #ifdef XRT_BUILD_DRIVER_OPENGLOVES 551 - size_t openglove_device_count = 552 - opengloves_create_devices(&usysd->base.xdevs[usysd->base.xdev_count], &usysd->base); 553 - for (size_t i = usysd->base.xdev_count; i < usysd->base.xdev_count + openglove_device_count; i++) { 554 - struct xrt_device *xdev = usysd->base.xdevs[i]; 555 - 556 - for (uint32_t j = 0; j < xdev->input_count; j++) { 557 - struct xrt_input *input = &xdev->inputs[j]; 558 - 559 - if (input->name == XRT_INPUT_GENERIC_HAND_TRACKING_LEFT) { 560 - usysd->base.roles.hand_tracking.left = xdev; 561 - 562 - break; 563 - } 564 - if (input->name == XRT_INPUT_GENERIC_HAND_TRACKING_RIGHT) { 565 - usysd->base.roles.hand_tracking.right = xdev; 554 + struct xrt_device *og_left = NULL, *og_right = NULL; 555 + opengloves_create_devices(left, right, &og_left, &og_right); 566 556 567 - break; 568 - } 569 - } 557 + // Overwrite the hand tracking roles with openglove ones. 558 + if (og_left != NULL) { 559 + *out_left_ht = og_left; 560 + } 561 + if (og_right != NULL) { 562 + *out_right_ht = og_right; 570 563 } 571 - 572 - usysd->base.xdev_count += openglove_device_count; 573 - 574 564 #endif 575 565 } 576 566 ··· 802 792 goto end_err; 803 793 } 804 794 795 + // Should we use OpenGloves. 805 796 if (!lhs->vive_tstatus.hand_enabled) { 806 797 // We only want to try to add opengloves if we aren't optically tracking hands 807 - try_add_opengloves(lhs->devices); 798 + try_add_opengloves(left, right, &left_ht, &right_ht); 808 799 } 809 800 810 801 // Assign to role(s).