Monado OpenXR Runtime
vive_device.h
Go to the documentation of this file.
1 // Copyright 2019, Collabora, Ltd.
2 // SPDX-License-Identifier: BSL-1.0
3 /*!
4  * @file
5  * @brief vive device header
6  * @author Lubosz Sarnecki <lubosz.sarnecki@collabora.com>
7  * @ingroup drv_vive
8  */
9 
10 #pragma once
11 
12 #include "xrt/xrt_device.h"
13 #include "math/m_imu_3dof.h"
14 #include "os/os_threading.h"
15 
16 #ifdef __cplusplus
17 extern "C" {
18 #endif
19 
20 
21 /*!
22  * A lighthouse consisting of sensors.
23  *
24  * All sensors are placed in IMU space.
25  */
26 struct lh_model
27 {
28  struct lh_sensor *sensors;
29  size_t num_sensors;
30 };
31 
32 /*!
33  * A single lighthouse senosor point and normal, in IMU space.
34  */
35 struct lh_sensor
36 {
37  struct xrt_vec3 pos;
38  uint32_t _pad0;
39  struct xrt_vec3 normal;
40  uint32_t _pad1;
41 };
42 
43 enum VIVE_VARIANT
44 {
45  VIVE_UNKNOWN = 0,
46  VIVE_VARIANT_VIVE,
47  VIVE_VARIANT_PRO,
48  VIVE_VARIANT_INDEX
49 };
50 
52 {
53  struct xrt_device base;
54  struct os_hid_device *mainboard_dev;
55  struct os_hid_device *sensors_dev;
56  enum VIVE_VARIANT variant;
57 
58  struct os_thread_helper sensors_thread;
59  struct os_thread_helper mainboard_thread;
60 
61  struct lh_model lh;
62 
63  struct
64  {
65  uint64_t time_ns;
66  uint8_t sequence;
67  uint32_t last_sample_time_raw;
68  double acc_range;
69  double gyro_range;
70  struct xrt_vec3 acc_bias;
71  struct xrt_vec3 acc_scale;
72  struct xrt_vec3 gyro_bias;
73  struct xrt_vec3 gyro_scale;
74 
75  //! IMU position in tracking space.
76  struct xrt_pose trackref;
77  } imu;
78 
79  struct m_imu_3dof fusion;
80 
81  struct
82  {
83  struct xrt_vec3 acc;
84  struct xrt_vec3 gyro;
85  } last;
86 
87  struct
88  {
89  double lens_separation;
90  double persistence;
91  uint16_t eye_target_height_in_pixels;
92  uint16_t eye_target_width_in_pixels;
93 
94  struct xrt_quat rot[2];
95 
96  //! Head position in tracking space.
97  struct xrt_pose trackref;
98  //! Head position in IMU space.
99  struct xrt_pose imuref;
100  } display;
101 
102  struct
103  {
104  uint16_t ipd;
105  uint16_t lens_separation;
106  uint16_t proximity;
107  uint8_t button;
108  } board;
109 
110  struct
111  {
112  uint32_t display_firmware_version;
113  uint32_t firmware_version;
114  uint8_t hardware_revision;
115  char *mb_serial_number;
116  char *model_number;
117  char *device_serial_number;
118  } firmware;
119 
120  struct xrt_quat rot_filtered;
121 
122  bool print_spew;
123  bool print_debug;
124  bool disconnect_notified;
125 
126  struct
127  {
128  bool calibration;
129  bool last;
130  } gui;
131 };
132 
133 struct vive_device *
134 vive_device_create(struct os_hid_device *mainboard_dev,
135  struct os_hid_device *sensors_dev,
136  enum VIVE_VARIANT variant);
137 
138 /*
139  *
140  * Printing functions.
141  *
142  */
143 
144 #define VIVE_SPEW(p, ...) \
145  do { \
146  if (p->print_spew) { \
147  fprintf(stderr, "%s - ", __func__); \
148  fprintf(stderr, __VA_ARGS__); \
149  fprintf(stderr, "\n"); \
150  } \
151  } while (false)
152 #define VIVE_DEBUG(p, ...) \
153  do { \
154  if (p->print_debug) { \
155  fprintf(stderr, "%s - ", __func__); \
156  fprintf(stderr, __VA_ARGS__); \
157  fprintf(stderr, "\n"); \
158  } \
159  } while (false)
160 
161 #define VIVE_ERROR(...) \
162  do { \
163  fprintf(stderr, "%s - ", __func__); \
164  fprintf(stderr, __VA_ARGS__); \
165  fprintf(stderr, "\n"); \
166  } while (false)
167 
168 #ifdef __cplusplus
169 }
170 #endif
A IMU fusion specially made for 3dof devices.
A 3 element vector with single floats.
Definition: xrt_defines.h:131
A pose composed of a position and orientation.
Definition: xrt_defines.h:229
A single lighthouse senosor point and normal, in IMU space.
Definition: vive_device.h:35
Definition: vive_device.h:51
A lighthouse consisting of sensors.
Definition: vive_device.h:26
A quaternion with single floats.
Definition: xrt_defines.h:97
Wrapper around OS threading native functions.
Header defining a xrt HMD device.
All in one helper that handles locking, waiting for change and starting a thread. ...
Definition: os_threading.h:149
Representing a single hid interface on a device.
Definition: os_hid.h:26
A single HMD or input device.
Definition: xrt_device.h:203
Definition: m_imu_3dof.h:34