d/opengloves: Refactor creation

This commit is contained in:
Jakob Bornecrantz 2023-10-16 21:06:35 +01:00
parent 8b30819b35
commit e805209fcd
3 changed files with 41 additions and 41 deletions

View file

@ -22,8 +22,11 @@ struct u_system_devices;
* @brief Driver for OpenGloves VR Gloves Devices
*/
int
opengloves_create_devices(struct xrt_device **out_xdevs, const struct xrt_system_devices *sysdevs);
void
opengloves_create_devices(struct xrt_device *old_left,
struct xrt_device *old_right,
struct xrt_device **out_left,
struct xrt_device **out_right);
/*!
* @dir drivers/opengloves

View file

@ -49,8 +49,11 @@ opengloves_load_config_file(struct u_config_json *config_json)
return out_config_json;
}
int
opengloves_create_devices(struct xrt_device **out_xdevs, const struct xrt_system_devices *sysdevs)
void
opengloves_create_devices(struct xrt_device *old_left,
struct xrt_device *old_right,
struct xrt_device **out_left,
struct xrt_device **out_right)
{
struct xrt_device *dev_left = NULL;
struct xrt_device *dev_right = NULL;
@ -81,12 +84,11 @@ opengloves_create_devices(struct xrt_device **out_xdevs, const struct xrt_system
const cJSON *opengloves_config_json = opengloves_load_config_file(&config_json);
if (opengloves_config_json == NULL) {
cJSON_Delete(config_json.root);
return 0;
return;
}
// set up tracking overrides
int cur_dev = 0;
if (dev_left != NULL && sysdevs->roles.left != NULL) {
if (dev_left != NULL && old_left != NULL) {
struct xrt_quat rot = XRT_QUAT_IDENTITY;
struct xrt_vec3 pos = XRT_VEC3_ZERO;
JSON_QUAT(opengloves_config_json, "offset_rot_left", &rot);
@ -94,14 +96,17 @@ opengloves_create_devices(struct xrt_device **out_xdevs, const struct xrt_system
struct xrt_pose offset_pose = {.orientation = rot, .position = pos};
struct xrt_device *dev_wrap =
multi_create_tracking_override(XRT_TRACKING_OVERRIDE_DIRECT, dev_left, sysdevs->roles.left,
XRT_INPUT_GENERIC_TRACKER_POSE, &offset_pose);
struct xrt_device *dev_wrap = multi_create_tracking_override( //
XRT_TRACKING_OVERRIDE_DIRECT, //
dev_left, //
old_left, //
XRT_INPUT_GENERIC_TRACKER_POSE, //
&offset_pose); //
out_xdevs[cur_dev++] = dev_wrap;
*out_left = dev_wrap;
}
if (dev_right != NULL && sysdevs->roles.right != NULL) {
if (dev_right != NULL && old_right != NULL) {
struct xrt_quat rot = XRT_QUAT_IDENTITY;
struct xrt_vec3 pos = XRT_VEC3_ZERO;
JSON_QUAT(opengloves_config_json, "offset_rot_right", &rot);
@ -109,14 +114,15 @@ opengloves_create_devices(struct xrt_device **out_xdevs, const struct xrt_system
struct xrt_pose offset_pose = {.orientation = rot, .position = pos};
struct xrt_device *dev_wrap =
multi_create_tracking_override(XRT_TRACKING_OVERRIDE_DIRECT, dev_right, sysdevs->roles.right,
XRT_INPUT_GENERIC_TRACKER_POSE, &offset_pose);
struct xrt_device *dev_wrap = multi_create_tracking_override( //
XRT_TRACKING_OVERRIDE_DIRECT, //
dev_right, //
old_right, //
XRT_INPUT_GENERIC_TRACKER_POSE, //
&offset_pose); //
out_xdevs[cur_dev++] = dev_wrap;
*out_right = dev_wrap;
}
cJSON_Delete(config_json.root);
return cur_dev;
}

View file

@ -545,32 +545,22 @@ stream_data_sources(struct lighthouse_system *lhs,
}
static void
try_add_opengloves(struct u_system_devices *usysd)
try_add_opengloves(struct xrt_device *left,
struct xrt_device *right,
struct xrt_device **out_left_ht,
struct xrt_device **out_right_ht)
{
#ifdef XRT_BUILD_DRIVER_OPENGLOVES
size_t openglove_device_count =
opengloves_create_devices(&usysd->base.xdevs[usysd->base.xdev_count], &usysd->base);
for (size_t i = usysd->base.xdev_count; i < usysd->base.xdev_count + openglove_device_count; i++) {
struct xrt_device *xdev = usysd->base.xdevs[i];
struct xrt_device *og_left = NULL, *og_right = NULL;
opengloves_create_devices(left, right, &og_left, &og_right);
for (uint32_t j = 0; j < xdev->input_count; j++) {
struct xrt_input *input = &xdev->inputs[j];
if (input->name == XRT_INPUT_GENERIC_HAND_TRACKING_LEFT) {
usysd->base.roles.hand_tracking.left = xdev;
break;
}
if (input->name == XRT_INPUT_GENERIC_HAND_TRACKING_RIGHT) {
usysd->base.roles.hand_tracking.right = xdev;
break;
}
}
// Overwrite the hand tracking roles with openglove ones.
if (og_left != NULL) {
*out_left_ht = og_left;
}
if (og_right != NULL) {
*out_right_ht = og_right;
}
usysd->base.xdev_count += openglove_device_count;
#endif
}
@ -802,9 +792,10 @@ end_valve_index:
goto end_err;
}
// Should we use OpenGloves.
if (!lhs->vive_tstatus.hand_enabled) {
// We only want to try to add opengloves if we aren't optically tracking hands
try_add_opengloves(lhs->devices);
try_add_opengloves(left, right, &left_ht, &right_ht);
}
// Assign to role(s).