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