tangled
alpha
login
or
join now
matrixfurry.com
/
monado
0
fork
atom
The open source OpenXR runtime
0
fork
atom
overview
issues
pulls
pipelines
a/vive: Add builder helper
Jakob Bornecrantz
2 years ago
be1b4ba5
755a7d14
+143
3 changed files
expand all
collapse all
unified
split
src
xrt
auxiliary
vive
CMakeLists.txt
vive_builder.c
vive_builder.h
+2
src/xrt/auxiliary/vive/CMakeLists.txt
···
5
5
aux_vive STATIC
6
6
vive_bindings.c
7
7
vive_bindings.h
8
8
+
vive_builder.c
9
9
+
vive_builder.h
8
10
vive_calibration.c
9
11
vive_calibration.h
10
12
vive_config.h
+106
src/xrt/auxiliary/vive/vive_builder.c
···
1
1
+
// Copyright 2023, Collabora, Ltd.
2
2
+
// SPDX-License-Identifier: BSL-1.0
3
3
+
/*!
4
4
+
* @file
5
5
+
* @brief Builder helpers for Vive/Index devices.
6
6
+
* @author Moses Turner <moses@collabora.com>
7
7
+
* @author Jakob Bornecrantz <jakob@collabora.com>
8
8
+
* @ingroup aux_vive
9
9
+
*/
10
10
+
11
11
+
#include "xrt/xrt_device.h"
12
12
+
#include "xrt/xrt_prober.h"
13
13
+
14
14
+
#include "util/u_misc.h"
15
15
+
#include "util/u_logging.h"
16
16
+
#include "util/u_builders.h"
17
17
+
#include "util/u_system_helpers.h"
18
18
+
19
19
+
#include "vive_common.h"
20
20
+
#include "vive_builder.h"
21
21
+
22
22
+
23
23
+
#define HAVE_USB_DEV(VID, PID) u_builder_find_prober_device(xpdevs, xpdev_count, VID, PID, XRT_BUS_TYPE_USB)
24
24
+
25
25
+
26
26
+
xrt_result_t
27
27
+
vive_builder_estimate(struct xrt_prober *xp,
28
28
+
bool have_6dof,
29
29
+
bool have_hand_tracking,
30
30
+
bool *out_valve_have_index,
31
31
+
struct xrt_builder_estimate *out_estimate)
32
32
+
{
33
33
+
struct xrt_builder_estimate estimate = XRT_STRUCT_INIT;
34
34
+
struct u_builder_search_results results = {0};
35
35
+
struct xrt_prober_device **xpdevs = NULL;
36
36
+
size_t xpdev_count = 0;
37
37
+
xrt_result_t xret = XRT_SUCCESS;
38
38
+
39
39
+
// Lock the device list
40
40
+
xret = xrt_prober_lock_list(xp, &xpdevs, &xpdev_count);
41
41
+
if (xret != XRT_SUCCESS) {
42
42
+
U_LOG_E("Failed to lock list!");
43
43
+
return xret;
44
44
+
}
45
45
+
46
46
+
bool have_vive = HAVE_USB_DEV(HTC_VID, VIVE_PID);
47
47
+
bool have_vive_pro = HAVE_USB_DEV(HTC_VID, VIVE_PRO_MAINBOARD_PID);
48
48
+
bool have_valve_index = HAVE_USB_DEV(VALVE_VID, VIVE_PRO_LHR_PID);
49
49
+
50
50
+
if (have_vive || have_vive_pro || have_valve_index) {
51
51
+
estimate.certain.head = true;
52
52
+
if (have_6dof) {
53
53
+
estimate.maybe.dof6 = true;
54
54
+
estimate.certain.dof6 = true;
55
55
+
}
56
56
+
}
57
57
+
58
58
+
/*
59
59
+
* The Valve Index HMDs have UVC stereo cameras on the front. If we've
60
60
+
* found an Index, we'll probably be able to open the camera and use it
61
61
+
* to track hands even if we haven't found controllers.
62
62
+
*/
63
63
+
if (have_hand_tracking && have_valve_index) {
64
64
+
estimate.maybe.left = true;
65
65
+
estimate.maybe.right = true;
66
66
+
}
67
67
+
68
68
+
static struct u_builder_search_filter maybe_controller_filters[] = {
69
69
+
{VALVE_VID, VIVE_WATCHMAN_DONGLE, XRT_BUS_TYPE_USB},
70
70
+
{VALVE_VID, VIVE_WATCHMAN_DONGLE_GEN2, XRT_BUS_TYPE_USB},
71
71
+
};
72
72
+
73
73
+
// Reset the results.
74
74
+
U_ZERO(&results);
75
75
+
76
76
+
u_builder_search( //
77
77
+
xp, //
78
78
+
xpdevs, //
79
79
+
xpdev_count, //
80
80
+
maybe_controller_filters, //
81
81
+
ARRAY_SIZE(maybe_controller_filters), //
82
82
+
&results); //
83
83
+
if (results.xpdev_count != 0) {
84
84
+
estimate.maybe.left = true;
85
85
+
estimate.maybe.right = true;
86
86
+
87
87
+
// Good assumption that if the user has more than 2 wireless devices, two of them will be controllers
88
88
+
// and the rest will be vive trackers.
89
89
+
if (results.xpdev_count > 2) {
90
90
+
estimate.maybe.extra_device_count = results.xpdev_count - 2;
91
91
+
}
92
92
+
}
93
93
+
94
94
+
estimate.priority = 0;
95
95
+
96
96
+
xret = xrt_prober_unlock_list(xp, &xpdevs);
97
97
+
if (xret) {
98
98
+
U_LOG_E("Failed to unlock list!");
99
99
+
return xret;
100
100
+
}
101
101
+
102
102
+
*out_valve_have_index = have_valve_index;
103
103
+
*out_estimate = estimate;
104
104
+
105
105
+
return XRT_SUCCESS;
106
106
+
}
+35
src/xrt/auxiliary/vive/vive_builder.h
···
1
1
+
// Copyright 2023, Collabora, Ltd.
2
2
+
// SPDX-License-Identifier: BSL-1.0
3
3
+
/*!
4
4
+
* @file
5
5
+
* @brief Builder helpers for Vive/Index devices.
6
6
+
* @author Jakob Bornecrantz <jakob@collabora.com>
7
7
+
* @ingroup aux_vive
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
+
20
20
+
/*!
21
21
+
* Helper function to do an estimate of a system.
22
22
+
*
23
23
+
* @ingroup aux_vive
24
24
+
*/
25
25
+
xrt_result_t
26
26
+
vive_builder_estimate(struct xrt_prober *xp,
27
27
+
bool have_6dof,
28
28
+
bool have_hand_tracking,
29
29
+
bool *out_valve_have_index,
30
30
+
struct xrt_builder_estimate *out_estimate);
31
31
+
32
32
+
33
33
+
#ifdef __cplusplus
34
34
+
}
35
35
+
#endif