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 
44 {
49 };
50 
52 {
53  struct xrt_device base;
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;
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  {
90  double persistence;
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  {
121  } firmware;
122 
123  struct xrt_quat rot_filtered;
124 
128 
129  struct
130  {
132  bool last;
133  } gui;
134 };
135 
136 struct vive_device *
138  struct os_hid_device *sensors_dev,
139  enum VIVE_VARIANT variant);
140 
141 /*
142  *
143  * Printing functions.
144  *
145  */
146 
147 #define VIVE_SPEW(p, ...) \
148  do { \
149  if (p->print_spew) { \
150  fprintf(stderr, "%s - ", __func__); \
151  fprintf(stderr, __VA_ARGS__); \
152  fprintf(stderr, "\n"); \
153  } \
154  } while (false)
155 #define VIVE_DEBUG(p, ...) \
156  do { \
157  if (p->print_debug) { \
158  fprintf(stderr, "%s - ", __func__); \
159  fprintf(stderr, __VA_ARGS__); \
160  fprintf(stderr, "\n"); \
161  } \
162  } while (false)
163 
164 #define VIVE_ERROR(...) \
165  do { \
166  fprintf(stderr, "%s - ", __func__); \
167  fprintf(stderr, __VA_ARGS__); \
168  fprintf(stderr, "\n"); \
169  } while (false)
170 
171 #ifdef __cplusplus
172 }
173 #endif
double acc_range
Definition: vive_device.h:68
A IMU fusion specially made for 3dof devices.
bool disconnect_notified
Definition: vive_device.h:127
A 3 element vector with single floats.
Definition: xrt_defines.h:133
enum VIVE_VARIANT variant
Definition: vive_device.h:56
A pose composed of a position and orientation.
Definition: xrt_defines.h:231
uint16_t ipd
Definition: vive_device.h:104
struct lh_sensor * sensors
Definition: vive_device.h:28
uint8_t hardware_version_major
Definition: vive_device.h:117
char * device_serial_number
Definition: vive_device.h:120
bool last
Definition: vive_device.h:132
uint16_t proximity
Definition: vive_device.h:106
A single lighthouse senosor point and normal, in IMU space.
Definition: vive_device.h:35
Definition: vive_device.h:51
VIVE_VARIANT
Definition: vive_device.h:43
uint32_t last_sample_time_raw
Definition: vive_device.h:67
A lighthouse consisting of sensors.
Definition: vive_device.h:26
uint64_t time_ns
Definition: vive_device.h:65
A quaternion with single floats.
Definition: xrt_defines.h:99
Wrapper around OS threading native functions.
Definition: vive_device.h:46
char * mb_serial_number
Definition: vive_device.h:118
struct os_hid_device * sensors_dev
Definition: vive_device.h:55
Definition: vive_device.h:45
Header defining a xrt HMD device.
uint8_t hardware_version_minor
Definition: vive_device.h:116
struct vive_device * vive_device_create(struct os_hid_device *mainboard_dev, struct os_hid_device *sensors_dev, enum VIVE_VARIANT variant)
Definition: vive_device.c:964
Definition: vive_device.h:48
Definition: vive_device.h:47
All in one helper that handles locking, waiting for change and starting a thread. ...
Definition: os_threading.h:151
bool print_spew
Definition: vive_device.h:125
uint32_t firmware_version
Definition: vive_device.h:113
uint8_t sequence
Definition: vive_device.h:66
uint32_t _pad0
Definition: vive_device.h:38
uint16_t gyro[3]
Definition: vive_protocol.h:210
Representing a single hid interface on a device.
Definition: os_hid.h:26
uint8_t button
Definition: vive_device.h:107
double persistence
Definition: vive_device.h:90
size_t num_sensors
Definition: vive_device.h:29
struct os_hid_device * mainboard_dev
Definition: vive_device.h:54
double gyro_range
Definition: vive_device.h:69
uint16_t lens_separation
Definition: vive_device.h:105
uint32_t display_firmware_version
Definition: vive_device.h:112
uint8_t hardware_revision
Definition: vive_device.h:114
uint16_t acc[3]
Definition: vive_protocol.h:209
bool print_debug
Definition: vive_device.h:126
uint16_t eye_target_width_in_pixels
Definition: vive_device.h:92
uint32_t _pad1
Definition: vive_device.h:40
A single HMD or input device.
Definition: xrt_device.h:202
uint16_t eye_target_height_in_pixels
Definition: vive_device.h:91
char * model_number
Definition: vive_device.h:119
Definition: m_imu_3dof.h:34
uint8_t hardware_version_micro
Definition: vive_device.h:115
bool calibration
Definition: vive_device.h:131
double lens_separation
Definition: vive_device.h:89