···294294295295 free(xdev);
296296}
297297+298298+/*
299299+ * move the assigned xdev from hand to other_hand if:
300300+ * - controller of type "any hand" is assigned to hand
301301+ * - other_hand is unassiged
302302+ */
303303+static void
304304+try_move_assignment(struct xrt_device **xdevs, int *hand, int *other_hand)
305305+{
306306+ if (*hand != XRT_DEVICE_ROLE_UNASSIGNED &&
307307+ xdevs[*hand]->device_type == XRT_DEVICE_TYPE_ANY_HAND_CONTROLLER &&
308308+ *other_hand == XRT_DEVICE_ROLE_UNASSIGNED) {
309309+310310+ *other_hand = *hand;
311311+ *hand = XRT_DEVICE_ROLE_UNASSIGNED;
312312+ }
313313+}
314314+315315+void
316316+u_device_assign_xdev_roles(struct xrt_device **xdevs,
317317+ size_t num_xdevs,
318318+ int *head,
319319+ int *left,
320320+ int *right)
321321+{
322322+ *head = XRT_DEVICE_ROLE_UNASSIGNED;
323323+ *left = XRT_DEVICE_ROLE_UNASSIGNED;
324324+ *right = XRT_DEVICE_ROLE_UNASSIGNED;
325325+326326+ for (size_t i = 0; i < num_xdevs; i++) {
327327+ if (xdevs[i] == NULL) {
328328+ continue;
329329+ }
330330+331331+ switch (xdevs[i]->device_type) {
332332+ case XRT_DEVICE_TYPE_HMD:
333333+ if (*head == XRT_DEVICE_ROLE_UNASSIGNED) {
334334+ *head = i;
335335+ }
336336+ break;
337337+ case XRT_DEVICE_TYPE_LEFT_HAND_CONTROLLER:
338338+ try_move_assignment(xdevs, left, right);
339339+ if (*left == XRT_DEVICE_ROLE_UNASSIGNED) {
340340+ *left = i;
341341+ }
342342+ break;
343343+ case XRT_DEVICE_TYPE_RIGHT_HAND_CONTROLLER:
344344+ try_move_assignment(xdevs, right, left);
345345+ if (*right == XRT_DEVICE_ROLE_UNASSIGNED) {
346346+ *right = i;
347347+ }
348348+ break;
349349+ case XRT_DEVICE_TYPE_ANY_HAND_CONTROLLER:
350350+ if (*left == XRT_DEVICE_ROLE_UNASSIGNED) {
351351+ *left = i;
352352+ } else if (*right == XRT_DEVICE_ROLE_UNASSIGNED) {
353353+ *right = i;
354354+ } else {
355355+ //! @todo: do something with unassigend devices?
356356+ }
357357+ break;
358358+ default: break;
359359+ }
360360+ }
361361+}
+14
src/xrt/auxiliary/util/u_device.h
···9898u_device_free(struct xrt_device *xdev);
9999100100101101+#define XRT_DEVICE_ROLE_UNASSIGNED (-1)
102102+103103+/*!
104104+ * Helper function to assign head, left hand and right hand roles.
105105+ *
106106+ * @ingroup aux_util
107107+ */
108108+void
109109+u_device_assign_xdev_roles(struct xrt_device **xdevs,
110110+ size_t num_xdevs,
111111+ int *head,
112112+ int *left,
113113+ int *right);
114114+101115#ifdef __cplusplus
102116}
103117#endif
+2-36
src/xrt/state_trackers/oxr/oxr_instance.c
···114114115115#define NUM_XDEVS 16
116116117117-static void
118118-assign_xdev_roles(struct oxr_instance *inst)
119119-{
120120- struct oxr_system *sys = &inst->system;
121121- for (size_t i = 0; i < NUM_XDEVS; i++) {
122122- if (sys->xdevs[i] == NULL) {
123123- continue;
124124- }
125125-126126- if (sys->xdevs[i]->device_type == XRT_DEVICE_TYPE_HMD) {
127127- sys->role.head = i;
128128- } else if (sys->xdevs[i]->device_type ==
129129- XRT_DEVICE_TYPE_LEFT_HAND_CONTROLLER) {
130130- if (sys->role.left == XRT_DEVICE_ROLE_UNASSIGNED) {
131131- sys->role.left = i;
132132- }
133133- } else if (sys->xdevs[i]->device_type ==
134134- XRT_DEVICE_TYPE_RIGHT_HAND_CONTROLLER) {
135135- if (sys->role.right == XRT_DEVICE_ROLE_UNASSIGNED) {
136136- sys->role.right = i;
137137- }
138138- } else if (sys->xdevs[i]->device_type ==
139139- XRT_DEVICE_TYPE_ANY_HAND_CONTROLLER) {
140140- if (sys->role.left == XRT_DEVICE_ROLE_UNASSIGNED) {
141141- sys->role.left = i;
142142- } else if (sys->role.right ==
143143- XRT_DEVICE_ROLE_UNASSIGNED) {
144144- sys->role.right = i;
145145- } else {
146146- //! @todo: do something with unassigend devices?
147147- }
148148- }
149149- }
150150-}
151151-152117static inline size_t
153118min_size_t(size_t a, size_t b)
154119{
···277242 oxr_xdev_destroy(&xdevs[i]);
278243 }
279244280280- assign_xdev_roles(inst);
245245+ u_device_assign_xdev_roles(xdevs, NUM_XDEVS, &sys->role.head,
246246+ &sys->role.left, &sys->role.right);
281247282248 // Did we find any HMD
283249 // @todo Headless with only controllers?
+1-2
src/xrt/state_trackers/oxr/oxr_objects.h
···2020#include "util/u_index_fifo.h"
2121#include "util/u_hashset.h"
2222#include "util/u_hashmap.h"
2323+#include "util/u_device.h"
23242425#include "oxr_extension_support.h"
2526#include "oxr_subaction.h"
···10881089 */
10891090 oxr_handle_destroyer destroy;
10901091};
10911091-10921092-#define XRT_DEVICE_ROLE_UNASSIGNED (-1)
1093109210941093/*!
10951094 * Single or multiple devices grouped together to form a system that sessions