u/system_helpers: Refactor hand-tracker helper getters

This commit is contained in:
Jakob Bornecrantz 2023-10-16 22:42:03 +01:00
parent 464a95abed
commit 08ec4e0259
5 changed files with 38 additions and 19 deletions

View file

@ -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;

View file

@ -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

View file

@ -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);
/*

View file

@ -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) {

View file

@ -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;