From 08ec4e0259cc05739dd689b53f64dbe1a55160a5 Mon Sep 17 00:00:00 2001 From: Jakob Bornecrantz Date: Mon, 16 Oct 2023 22:42:03 +0100 Subject: [PATCH] u/system_helpers: Refactor hand-tracker helper getters --- src/xrt/auxiliary/util/u_system_helpers.c | 6 ++-- src/xrt/auxiliary/util/u_system_helpers.h | 33 ++++++++++++++++--- .../targets/common/target_builder_legacy.c | 6 ++-- .../common/target_builder_lighthouse.c | 6 ++-- src/xrt/targets/common/target_builder_wmr.c | 6 ++-- 5 files changed, 38 insertions(+), 19 deletions(-) diff --git a/src/xrt/auxiliary/util/u_system_helpers.c b/src/xrt/auxiliary/util/u_system_helpers.c index 87fad6e01..c41ef69c3 100644 --- a/src/xrt/auxiliary/util/u_system_helpers.c +++ b/src/xrt/auxiliary/util/u_system_helpers.c @@ -95,10 +95,10 @@ u_system_devices_create_from_prober(struct xrt_instance *xinst, } struct xrt_device * -u_system_devices_get_ht_device(struct u_system_devices *usysd, enum xrt_input_name name) +u_system_devices_get_ht_device(struct xrt_system_devices *xsysd, enum xrt_input_name name) { - for (uint32_t i = 0; i < usysd->base.xdev_count; i++) { - struct xrt_device *xdev = usysd->base.xdevs[i]; + for (uint32_t i = 0; i < xsysd->xdev_count; i++) { + struct xrt_device *xdev = xsysd->xdevs[i]; if (xdev == NULL || !xdev->hand_tracking_supported) { continue; diff --git a/src/xrt/auxiliary/util/u_system_helpers.h b/src/xrt/auxiliary/util/u_system_helpers.h index 2e8af1e3e..ce9969382 100644 --- a/src/xrt/auxiliary/util/u_system_helpers.h +++ b/src/xrt/auxiliary/util/u_system_helpers.h @@ -113,15 +113,40 @@ u_system_devices_create_from_prober(struct xrt_instance *xinst, /*! * Helper function. * - * Looks through @ref u_system_devices's devices and returns the first device that supports hand tracking and the - * supplied input name. + * Looks through @ref xrt_system_devices's devices and returns the first device + * that supports hand tracking and the supplied input name. * - * Used by target_builder_lighthouse to find Knuckles controllers in the list of devices returned. + * Used by target_builder_lighthouse to find Knuckles controllers in the list of + * devices returned, the legacy builder to find hand tracking devices, etc. * * @ingroup aux_util */ struct xrt_device * -u_system_devices_get_ht_device(struct u_system_devices *usysd, enum xrt_input_name name); +u_system_devices_get_ht_device(struct xrt_system_devices *xsysd, enum xrt_input_name name); + +/*! + * Helper to get the first left hand-tracking device, + * uses @ref u_system_devices_get_ht_device. + * + * @ingroup aux_util + */ +static inline struct xrt_device * +u_system_devices_get_ht_device_left(struct xrt_system_devices *xsysd) +{ + return u_system_devices_get_ht_device(xsysd, XRT_INPUT_GENERIC_HAND_TRACKING_LEFT); +} + +/*! + * Helper to get the first right hand-tracking device, + * uses @ref u_system_devices_get_ht_device. + * + * @ingroup aux_util + */ +static inline struct xrt_device * +u_system_devices_get_ht_device_right(struct xrt_system_devices *xsysd) +{ + return u_system_devices_get_ht_device(xsysd, XRT_INPUT_GENERIC_HAND_TRACKING_RIGHT); +} #ifdef __cplusplus diff --git a/src/xrt/targets/common/target_builder_legacy.c b/src/xrt/targets/common/target_builder_legacy.c index 9eccdb830..fd83dd560 100644 --- a/src/xrt/targets/common/target_builder_legacy.c +++ b/src/xrt/targets/common/target_builder_legacy.c @@ -164,10 +164,8 @@ legacy_open_system(struct xrt_builder *xb, } // Find hand tracking devices. - usysd->base.roles.hand_tracking.left = - u_system_devices_get_ht_device(usysd, XRT_INPUT_GENERIC_HAND_TRACKING_LEFT); - usysd->base.roles.hand_tracking.right = - u_system_devices_get_ht_device(usysd, XRT_INPUT_GENERIC_HAND_TRACKING_RIGHT); + usysd->base.roles.hand_tracking.left = u_system_devices_get_ht_device_left(&usysd->base); + usysd->base.roles.hand_tracking.right = u_system_devices_get_ht_device_right(&usysd->base); /* diff --git a/src/xrt/targets/common/target_builder_lighthouse.c b/src/xrt/targets/common/target_builder_lighthouse.c index e74efef1e..fb5287bc0 100644 --- a/src/xrt/targets/common/target_builder_lighthouse.c +++ b/src/xrt/targets/common/target_builder_lighthouse.c @@ -677,15 +677,13 @@ lighthouse_open_system(struct xrt_builder *xb, if (left_idx >= 0) { lhs->vive_tstatus.controllers_found = true; usysd->base.roles.left = usysd->base.xdevs[left_idx]; - usysd->base.roles.hand_tracking.left = - u_system_devices_get_ht_device(usysd, XRT_INPUT_GENERIC_HAND_TRACKING_LEFT); + usysd->base.roles.hand_tracking.left = u_system_devices_get_ht_device_left(&usysd->base); } if (right_idx >= 0) { lhs->vive_tstatus.controllers_found = true; usysd->base.roles.right = usysd->base.xdevs[right_idx]; - usysd->base.roles.hand_tracking.right = - u_system_devices_get_ht_device(usysd, XRT_INPUT_GENERIC_HAND_TRACKING_RIGHT); + usysd->base.roles.hand_tracking.right = u_system_devices_get_ht_device_right(&usysd->base); } if (lhs->is_valve_index) { diff --git a/src/xrt/targets/common/target_builder_wmr.c b/src/xrt/targets/common/target_builder_wmr.c index f170efa1e..66e35e64b 100644 --- a/src/xrt/targets/common/target_builder_wmr.c +++ b/src/xrt/targets/common/target_builder_wmr.c @@ -300,10 +300,8 @@ wmr_open_system(struct xrt_builder *xb, } // Find hand tracking devices. - usysd->base.roles.hand_tracking.left = - u_system_devices_get_ht_device(usysd, XRT_INPUT_GENERIC_HAND_TRACKING_LEFT); - usysd->base.roles.hand_tracking.right = - u_system_devices_get_ht_device(usysd, XRT_INPUT_GENERIC_HAND_TRACKING_RIGHT); + usysd->base.roles.hand_tracking.left = u_system_devices_get_ht_device_left(&usysd->base); + usysd->base.roles.hand_tracking.right = u_system_devices_get_ht_device_right(&usysd->base); // Create space overseer last once all devices set. struct xrt_space_overseer *xso = NULL;