Monado OpenXR Runtime
Loading...
Searching...
No Matches
contactglove.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_device.h>
11#include <xrt/xrt_defines.h>
12
13#include <os/os_threading.h>
14
15#include <util/u_cobs.h>
16#include <util/u_var.h>
17#include <util/u_logging.h>
18
20
23
24
25/*!
26 * A dongle for ContactGlove gloves.
27 *
28 * @implements xrt_reference
29 */
31{
32 struct xrt_reference base;
33
34 enum u_logging_level log_level;
35
36 struct os_mutex data_lock;
38
39 struct os_serial_device *dongle_serial;
40 enum contactglove_type type;
41
42 struct u_cobs_decoder cobs_decoder;
43
44 uint8_t last_sent_ping_nonce;
45 timepoint_ns last_ping_send;
46
47 struct contactglove_version version;
48 uint8_t channel;
49
50 struct contactglove_device *left_glove;
51 struct contactglove_device *right_glove;
52};
53
54enum contactglove_device_inputs
55{
56 CONTACTGLOVE_DEVICE_INPUT_HT_UNOBSTRUCTED = 0,
57 CONTACTGLOVE_DEVICE_INPUT_A_CLICK,
58 CONTACTGLOVE_DEVICE_INPUT_B_CLICK,
59 CONTACTGLOVE_DEVICE_INPUT_X_CLICK,
60 CONTACTGLOVE_DEVICE_INPUT_Y_CLICK,
61 CONTACTGLOVE_DEVICE_INPUT_SYSTEM_CLICK,
62 CONTACTGLOVE_DEVICE_INPUT_PAIRING_CLICK,
63 CONTACTGLOVE_DEVICE_INPUT_TRIGGER_VALUE,
64 CONTACTGLOVE_DEVICE_INPUT_TRIGGER_CLICK,
65 CONTACTGLOVE_DEVICE_INPUT_SQUEEZE_VALUE,
66 CONTACTGLOVE_DEVICE_INPUT_THUMBSTICK,
67 CONTACTGLOVE_DEVICE_INPUT_THUMBSTICK_CLICK,
68 CONTACTGLOVE_DEVICE_INPUT_GRIP_POSE,
69 CONTACTGLOVE_DEVICE_INPUT_AIM_POSE,
70 CONTACTGLOVE_DEVICE_INPUT_COUNT,
71};
72
73/*!
74 * A single ContactGlove glove.
75 *
76 * @implements xrt_device
77 */
79{
80 struct xrt_device base;
81
82 struct contactglove_dongle *dongle;
83
84 struct contactglove_version version;
85 struct contactglove_raw_battery_info raw_battery;
86
87 uint8_t last_received_ping_nonce;
88 timepoint_ns last_ping_receive;
89 uint16_t glove_to_dongle_ms;
90
91 //! Whether this glove is actively connected to the dongle
93
94 bool magnetra2_connected;
95
96 timepoint_ns raw_input_update_time_ns;
98
99 timepoint_ns avg_glove_to_dongle_offset_ns;
100
101 bool module_state_valid[CONTACTGLOVE_MODULE_MAX];
102 struct contactglove_module_state_magnetra2 module_state_magnetra2;
103 struct contactglove_module_state_sleep_manager module_state_sleep_manager;
104 struct contactglove_module_state_led_manager module_state_led_manager;
105
106 struct m_relation_history *relation_history;
107 struct xrt_quat latest_orientation;
108
109 uint16_t raw_flex_adc_values[CONTACTGLOVE2_SENSOR_COUNT];
110 struct u_var_u16_arr u_var_flex_adc_values;
111
112 struct u_hand_tracking_curl_values no_curl_cal;
113 struct u_hand_tracking_curl_values full_curl_cal;
114
115 struct u_var_button u_var_no_curl_cal_button;
116 struct u_var_button u_var_full_curl_cal_button;
117
118 enum xrt_hand hand;
119 enum contactglove_device_role role;
120};
121
122static struct xrt_binding_input_pair simple_inputs_magnetra2[] = {
123 {XRT_INPUT_SIMPLE_SELECT_CLICK, XRT_INPUT_MAGNETRA2_TRIGGER_VALUE},
124 {XRT_INPUT_SIMPLE_MENU_CLICK, XRT_INPUT_MAGNETRA2_B_CLICK},
125 {XRT_INPUT_SIMPLE_GRIP_POSE, XRT_INPUT_MAGNETRA2_GRIP_POSE},
126 {XRT_INPUT_SIMPLE_AIM_POSE, XRT_INPUT_MAGNETRA2_AIM_POSE},
127};
128
129static struct xrt_binding_output_pair simple_outputs_magnetra2[] = {
130 {XRT_OUTPUT_NAME_SIMPLE_VIBRATION, XRT_OUTPUT_NAME_CONTACTGLOVE2_HAPTIC},
131};
132
133static struct xrt_binding_input_pair contactglove2_inputs_magnetra2[] = {
134 {XRT_INPUT_MAGNETRA2_SQUEEZE_VALUE, XRT_INPUT_MAGNETRA2_SQUEEZE_VALUE},
135 {XRT_INPUT_MAGNETRA2_GRIP_POSE, XRT_INPUT_MAGNETRA2_GRIP_POSE},
136 {XRT_INPUT_MAGNETRA2_AIM_POSE, XRT_INPUT_MAGNETRA2_AIM_POSE},
137};
138
139static struct xrt_binding_output_pair contactglove2_outputs_magnetra2[] = {
140 {XRT_OUTPUT_NAME_CONTACTGLOVE2_HAPTIC, XRT_OUTPUT_NAME_CONTACTGLOVE2_HAPTIC},
141};
142
143static struct xrt_binding_input_pair touch_inputs_magnetra2[] = {
144 {XRT_INPUT_TOUCH_X_CLICK, XRT_INPUT_MAGNETRA2_A_CLICK},
145 {XRT_INPUT_TOUCH_X_TOUCH, XRT_INPUT_MAGNETRA2_X_CLICK},
146 {XRT_INPUT_TOUCH_Y_CLICK, XRT_INPUT_MAGNETRA2_B_CLICK},
147 {XRT_INPUT_TOUCH_Y_TOUCH, XRT_INPUT_MAGNETRA2_Y_CLICK},
148 {XRT_INPUT_TOUCH_MENU_CLICK, XRT_INPUT_MAGNETRA2_SYSTEM_CLICK}, // Map to menu
149 {XRT_INPUT_TOUCH_A_CLICK, XRT_INPUT_MAGNETRA2_A_CLICK},
150 {XRT_INPUT_TOUCH_A_TOUCH, XRT_INPUT_MAGNETRA2_X_CLICK},
151 {XRT_INPUT_TOUCH_B_CLICK, XRT_INPUT_MAGNETRA2_B_CLICK},
152 {XRT_INPUT_TOUCH_B_TOUCH, XRT_INPUT_MAGNETRA2_Y_CLICK},
153 {XRT_INPUT_TOUCH_SYSTEM_CLICK, XRT_INPUT_MAGNETRA2_SYSTEM_CLICK},
154 {XRT_INPUT_TOUCH_SQUEEZE_VALUE, XRT_INPUT_MAGNETRA2_SQUEEZE_VALUE},
155 {XRT_INPUT_TOUCH_TRIGGER_VALUE, XRT_INPUT_MAGNETRA2_TRIGGER_VALUE},
156 {XRT_INPUT_TOUCH_THUMBSTICK_CLICK, XRT_INPUT_MAGNETRA2_THUMBSTICK_CLICK},
157 // {XRT_INPUT_TOUCH_THUMBSTICK_TOUCH, }, // No good mapping.
158 {XRT_INPUT_TOUCH_THUMBSTICK, XRT_INPUT_MAGNETRA2_THUMBSTICK},
159 {XRT_INPUT_TOUCH_THUMBREST_TOUCH, XRT_INPUT_MAGNETRA2_PAIRING_CLICK}, // Best emulation
160 {XRT_INPUT_TOUCH_GRIP_POSE, XRT_INPUT_MAGNETRA2_GRIP_POSE},
161 {XRT_INPUT_TOUCH_AIM_POSE, XRT_INPUT_MAGNETRA2_AIM_POSE},
162};
163
164static struct xrt_binding_output_pair touch_outputs_magnetra2[] = {
165 {XRT_OUTPUT_NAME_TOUCH_HAPTIC, XRT_OUTPUT_NAME_CONTACTGLOVE2_HAPTIC},
166};
167
168struct xrt_binding_profile binding_profiles_magnetra2[] = {
169 {
170 .name = XRT_DEVICE_CONTACTGLOVE2,
171 .inputs = contactglove2_inputs_magnetra2,
172 .input_count = ARRAY_SIZE(contactglove2_inputs_magnetra2),
173 .outputs = contactglove2_outputs_magnetra2,
174 .output_count = ARRAY_SIZE(contactglove2_outputs_magnetra2),
175 },
176 {
177 .name = XRT_DEVICE_TOUCH_CONTROLLER,
178 .inputs = touch_inputs_magnetra2,
179 .input_count = ARRAY_SIZE(touch_inputs_magnetra2),
180 .outputs = touch_outputs_magnetra2,
181 .output_count = ARRAY_SIZE(touch_outputs_magnetra2),
182 },
183 {
184 .name = XRT_DEVICE_SIMPLE_CONTROLLER,
185 .inputs = simple_inputs_magnetra2,
186 .input_count = ARRAY_SIZE(simple_inputs_magnetra2),
187 .outputs = simple_outputs_magnetra2,
188 .output_count = ARRAY_SIZE(simple_outputs_magnetra2),
189 },
190};
Interface to drv_contactglove.
Implementation of ContactGlove device driver.
u_logging_level
Logging level enum.
Definition u_logging.h:45
int64_t timepoint_ns
Integer timestamp type.
Definition u_time.h:77
xrt_hand
Enumeration for left and right hand.
Definition xrt_defines.h:1478
Small utility for keeping track of the history of an xrt_space_relation, ie.
Wrapper around OS threading native functions.
A single ContactGlove glove.
Definition contactglove.h:79
bool connected
Whether this glove is actively connected to the dongle.
Definition contactglove.h:92
A dongle for ContactGlove gloves.
Definition contactglove.h:31
Definition contactglove_protocol.h:192
Definition contactglove_protocol.h:177
Definition contactglove_protocol.h:183
Definition contactglove_protocol.h:69
Definition contactglove_protocol.h:145
Definition contactglove_protocol.h:55
Definition m_relation_history.cpp:49
A wrapper around a native mutex.
Definition os_threading.h:69
Representing a single serial interface on a device.
Definition os_serial.h:33
All in one helper that handles locking, waiting for change and starting a thread.
Definition os_threading.h:499
Definition u_worker.c:38
A streaming COBS (Consistent Overhead Byte Stuffing) decoder with automatic error recovery.
Definition u_cobs.h:32
Values used for the XRT_HAND_TRACKING_MODEL_FINGERL_CURL model.
Definition u_hand_tracking.h:44
Simple pushable button.
Definition u_var.h:86
Definition u_var.h:42
A binding pair, going from a binding point to a device input.
Definition xrt_device.h:217
A binding pair, going from a binding point to a device output.
Definition xrt_device.h:228
A binding profile, has lists of binding pairs to goes from device in name to the device it hangs off ...
Definition xrt_device.h:240
enum xrt_device_name name
Device this binding emulates.
Definition xrt_device.h:242
A single HMD or input device.
Definition xrt_device.h:311
A quaternion with single floats.
Definition xrt_defines.h:235
A base class for reference counted objects.
Definition xrt_defines.h:99
Code to decode and encode COBS (Consistent Overhead Byte Stuffing) packet data.
Basic logging functionality.
Variable tracking code.
#define ARRAY_SIZE(a)
Array size helper.
Definition xrt_compiler.h:59
Common defines and enums for XRT.
Header defining an xrt display or controller device.