Monado OpenXR Runtime
Loading...
Searching...
No Matches
contactglove_internal.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_device.h"
13#include "xrt/xrt_defines.h"
14
15#include "os/os_threading.h"
16
17#include "util/u_cobs.h"
18#include "util/u_var.h"
19#include "util/u_logging.h"
21
23
27
28
29/*!
30 * A dongle for ContactGlove gloves.
31 *
32 * @implements xrt_reference
33 */
35{
36 struct xrt_reference base;
37
38 enum u_logging_level log_level;
39
40 struct os_mutex data_lock;
42
43 struct os_serial_device *dongle_serial;
44 enum contactglove_type type;
45
46 struct u_cobs_decoder cobs_decoder;
47
48 uint8_t last_sent_ping_nonce;
49 timepoint_ns last_ping_send;
50
51 struct contactglove_version version;
52 uint8_t channel;
53
54 struct contactglove_device *left_glove;
55 struct contactglove_device *right_glove;
56};
57
58enum contactglove_device_inputs
59{
60 CONTACTGLOVE_DEVICE_INPUT_HT_UNOBSTRUCTED = 0,
61 CONTACTGLOVE_DEVICE_INPUT_A_CLICK,
62 CONTACTGLOVE_DEVICE_INPUT_B_CLICK,
63 CONTACTGLOVE_DEVICE_INPUT_X_CLICK,
64 CONTACTGLOVE_DEVICE_INPUT_Y_CLICK,
65 CONTACTGLOVE_DEVICE_INPUT_SYSTEM_CLICK,
66 CONTACTGLOVE_DEVICE_INPUT_PAIRING_CLICK,
67 CONTACTGLOVE_DEVICE_INPUT_TRIGGER_VALUE,
68 CONTACTGLOVE_DEVICE_INPUT_TRIGGER_CLICK,
69 CONTACTGLOVE_DEVICE_INPUT_SQUEEZE_VALUE,
70 CONTACTGLOVE_DEVICE_INPUT_THUMBSTICK,
71 CONTACTGLOVE_DEVICE_INPUT_THUMBSTICK_CLICK,
72 CONTACTGLOVE_DEVICE_INPUT_GRIP_POSE,
73 CONTACTGLOVE_DEVICE_INPUT_AIM_POSE,
74 CONTACTGLOVE_DEVICE_INPUT_COUNT,
75};
76
77/*!
78 * A single ContactGlove glove.
79 *
80 * @implements xrt_device
81 */
83{
84 struct xrt_device base;
85
86 struct contactglove_dongle *dongle;
87
88 struct contactglove_version version;
89 struct contactglove_raw_battery_info raw_battery;
90
91 uint8_t last_received_ping_nonce;
92 timepoint_ns last_ping_receive;
93 uint16_t glove_to_dongle_ms;
94
95 //! Whether this glove is actively connected to the dongle
97
98 bool magnetra2_connected;
99
100 timepoint_ns raw_input_update_time_ns;
102
103 timepoint_ns avg_glove_to_dongle_offset_ns;
104
105 bool module_state_valid[CONTACTGLOVE_MODULE_MAX];
106 struct contactglove_module_state_magnetra2 module_state_magnetra2;
107 struct contactglove_module_state_sleep_manager module_state_sleep_manager;
108 struct contactglove_module_state_led_manager module_state_led_manager;
109
110 struct m_relation_history *relation_history;
111 struct xrt_quat latest_orientation;
112
113 uint16_t raw_flex_adc_values[CONTACTGLOVE2_SENSOR_COUNT];
114 struct u_var_u16_arr u_var_flex_adc_values;
115
116 struct contactglove_calibration_wizard calibration_wizard;
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
168// @note XRT_MAYBE_UNUSED is here since it's used only in some compilation units, not all that include this file
169XRT_MAYBE_UNUSED static struct xrt_binding_profile binding_profiles_magnetra2[] = {
170 {
171 .name = XRT_DEVICE_CONTACTGLOVE2,
172 .inputs = contactglove2_inputs_magnetra2,
173 .input_count = ARRAY_SIZE(contactglove2_inputs_magnetra2),
174 .outputs = contactglove2_outputs_magnetra2,
175 .output_count = ARRAY_SIZE(contactglove2_outputs_magnetra2),
176 },
177 {
178 .name = XRT_DEVICE_TOUCH_CONTROLLER,
179 .inputs = touch_inputs_magnetra2,
180 .input_count = ARRAY_SIZE(touch_inputs_magnetra2),
181 .outputs = touch_outputs_magnetra2,
182 .output_count = ARRAY_SIZE(touch_outputs_magnetra2),
183 },
184 {
185 .name = XRT_DEVICE_SIMPLE_CONTROLLER,
186 .inputs = simple_inputs_magnetra2,
187 .input_count = ARRAY_SIZE(simple_inputs_magnetra2),
188 .outputs = simple_outputs_magnetra2,
189 .output_count = ARRAY_SIZE(simple_outputs_magnetra2),
190 },
191};
ContactGlove device calibration implementation.
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:1488
Small utility for keeping track of the history of an xrt_space_relation, ie.
Wrapper around OS threading native functions.
A type which manages the state of the currently-running calibration step.
Definition contactglove_calibration.h:226
A single ContactGlove glove.
Definition contactglove_internal.h:83
bool connected
Whether this glove is actively connected to the dongle.
Definition contactglove_internal.h:96
A dongle for ContactGlove gloves.
Definition contactglove_internal.h:35
Definition contactglove_protocol.h:198
Definition contactglove_protocol.h:183
Definition contactglove_protocol.h:189
Definition contactglove_protocol.h:75
Definition contactglove_protocol.h:151
Definition contactglove_protocol.h:61
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
Definition u_var.h:42
A binding pair, going from a binding point to a device input.
Definition xrt_device.h:239
A binding pair, going from a binding point to a device output.
Definition xrt_device.h:250
A binding profile, has lists of binding pairs to goes from device in name to the device it hangs off ...
Definition xrt_device.h:262
enum xrt_device_name name
Device this binding emulates.
Definition xrt_device.h:264
A single HMD or input device.
Definition xrt_device.h:341
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.
Hand Tracking API interface.
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.