Monado OpenXR Runtime
xreal_air_hmd.h
Go to the documentation of this file.
1// Copyright 2023-2025, Tobias Frisch
2// SPDX-License-Identifier: BSL-1.0
3/*!
4 * @file
5 * @brief Xreal Air packet parsing implementation.
6 * @author Tobias Frisch <jacki@thejackimonster.de>
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_MSG_R_BRIGHTNESS 0x03
24#define XREAL_AIR_MSG_W_BRIGHTNESS 0x04
25#define XREAL_AIR_MSG_R_DISP_MODE 0x07
26#define XREAL_AIR_MSG_W_DISP_MODE 0x08
27
28#define XREAL_AIR_MSG_P_START_HEARTBEAT 0x6c02
29#define XREAL_AIR_MSG_P_DISPLAY_TOGGLED 0x6C04
30#define XREAL_AIR_MSG_P_BUTTON_PRESSED 0x6C05
31#define XREAL_AIR_MSG_P_END_HEARTBEAT 0x6c12
32#define XREAL_AIR_MSG_P_ASYNC_TEXT_LOG 0x6c09
33
34#define XREAL_AIR_BUTTON_PHYS_DISPLAY_TOGGLE 0x1
35#define XREAL_AIR_BUTTON_PHYS_BRIGHTNESS_UP 0x2
36#define XREAL_AIR_BUTTON_PHYS_BRIGHTNESS_DOWN 0x3
37
38#define XREAL_AIR_BUTTON_VIRT_DISPLAY_TOGGLE 0x1
39#define XREAL_AIR_BUTTON_VIRT_MENU_TOGGLE 0x3
40#define XREAL_AIR_BUTTON_VIRT_BRIGHTNESS_UP 0x6
41#define XREAL_AIR_BUTTON_VIRT_BRIGHTNESS_DOWN 0x7
42#define XREAL_AIR_BUTTON_VIRT_UP 0x8
43#define XREAL_AIR_BUTTON_VIRT_DOWN 0x9
44#define XREAL_AIR_BUTTON_VIRT_MODE_2D 0xA
45#define XREAL_AIR_BUTTON_VIRT_MODE_3D 0xB
46#define XREAL_AIR_BUTTON_VIRT_BLEND_CYCLE 0xC
47#define XREAL_AIR_BUTTON_VIRT_CONTROL_TOGGLE 0xF
48
49#define XREAL_AIR_BLEND_STATE_LOW 0x0
50#define XREAL_AIR_BLEND_STATE_DEFAULT 0x1
51#define XREAL_AIR_BLEND_STATE_MEDIUM 0x2
52#define XREAL_AIR_BLEND_STATE_FULL 0x3
53
54#define XREAL_AIR_CONTROL_MODE_BRIGHTNESS 0x0
55#define XREAL_AIR_CONTROL_MODE_VOLUME 0x1
56
57#define XREAL_AIR_BRIGHTNESS_MIN 0
58#define XREAL_AIR_BRIGHTNESS_MAX 7
59
60#define XREAL_AIR_DISPLAY_MODE_2D 0x1
61#define XREAL_AIR_DISPLAY_MODE_3D 0x3
62
63#define XREAL_AIR_TICKS_PER_SECOND (1000.0) // 1 KHz ticks
64#define XREAL_AIR_NS_PER_TICK (1000000) // Each tick is a millisecond
65
66#define XREAL_AIR_MSG_GET_CAL_DATA_LENGTH 0x14
67#define XREAL_AIR_MSG_CAL_DATA_GET_NEXT_SEGMENT 0x15
68#define XREAL_AIR_MSG_ALLOCATE_CAL_DATA_BUFFER 0x16
69#define XREAL_AIR_MSG_WRITE_CAL_DATA_SEGMENT 0x17
70#define XREAL_AIR_MSG_FREE_CAL_BUFFER 0x18
71#define XREAL_AIR_MSG_START_IMU_DATA 0x19
72#define XREAL_AIR_MSG_GET_STATIC_ID 0x1A
73#define XREAL_AIR_MSG_UNKNOWN 0x1D
74
76{
77 struct xrt_vec3 accel_bias;
78 struct xrt_quat accel_q_gyro;
79 struct xrt_vec3 gyro_bias;
80 struct xrt_quat gyro_q_mag;
81 struct xrt_vec3 mag_bias;
82
83 struct xrt_vec3 scale_accel;
84 struct xrt_vec3 scale_gyro;
85 struct xrt_vec3 scale_mag;
86
87 float imu_noises[4];
88};
89
90/*!
91 * A parsed single gyroscope, accelerometer and
92 * magnetometer sample with their corresponding
93 * factors for conversion from raw data.
94 *
95 * @ingroup drv_xreal_air
96 */
98{
99 struct xrt_vec3_i32 accel;
100 struct xrt_vec3_i32 gyro;
101 struct xrt_vec3_i32 mag;
102
103 int16_t accel_multiplier;
104 int16_t gyro_multiplier;
105 int16_t mag_multiplier;
106
107 int32_t accel_divisor;
108 int32_t gyro_divisor;
109 int32_t mag_divisor;
110};
111
112/*!
113 * Over the wire sensor packet from the glasses.
114 *
115 * @ingroup drv_xreal_air
116 */
118{
119 int16_t temperature;
120 uint64_t timestamp;
121
122 struct xreal_air_parsed_sample sample;
123};
124
125/*!
126 * Over the wire sensor control data packet from the glasses.
127 *
128 * @ingroup drv_xreal_air
129 */
131{
132 uint16_t length;
133 uint8_t msgid;
134
135 uint8_t data[512 - 8];
136};
137
138/*!
139 * A control packet from the glasses in wire format.
140 *
141 * @ingroup drv_xreal_air
142 */
144{
145 uint16_t length;
146 uint64_t timestamp;
147 uint16_t action;
148
149 uint8_t data[42];
150};
151
152/*!
153 * Create Xreal Air glasses.
154 *
155 * @ingroup drv_xreal_air
156 */
157struct xrt_device *
158xreal_air_hmd_create_device(struct os_hid_device *sensor_device,
159 struct os_hid_device *control_device,
160 enum u_logging_level log_level,
161 uint16_t max_sensor_buffer_size);
162
163bool
164xreal_air_parse_calibration_buffer(struct xreal_air_parsed_calibration *calibration, const char *buffer, size_t size);
165
166bool
167xreal_air_parse_sensor_packet(struct xreal_air_parsed_sensor *sensor,
168 const uint8_t *buffer,
169 size_t size,
170 size_t max_size);
171
172bool
173xreal_air_parse_sensor_control_data_packet(struct xreal_air_parsed_sensor_control_data *data,
174 const uint8_t *buffer,
175 size_t size,
176 size_t max_size);
177
178bool
179xreal_air_parse_control_packet(struct xreal_air_parsed_control *control, const uint8_t *buffer, int size);
180
181#ifdef __cplusplus
182}
183#endif
u_logging_level
Logging level enum.
Definition: u_logging.h:44
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, uint16_t max_sensor_buffer_size)
Create Xreal Air glasses.
Definition: xreal_air_hmd.c:1183
Wrapper around OS native hid functions.
Representing a single hid interface on a device.
Definition: os_hid.h:29
Definition: xreal_air_hmd.h:76
A control packet from the glasses in wire format.
Definition: xreal_air_hmd.h:144
A parsed single gyroscope, accelerometer and magnetometer sample with their corresponding factors for...
Definition: xreal_air_hmd.h:98
Over the wire sensor control data packet from the glasses.
Definition: xreal_air_hmd.h:131
Over the wire sensor packet from the glasses.
Definition: xreal_air_hmd.h:118
A single HMD or input device.
Definition: xrt_device.h:281
A quaternion with single floats.
Definition: xrt_defines.h:219
A 3 element vector with 32 bit integers.
Definition: xrt_defines.h:334
A 3 element vector with single floats.
Definition: xrt_defines.h:273
Basic logging functionality.
Header defining an xrt display or controller device.
Common interface to probe for devices.