Monado OpenXR Runtime
psvr_device.h
Go to the documentation of this file.
1 // Copyright 2016, Joey Ferwerda.
2 // Copyright 2019, Collabora, Ltd.
3 // SPDX-License-Identifier: BSL-1.0
4 /*!
5  * @file
6  * @brief PSVR device header, imported from OpenHMD.
7  * @author Joey Ferwerda <joeyferweda@gmail.com>
8  * @author Philipp Zabel <philipp.zabel@gmail.com>
9  * @author Jakob Bornecrantz <jakob@collabora.com>
10  * @ingroup drv_psvr
11  */
12 
13 #pragma once
14 
15 #include "xrt/xrt_device.h"
16 #include "xrt/xrt_prober.h"
17 
18 #include <hidapi/hidapi.h>
19 
20 
21 #ifdef __cplusplus
22 extern "C" {
23 #endif
24 
25 
26 /*
27  *
28  * Defines
29  *
30  */
31 
32 #define PSVR_VID 0x054c
33 #define PSVR_PID 0x09af
34 
35 #define PSVR_HANDLE_IFACE 4
36 #define PSVR_CONTROL_IFACE 5
37 
38 enum psvr_status_bits
39 {
40  // clang-format off
41  PSVR_STATUS_BIT_POWER = (1 << 0),
42  PSVR_STATUS_BIT_HMD_WORN = (1 << 1),
43  PSVR_STATUS_BIT_CINEMATIC_MODE = (1 << 2),
44  PSVR_STATUS_BIT_UNKNOWN_BIT_3 = (1 << 3),
45  PSVR_STATUS_BIT_HEADPHONES_CONNECTED = (1 << 4),
46  PSVR_STATUS_BIT_MUTE_ENABLED = (1 << 5),
47  PSVR_STATUS_BIT_UNKNOWN_BIT_6 = (1 << 6),
48  PSVR_STATUS_BIT_UNKNOWN_BIT_7 = (1 << 7),
49  // clang-format on
50 };
51 
52 #define PSVR_STATUS_VR_MODE_OFF 0
53 #define PSVR_STATUS_VR_MODE_ON 1
54 
55 #define PSVR_TICKS_PER_SECOND (1000000.0) // 1 MHz ticks
56 #define PSVR_NS_PER_TICK (1000) // Each tick is a microsecond
57 
58 #define PSVR_PKG_STATUS 0xF0
59 #define PSVR_PKG_DEVICE_NAME 0x80
60 #define PSVR_PKG_CALIBRATION 0x86
61 #define PSVR_PKG_0xA0 0xA0
62 #define PSVR_PKG_0x82 0x82
63 
64 #define PSVR_GET_DATA_ID_DEVICE_NAME 0x80
65 #define PSVR_GET_DATA_ID_CALIBRATION 0x86
66 #define PSVR_GET_DATA_ID_0x82 0x82
67 
68 
69 /*
70  *
71  * Structs
72  *
73  */
74 
75 /*!
76  * A parsed single gyro, accel and tick sample.
77  *
78  * @ingroup drv_psvr
79  */
81 {
82  struct xrt_vec3_i32 accel;
83  struct xrt_vec3_i32 gyro;
84  uint32_t tick;
85 };
86 
87 /*!
88  * Over the wire sensor packet from the headset.
89  *
90  * @ingroup drv_psvr
91  */
93 {
94  uint8_t buttons;
95  uint8_t state;
96  uint16_t volume;
97  uint16_t button_raw;
98  uint16_t proximity;
99  uint8_t seq;
100 
101  struct psvr_parsed_sample samples[2];
102 };
103 
104 /*!
105  * A status packet from the headset in wire format.
106  *
107  * @ingroup drv_psvr
108  */
110 {
111  uint8_t status;
112  uint8_t volume;
113  uint8_t display_time;
114  uint8_t vr_mode;
115 };
116 
117 
118 /*
119  *
120  * Functions
121  *
122  */
123 
124 struct xrt_device *
125 psvr_device_create(struct hid_device_info *hmd_handle_info,
126  struct hid_device_info *hmd_control_info,
127  struct xrt_prober *xp,
128  bool print_spew,
129  bool print_debug);
130 
131 bool
132 psvr_parse_sensor_packet(struct psvr_parsed_sensor *sensor,
133  const uint8_t *buffer,
134  int size);
135 
136 bool
137 psvr_parse_status_packet(struct psvr_parsed_status *status,
138  const uint8_t *buffer,
139  int size);
140 
141 
142 /*
143  *
144  * Printing functions.
145  *
146  */
147 
148 #define PSVR_SPEW(p, ...) \
149  do { \
150  if (p->print_spew) { \
151  fprintf(stderr, "%s - ", __func__); \
152  fprintf(stderr, __VA_ARGS__); \
153  fprintf(stderr, "\n"); \
154  } \
155  } while (false)
156 #define PSVR_DEBUG(p, ...) \
157  do { \
158  if (p->print_debug) { \
159  fprintf(stderr, "%s - ", __func__); \
160  fprintf(stderr, __VA_ARGS__); \
161  fprintf(stderr, "\n"); \
162  } \
163  } while (false)
164 
165 #define PSVR_ERROR(p, ...) \
166  do { \
167  fprintf(stderr, "%s - ", __func__); \
168  fprintf(stderr, __VA_ARGS__); \
169  fprintf(stderr, "\n"); \
170  } while (false)
171 
172 
173 #ifdef __cplusplus
174 }
175 #endif
A parsed single gyro, accel and tick sample.
Definition: psvr_device.h:80
Header defining a xrt HMD device.
Common interface to probe for devices.
A 3 element vector with 32 bit integers.
Definition: xrt_defines.h:143
The main prober that probes and manages found but not opened HMD devices that are connected to the sy...
Definition: xrt_prober.h:147
A status packet from the headset in wire format.
Definition: psvr_device.h:109
struct xrt_device * psvr_device_create(struct hid_device_info *hmd_handle_info, struct hid_device_info *hmd_control_info, struct xrt_prober *xp, bool print_spew, bool print_debug)
Definition: psvr_device.c:1011
Over the wire sensor packet from the headset.
Definition: psvr_device.h:92
A single HMD or input device.
Definition: xrt_device.h:203