tangled
alpha
login
or
join now
matrixfurry.com
/
monado
0
fork
atom
The open source OpenXR runtime
0
fork
atom
overview
issues
pulls
pipelines
u/builders: Add xrt_builder_helpers
Jakob Bornecrantz
3 years ago
f91db16d
46c6412c
+163
-1
4 changed files
expand all
collapse all
unified
split
src
xrt
auxiliary
CMakeLists.txt
util
u_builders.c
u_builders.h
u_system_helpers.h
+2
src/xrt/auxiliary/CMakeLists.txt
···
153
153
aux_util STATIC
154
154
util/u_bitwise.c
155
155
util/u_bitwise.h
156
156
+
util/u_builders.c
157
157
+
util/u_builders.h
156
158
util/u_debug.c
157
159
util/u_debug.h
158
160
util/u_device.c
+74
src/xrt/auxiliary/util/u_builders.c
···
1
1
+
// Copyright 2022, Collabora, Ltd.
2
2
+
// SPDX-License-Identifier: BSL-1.0
3
3
+
/*!
4
4
+
* @file
5
5
+
* @brief Helpers for @ref xrt_builder implementations.
6
6
+
* @author Jakob Bornecrantz <jakob@collabora.com>
7
7
+
* @ingroup aux_util
8
8
+
*/
9
9
+
10
10
+
#include "xrt/xrt_prober.h"
11
11
+
#include "u_builders.h"
12
12
+
13
13
+
14
14
+
/*
15
15
+
*
16
16
+
* 'Exported' function.
17
17
+
*
18
18
+
*/
19
19
+
20
20
+
struct xrt_prober_device *
21
21
+
u_builder_find_prober_device(struct xrt_prober_device *const *xpdevs,
22
22
+
size_t xpdev_count,
23
23
+
uint16_t product_id,
24
24
+
uint16_t vendor_id)
25
25
+
{
26
26
+
for (size_t i = 0; i < xpdev_count; i++) {
27
27
+
struct xrt_prober_device *xpdev = xpdevs[i];
28
28
+
if (xpdev->product_id != product_id || xpdev->vendor_id != vendor_id) {
29
29
+
continue;
30
30
+
}
31
31
+
32
32
+
return xpdev;
33
33
+
}
34
34
+
35
35
+
return NULL;
36
36
+
}
37
37
+
38
38
+
void
39
39
+
u_builder_search(struct xrt_prober *xp,
40
40
+
struct xrt_prober_device *const *xpdevs,
41
41
+
size_t xpdev_count,
42
42
+
const struct u_builder_search_filter *filters,
43
43
+
size_t filter_count,
44
44
+
struct u_builder_search_results *results)
45
45
+
{
46
46
+
for (size_t i = 0; i < xpdev_count; i++) {
47
47
+
struct xrt_prober_device *xpdev = xpdevs[i];
48
48
+
bool match = false;
49
49
+
50
50
+
for (size_t k = 0; k < filter_count; k++) {
51
51
+
struct u_builder_search_filter f = filters[k];
52
52
+
53
53
+
if (xpdev->product_id != f.product_id || //
54
54
+
xpdev->vendor_id != f.vendor_id || //
55
55
+
xpdev->bus != f.bus_type) { //
56
56
+
continue;
57
57
+
}
58
58
+
59
59
+
match = true;
60
60
+
break;
61
61
+
}
62
62
+
63
63
+
if (!match) {
64
64
+
continue;
65
65
+
}
66
66
+
67
67
+
results->xpdevs[results->xpdev_count++] = xpdev;
68
68
+
69
69
+
// Abort if full.
70
70
+
if (results->xpdev_count >= ARRAY_SIZE(results->xpdevs)) {
71
71
+
return;
72
72
+
}
73
73
+
}
74
74
+
}
+82
src/xrt/auxiliary/util/u_builders.h
···
1
1
+
// Copyright 2022, Collabora, Ltd.
2
2
+
// SPDX-License-Identifier: BSL-1.0
3
3
+
/*!
4
4
+
* @file
5
5
+
* @brief Helpers for @ref xrt_builder implementations.
6
6
+
* @author Jakob Bornecrantz <jakob@collabora.com>
7
7
+
* @ingroup aux_util
8
8
+
*/
9
9
+
10
10
+
#pragma once
11
11
+
12
12
+
#include "xrt/xrt_prober.h"
13
13
+
14
14
+
15
15
+
#ifdef __cplusplus
16
16
+
extern "C" {
17
17
+
#endif
18
18
+
19
19
+
struct xrt_prober_device;
20
20
+
21
21
+
/*!
22
22
+
* Max return of the number @ref xrt_prober_device.
23
23
+
*
24
24
+
* @ingroup aux_util
25
25
+
*/
26
26
+
#define U_BUILDER_SEARCH_MAX (16) // 16 Vive trackers
27
27
+
28
28
+
/*!
29
29
+
* A filter to match the against.
30
30
+
*
31
31
+
* @ingroup aux_util
32
32
+
*/
33
33
+
struct u_builder_search_filter
34
34
+
{
35
35
+
uint16_t vendor_id;
36
36
+
uint16_t product_id;
37
37
+
enum xrt_bus_type bus_type;
38
38
+
};
39
39
+
40
40
+
/*!
41
41
+
* Results of a search of devices.
42
42
+
*
43
43
+
* @ingroup aux_util
44
44
+
*/
45
45
+
struct u_builder_search_results
46
46
+
{
47
47
+
//! Out field of found @ref xrt_prober_device.
48
48
+
struct xrt_prober_device *xpdevs[U_BUILDER_SEARCH_MAX];
49
49
+
50
50
+
//! Number of found devices.
51
51
+
size_t xpdev_count;
52
52
+
};
53
53
+
54
54
+
/*!
55
55
+
* Find the first @ref xrt_prober_device in the prober list.
56
56
+
*
57
57
+
* @ingroup aux_util
58
58
+
*/
59
59
+
struct xrt_prober_device *
60
60
+
u_builder_find_prober_device(struct xrt_prober_device *const *xpdevs,
61
61
+
size_t xpdev_count,
62
62
+
uint16_t product_id,
63
63
+
uint16_t vendor_id);
64
64
+
65
65
+
/*!
66
66
+
* Find all of the @ref xrt_prober_device that matches any in the given list of
67
67
+
* @ref u_builder_search_filter filters.
68
68
+
*
69
69
+
* @ingroup aux_util
70
70
+
*/
71
71
+
void
72
72
+
u_builder_search(struct xrt_prober *xp,
73
73
+
struct xrt_prober_device *const *xpdevs,
74
74
+
size_t xpdev_count,
75
75
+
const struct u_builder_search_filter *filters,
76
76
+
size_t filter_count,
77
77
+
struct u_builder_search_results *results);
78
78
+
79
79
+
80
80
+
#ifdef __cplusplus
81
81
+
}
82
82
+
#endif
+5
-1
src/xrt/auxiliary/util/u_system_helpers.h
···
13
13
#include "xrt/xrt_frame.h"
14
14
#include "xrt/xrt_system.h"
15
15
#include "xrt/xrt_instance.h"
16
16
+
#include "xrt/xrt_tracking.h"
16
17
17
18
18
19
#ifdef __cplusplus
···
33
34
{
34
35
struct xrt_system_devices base;
35
36
36
36
-
//! Frame context for visual tracking.
37
37
+
//! Optional frame context for visual tracking.
37
38
struct xrt_frame_context xfctx;
39
39
+
40
40
+
//! Optional shared tracking origin.
41
41
+
struct xrt_tracking_origin origin;
38
42
};
39
43
40
44
/*!