Monado OpenXR Runtime
survive_internal.h
Go to the documentation of this file.
1// Copyright 2019-2023, Collabora, Ltd.
2// Copyright 2026, Beyley Cardellio
3// SPDX-License-Identifier: BSL-1.0
4/*!
5 * @file
6 * @brief Adapter to Libsurvive.
7 * @author Christoph Haag <christoph.haag@collabora.com>
8 * @author Jakob Bornecrantz <jakob@collabora.com>
9 * @author Moshi Turner <moshiturner@protonmail.com>
10 * @author Beyley Cardellio <ep1cm1n10n123@gmail.com>
11 * @ingroup drv_survive
12 */
13
14#pragma once
15
16#include "tracking/t_tracking.h"
17
19#include "util/u_var.h"
20
21#include "os/os_threading.h"
22
23#include "vp2/vp2_config.h"
24#include "vp2/vp2_hid.h"
25
26#include "survive_interface.h"
27#include "survive_api.h"
28
29
30#define SURVIVE_TRACE(d, ...) U_LOG_XDEV_IFL_T(&d->base, d->sys->log_level, __VA_ARGS__)
31#define SURVIVE_DEBUG(d, ...) U_LOG_XDEV_IFL_D(&d->base, d->sys->log_level, __VA_ARGS__)
32#define SURVIVE_INFO(d, ...) U_LOG_XDEV_IFL_I(&d->base, d->sys->log_level, __VA_ARGS__)
33#define SURVIVE_WARN(d, ...) U_LOG_XDEV_IFL_W(&d->base, d->sys->log_level, __VA_ARGS__)
34#define SURVIVE_ERROR(d, ...) U_LOG_XDEV_IFL_E(&d->base, d->sys->log_level, __VA_ARGS__)
35
36//! excl HMD we support 16 devices (controllers, trackers, ...)
37#define MAX_TRACKED_DEVICE_COUNT 16
38
39enum input_index
40{
41 // common inputs
42 VIVE_CONTROLLER_AIM_POSE = 0,
43 VIVE_CONTROLLER_GRIP_POSE,
44 VIVE_CONTROLLER_SYSTEM_CLICK,
45 VIVE_CONTROLLER_TRIGGER_CLICK,
46 VIVE_CONTROLLER_TRIGGER_VALUE,
47 VIVE_CONTROLLER_TRACKPAD,
48 VIVE_CONTROLLER_TRACKPAD_TOUCH,
49
50 // Vive Wand specific inputs
51 VIVE_CONTROLLER_SQUEEZE_CLICK,
52 VIVE_CONTROLLER_MENU_CLICK,
53 VIVE_CONTROLLER_TRACKPAD_CLICK,
54
55 // Valve Index specific inputs
56 VIVE_CONTROLLER_THUMBSTICK,
57 VIVE_CONTROLLER_A_CLICK,
58 VIVE_CONTROLLER_B_CLICK,
59 VIVE_CONTROLLER_THUMBSTICK_CLICK,
60 VIVE_CONTROLLER_THUMBSTICK_TOUCH,
61 VIVE_CONTROLLER_SYSTEM_TOUCH,
62 VIVE_CONTROLLER_A_TOUCH,
63 VIVE_CONTROLLER_B_TOUCH,
64 VIVE_CONTROLLER_SQUEEZE_VALUE,
65 VIVE_CONTROLLER_SQUEEZE_FORCE,
66 VIVE_CONTROLLER_TRIGGER_TOUCH,
67 VIVE_CONTROLLER_TRACKPAD_FORCE,
68
69 VIVE_CONTROLLER_HAND_TRACKING,
70
71 VIVE_TRACKER_POSE,
72
73 VIVE_CONTROLLER_MAX_INDEX,
74};
75
76enum DeviceType
77{
78 DEVICE_TYPE_HMD,
79 DEVICE_TYPE_CONTROLLER
80};
81
82struct survive_system;
83
84/*!
85 * @implements xrt_device
86 */
88{
89 struct xrt_device base;
90 struct survive_system *sys;
91 const SurviveSimpleObject *survive_obj;
92
93 struct m_relation_history *relation_hist;
94
95 //! Number of inputs.
97 //! Array of input structs.
99
100 enum DeviceType device_type;
101
102 union {
103 struct
104 {
105 float proximity; // [0,1]
106 //! The current IPD given by the headset
107 float ipd;
108 //! The IPD to force, -1 if no override
110 //! Whether to use the default eye relation, or the IPD given by the HMD
112
113 struct vive_config config;
114
115 struct vp2_hid *vp2_hid;
116 } hmd;
117
118 struct
119 {
120 float curl[XRT_FINGER_COUNT];
121 uint64_t curl_ts[XRT_FINGER_COUNT];
122 struct u_hand_tracking hand_tracking;
123
124 struct vive_controller_config config;
125 } ctrl;
126 };
127};
128
129/*!
130 * @extends xrt_tracking_origin
131 */
133{
134 struct xrt_tracking_origin base;
135 SurviveSimpleContext *ctx;
136 struct survive_device *hmd;
137 struct survive_device *controllers[MAX_TRACKED_DEVICE_COUNT];
138 enum u_logging_level log_level;
139 struct xrt_prober *xp;
140
141 float wait_timeout;
142 struct u_var_draggable_f32 timecode_offset_ms;
143
144 struct os_thread_helper event_thread;
145 struct os_mutex lock;
146};
u_logging_level
Logging level enum.
Definition: u_logging.h:45
#define XRT_FINGER_COUNT
Number of fingers on a hand.
Definition: xrt_defines.h:1469
Wrapper around OS threading native functions.
Definition: m_relation_history.cpp:49
A wrapper around a native mutex.
Definition: os_threading.h:69
All in one helper that handles locking, waiting for change and starting a thread.
Definition: os_threading.h:499
Definition: survive_internal.h:88
bool use_default_ipd
Whether to use the default eye relation, or the IPD given by the HMD.
Definition: survive_internal.h:111
struct xrt_input * last_inputs
Array of input structs.
Definition: survive_internal.h:98
float ipd_override_mm
The IPD to force, -1 if no override.
Definition: survive_internal.h:109
float ipd
The current IPD given by the headset.
Definition: survive_internal.h:107
size_t num_last_inputs
Number of inputs.
Definition: survive_internal.h:96
Definition: survive_internal.h:133
Main struct drivers can use to implement hand and finger tracking.
Definition: u_hand_tracking.h:93
Draggable single precision float information.
Definition: u_var.h:128
headset config.
Definition: vive_config.h:133
Controller config.
Definition: vive_config.h:210
Definition: vp2_hid.c:40
A single HMD or input device.
Definition: xrt_device.h:310
A single named input, that sits on a xrt_device.
Definition: xrt_device.h:188
The main prober that probes and manages found but not opened HMD devices that are connected to the sy...
Definition: xrt_prober.h:133
A tracking system or device origin.
Definition: xrt_tracking.h:75
Interface to Libsurvive adapter.
#define MAX_TRACKED_DEVICE_COUNT
excl HMD we support 16 devices (controllers, trackers, ...)
Definition: survive_internal.h:37
Tracking API interface.
Hand Tracking API interface.
Variable tracking code.
Code to parse and handle the Vive Pro 2 configuration data.
Implementation of the Vive Pro 2 HID interface.