Monado OpenXR Runtime
Loading...
Searching...
No Matches
contactglove_protocol.h
Go to the documentation of this file.
1// Copyright 2026, Beyley Cardellio
2// SPDX-License-Identifier: BSL-1.0
3/*!
4 * @file
5 * @brief Implementation of ContactGlove device driver.
6 * @author Beyley Cardellio <ep1cm1n10n123@gmail.com>
7 * @ingroup drv_contactglove
8 */
9
10#include <xrt/xrt_compiler.h>
11#include <xrt/xrt_byte_order.h>
12
13
14#define PING_INTERVAL_NS (1000LL * U_TIME_1MS_IN_NS) // 1000 ms
15#define PING_TIMEOUT_NS (800LL * U_TIME_1MS_IN_NS) // 800 ms
16
17#define CONTACTGLOVE2_SENSOR_COUNT 16
18
19enum contactglove_to_device_packet_mode
20{
21 CONTACTGLOVE_TO_DEVICE_PACKET_MODE_REQUEST_PAIRING = 2,
22 CONTACTGLOVE_TO_DEVICE_PACKET_MODE_DEBUG = 6,
23 CONTACTGLOVE_TO_DEVICE_PACKET_MODE_REQUEST_VERSION = 7,
24 CONTACTGLOVE_TO_DEVICE_PACKET_MODE_PING = 8,
25 CONTACTGLOVE_TO_DEVICE_PACKET_MODE_SWITCH_CHANNEL = 13,
26 CONTACTGLOVE_TO_DEVICE_PACKET_MODE_BODY_HAPTICS_LEFT = 15,
27 CONTACTGLOVE_TO_DEVICE_PACKET_MODE_BODY_HAPTICS_RIGHT = 16,
28 CONTACTGLOVE_TO_DEVICE_PACKET_MODE_SET_MODULE_STATE = 22,
29 CONTACTGLOVE_TO_DEVICE_PACKET_MODE_REQUEST_MODULE_STATE = 24,
30};
31
32enum contactglove_to_host_packet_mode
33{
34 CONTACTGLOVE_TO_HOST_PACKET_MODE_SENSOR_VALUE_LEFT = 4,
35 CONTACTGLOVE_TO_HOST_PACKET_MODE_SENSOR_VALUE_RIGHT = 5,
36 CONTACTGLOVE_TO_HOST_PACKET_MODE_DEBUG = 6,
37 CONTACTGLOVE_TO_HOST_PACKET_MODE_DEVICE_VERSION = 7,
38 CONTACTGLOVE_TO_HOST_PACKET_MODE_LEFT_PING = 8,
39 CONTACTGLOVE_TO_HOST_PACKET_MODE_RIGHT_PING = 9,
40 CONTACTGLOVE_TO_HOST_PACKET_MODE_HAND_GYRO_DATA_LEFT = 10,
41 CONTACTGLOVE_TO_HOST_PACKET_MODE_HAND_GYRO_DATA_RIGHT = 11,
42 CONTACTGLOVE_TO_HOST_PACKET_MODE_MODULE_STATE = 14,
43 CONTACTGLOVE_TO_HOST_PACKET_MODE_HAND_MAGNETRA2_INPUT_LEFT = 21,
44 CONTACTGLOVE_TO_HOST_PACKET_MODE_HAND_MAGNETRA2_INPUT_RIGHT = 22,
45 CONTACTGLOVE_TO_HOST_PACKET_MODE_GLOVE_CONNECTION = 30,
46 CONTACTGLOVE_TO_HOST_PACKET_MODE_ERROR_LOG = 100,
47};
48
49#pragma pack(push, 1)
50
51#define SIZE_ASSERT(type, size) \
52 static_assert(sizeof(type) == (size), "Size of " #type " is not " #size " bytes as was expected")
53
55{
56 uint8_t major;
57 uint8_t minor;
58};
59
61{
62 struct contactglove_version dongle;
63 struct contactglove_version left;
64 struct contactglove_version right;
65};
67
69{
70 uint8_t battery_raw;
71 uint8_t charge_status;
72};
73
75{
76 struct contactglove_raw_battery_info battery_left;
77 struct contactglove_raw_battery_info battery_right;
78 uint8_t channel;
79};
81
83{
84 uint8_t nonce;
85 __le16 glove_to_dongle_ms;
86};
87SIZE_ASSERT(struct contactglove_to_host_packet_ping, 3);
88
90{
91 __le16 quat_raw[4];
92};
94
95enum contactglove_sensor_position
96{
97 CONTACTGLOVE_SENSOR_POSITION_FINGER_PINKY_ROOT1,
98 CONTACTGLOVE_SENSOR_POSITION_FINGER_PINKY_TIP,
99 CONTACTGLOVE_SENSOR_POSITION_FINGER_PINKY_ROOT2,
100 CONTACTGLOVE_SENSOR_POSITION_FINGER_RING_ROOT1,
101 CONTACTGLOVE_SENSOR_POSITION_FINGER_RING_TIP,
102 CONTACTGLOVE_SENSOR_POSITION_FINGER_RING_ROOT2,
103 CONTACTGLOVE_SENSOR_POSITION_FINGER_MIDDLE_ROOT1,
104 CONTACTGLOVE_SENSOR_POSITION_FINGER_MIDDLE_TIP,
105 CONTACTGLOVE_SENSOR_POSITION_FINGER_MIDDLE_ROOT2,
106 CONTACTGLOVE_SENSOR_POSITION_FINGER_INDEX_ROOT1,
107 CONTACTGLOVE_SENSOR_POSITION_FINGER_INDEX_TIP,
108 CONTACTGLOVE_SENSOR_POSITION_FINGER_INDEX_ROOT2,
109 CONTACTGLOVE_SENSOR_POSITION_FINGER_THUMB_ROOT1,
110 CONTACTGLOVE_SENSOR_POSITION_FINGER_THUMB_TIP,
111 CONTACTGLOVE_SENSOR_POSITION_FINGER_THUMB_ROOT2,
112 CONTACTGLOVE_SENSOR_POSITION_FINGER_THUMB_BASE,
113};
114
116{
117 uint8_t mode;
118 uint8_t valid;
119 __le16 sensor_values[CONTACTGLOVE2_SENSOR_COUNT];
120};
121SIZE_ASSERT(struct contactglove_to_host_packet_sensor_data, 1 + 1 + (2 * CONTACTGLOVE2_SENSOR_COUNT));
122
123enum contactglove_magnetra2_button_bits
124{
125 MAGNETRA2_BUTTON_BITS_A = (1 << 0),
126 MAGNETRA2_BUTTON_BITS_B = (1 << 1),
127 MAGNETRA2_BUTTON_BITS_TRIGGER_CLICK = (1 << 2),
128 MAGNETRA2_BUTTON_BITS_TRACKPAD_BOTTOM = (1 << 3),
129 MAGNETRA2_BUTTON_BITS_PAIRING = (1 << 4),
130};
131
132enum contactglove_magnetra2_multi_ch_ranges
133{
134 MAGNETRA2_MULTI_CH_RANGE_JOYSTICK_START = 0,
135 MAGNETRA2_MULTI_CH_RANGE_JOYSTICK_END = 50,
136 MAGNETRA2_MULTI_CH_RANGE_TRACKPAD_TOP_START = 51,
137 MAGNETRA2_MULTI_CH_RANGE_TRACKPAD_TOP_END = 150,
138 MAGNETRA2_MULTI_CH_RANGE_SYSTEM_START = 151,
139 MAGNETRA2_MULTI_CH_RANGE_SYSTEM_END = 210,
140 MAGNETRA2_MULTI_CH_RANGE_NONE_START = 211,
141 MAGNETRA2_MULTI_CH_RANGE_NONE_END = 255,
142};
143
145{
146 uint8_t button_bits;
147 uint8_t joystick_x;
148 uint8_t joystick_y;
149 uint8_t trigger;
150 uint8_t multi_ch_value;
151};
153
154enum contactglove_module_kind
155{
156 CONTACTGLOVE_MODULE_MAGNETRA2 = 1,
157 CONTACTGLOVE_MODULE_LED_MANAGER = 4,
158 CONTACTGLOVE_MODULE_SLEEP_MANAGER = 11,
159 CONTACTGLOVE_MODULE_MAX,
160};
161
162enum contactglove_device_role
163{
164 CONTACTGLOVE_DEVICE_ROLE_LEFT = 1,
165 CONTACTGLOVE_DEVICE_ROLE_RIGHT = 2,
166};
167
169{
170 uint8_t device_role; // Maps to enum contactglove_device_role
171 uint8_t module_kind; // Maps to enum contactglove_module_kind
172 uint8_t data_length;
173};
175
177{
178 uint8_t enabled;
179};
180SIZE_ASSERT(struct contactglove_module_state_magnetra2, 1);
181
183{
184 //! How long until the glove goes into sleep mode, 255=disabled
186 //! Unused
188};
189SIZE_ASSERT(struct contactglove_module_state_sleep_manager, 2);
190
192{
193 uint8_t r;
194 uint8_t g;
195 uint8_t b;
196};
197SIZE_ASSERT(struct contactglove_module_state_led_manager, 3);
198
199enum contactglove_debug_message_kind
200{
201 CONTACTGLOVE_DEBUG_MESSAGE_TEMPORARY_LOG = 1,
202 CONTACTGLOVE_DEBUG_MESSAGE_SIZE_UNMATCHED = 2,
203 CONTACTGLOVE_DEBUG_MESSAGE_WAITING_FOR_PAIRING = 3,
204 CONTACTGLOVE_DEBUG_MESSAGE_UNKNOWN_MODE = 5,
205 CONTACTGLOVE_DEBUG_MESSAGE_UNKNOWN_MAC_ADDRESS = 6,
206 CONTACTGLOVE_DEBUG_MESSAGE_UNKNOWN_DEVICE = 9,
207 CONTACTGLOVE_DEBUG_MESSAGE_SEND_FAILED = 10,
208 CONTACTGLOVE_DEBUG_MESSAGE_CRC = 11,
209};
210
212{
213 uint8_t message_kind; // see enum contactglove_debug_message_kind
214 uint8_t message_value;
215};
216SIZE_ASSERT(struct contactglove_to_host_packet_debug, 2);
217
218#pragma pack(pop)
Definition contactglove_protocol.h:192
Definition contactglove_protocol.h:177
Definition contactglove_protocol.h:183
uint8_t duration_minutes
How long until the glove goes into sleep mode, 255=disabled.
Definition contactglove_protocol.h:185
uint8_t duration_sec
Unused.
Definition contactglove_protocol.h:187
Definition contactglove_protocol.h:69
Definition contactglove_protocol.h:212
Definition contactglove_protocol.h:61
Definition contactglove_protocol.h:75
Definition contactglove_protocol.h:90
Definition contactglove_protocol.h:145
Definition contactglove_protocol.h:169
Definition contactglove_protocol.h:83
Definition contactglove_protocol.h:116
Definition contactglove_protocol.h:55
Endian-specific byte order defines.
Header holding common defines.