Monado OpenXR Runtime
xreal_air_hmd.h
Go to the documentation of this file.
1// Copyright 2023-2024, Tobias Frisch
2// SPDX-License-Identifier: BSL-1.0
3/*!
4 * @file
5 * @brief Xreal Air packet parsing implementation.
6 * @author Tobias Frisch <thejackimonster@gmail.com>
7 * @ingroup drv_xreal_air
8 */
9
10#pragma once
11
12#include "xrt/xrt_device.h"
13#include "xrt/xrt_prober.h"
14
15#include "os/os_hid.h"
16
17#include "util/u_logging.h"
18
19#ifdef __cplusplus
20extern "C" {
21#endif
22
23#define XREAL_AIR_HANDLE_IFACE 3
24#define XREAL_AIR_CONTROL_IFACE 4
25
26#define XREAL_AIR_MSG_R_BRIGHTNESS 0x03
27#define XREAL_AIR_MSG_W_BRIGHTNESS 0x04
28#define XREAL_AIR_MSG_R_DISP_MODE 0x07
29#define XREAL_AIR_MSG_W_DISP_MODE 0x08
30
31#define XREAL_AIR_MSG_P_START_HEARTBEAT 0x6c02
32#define XREAL_AIR_MSG_P_BUTTON_PRESSED 0x6C05
33#define XREAL_AIR_MSG_P_END_HEARTBEAT 0x6c12
34#define XREAL_AIR_MSG_P_ASYNC_TEXT_LOG 0x6c09
35
36#define XREAL_AIR_BUTTON_PHYS_DISPLAY_TOGGLE 0x1
37#define XREAL_AIR_BUTTON_PHYS_BRIGHTNESS_UP 0x2
38#define XREAL_AIR_BUTTON_PHYS_BRIGHTNESS_DOWN 0x3
39
40#define XREAL_AIR_BUTTON_VIRT_DISPLAY_TOGGLE 0x1
41#define XREAL_AIR_BUTTON_VIRT_MENU_TOGGLE 0x3
42#define XREAL_AIR_BUTTON_VIRT_BRIGHTNESS_UP 0x6
43#define XREAL_AIR_BUTTON_VIRT_BRIGHTNESS_DOWN 0x7
44#define XREAL_AIR_BUTTON_VIRT_MODE_UP 0x8
45#define XREAL_AIR_BUTTON_VIRT_MODE_DOWN 0x9
46
47#define XREAL_AIR_BRIGHTNESS_MIN 0
48#define XREAL_AIR_BRIGHTNESS_MAX 7
49
50#define XREAL_AIR_DISPLAY_MODE_2D 0x1
51#define XREAL_AIR_DISPLAY_MODE_3D 0x3
52
53#define XREAL_AIR_TICKS_PER_SECOND (1000.0) // 1 KHz ticks
54#define XREAL_AIR_NS_PER_TICK (1000000) // Each tick is a millisecond
55
56#define XREAL_AIR_MSG_GET_CAL_DATA_LENGTH 0x14
57#define XREAL_AIR_MSG_CAL_DATA_GET_NEXT_SEGMENT 0x15
58#define XREAL_AIR_MSG_ALLOCATE_CAL_DATA_BUFFER 0x16
59#define XREAL_AIR_MSG_WRITE_CAL_DATA_SEGMENT 0x17
60#define XREAL_AIR_MSG_FREE_CAL_BUFFER 0x18
61#define XREAL_AIR_MSG_START_IMU_DATA 0x19
62#define XREAL_AIR_MSG_GET_STATIC_ID 0x1A
63#define XREAL_AIR_MSG_UNKNOWN 0x1D
64
66{
67 struct xrt_vec3 accel_bias;
68 struct xrt_quat accel_q_gyro;
69 struct xrt_vec3 gyro_bias;
70 struct xrt_quat gyro_q_mag;
71 struct xrt_vec3 mag_bias;
72
73 struct xrt_vec3 scale_accel;
74 struct xrt_vec3 scale_gyro;
75 struct xrt_vec3 scale_mag;
76
77 float imu_noises[4];
78};
79
80/*!
81 * A parsed single gyroscope, accelerometer and
82 * magnetometer sample with their corresponding
83 * factors for conversion from raw data.
84 *
85 * @ingroup drv_xreal_air
86 */
88{
89 struct xrt_vec3_i32 accel;
90 struct xrt_vec3_i32 gyro;
91 struct xrt_vec3_i32 mag;
92
93 int16_t accel_multiplier;
94 int16_t gyro_multiplier;
95 int16_t mag_multiplier;
96
97 int32_t accel_divisor;
98 int32_t gyro_divisor;
99 int32_t mag_divisor;
100};
101
102/*!
103 * Over the wire sensor packet from the glasses.
104 *
105 * @ingroup drv_xreal_air
106 */
108{
109 int16_t temperature;
110 uint64_t timestamp;
111
112 struct xreal_air_parsed_sample sample;
113};
114
115/*!
116 * Over the wire sensor control data packet from the glasses.
117 *
118 * @ingroup drv_xreal_air
119 */
121{
122 uint16_t length;
123 uint8_t msgid;
124
125 uint8_t data[56];
126};
127
128/*!
129 * A control packet from the glasses in wire format.
130 *
131 * @ingroup drv_xreal_air
132 */
134{
135 uint16_t length;
136 uint64_t timestamp;
137 uint16_t action;
138
139 uint8_t data[42];
140};
141
142/*!
143 * Create Xreal Air glasses.
144 *
145 * @ingroup drv_xreal_air
146 */
147struct xrt_device *
148xreal_air_hmd_create_device(struct os_hid_device *sensor_device,
149 struct os_hid_device *control_device,
150 enum u_logging_level log_level);
151
152bool
153xreal_air_parse_calibration_buffer(struct xreal_air_parsed_calibration *calibration, const char *buffer, size_t size);
154
155bool
156xreal_air_parse_sensor_packet(struct xreal_air_parsed_sensor *sensor, const uint8_t *buffer, int size);
157
158bool
159xreal_air_parse_sensor_control_data_packet(struct xreal_air_parsed_sensor_control_data *data,
160 const uint8_t *buffer,
161 int size);
162
163bool
164xreal_air_parse_control_packet(struct xreal_air_parsed_control *control, const uint8_t *buffer, int size);
165
166#ifdef __cplusplus
167}
168#endif
u_logging_level
Logging level enum.
Definition: u_logging.h:40
struct xrt_device * xreal_air_hmd_create_device(struct os_hid_device *sensor_device, struct os_hid_device *control_device, enum u_logging_level log_level)
Create Xreal Air glasses.
Definition: xreal_air_hmd.c:1102
Wrapper around OS native hid functions.
Representing a single hid interface on a device.
Definition: os_hid.h:29
Definition: xreal_air_hmd.h:66
A control packet from the glasses in wire format.
Definition: xreal_air_hmd.h:134
A parsed single gyroscope, accelerometer and magnetometer sample with their corresponding factors for...
Definition: xreal_air_hmd.h:88
Over the wire sensor control data packet from the glasses.
Definition: xreal_air_hmd.h:121
Over the wire sensor packet from the glasses.
Definition: xreal_air_hmd.h:108
A single HMD or input device.
Definition: xrt_device.h:230
A quaternion with single floats.
Definition: xrt_defines.h:216
A 3 element vector with 32 bit integers.
Definition: xrt_defines.h:336
A 3 element vector with single floats.
Definition: xrt_defines.h:271
Basic logging functionality.
Header defining an xrt display or controller device.
Common interface to probe for devices.