32#define CONTACTGLOVE2_DEFAULT_DEADZONE 0.1f
41#define CONTACTGLOVE_CALIBRATION_MAGIC 0x15D04C50
50#define CONTACTGLOVE_CALIBRATION_CURRENT_VERSION CONTACTGLOVE_CALIBRATION_VERSION_INITIAL
106 const uint16_t *adc_values)
110 return (
CLAMP(adc_values[index], sensor_calib.
min, sensor_calib.
max) - sensor_calib.
min) /
111 (float)(sensor_calib.
max - sensor_calib.
min);
117 const uint8_t stick_x,
118 const uint8_t stick_y)
120 const int8_t from_center_x = (int8_t)(((int16_t)stick_x) - calibration.stick_center_x);
121 const int8_t from_center_y = (int8_t)(((int16_t)stick_y) - calibration.stick_center_y);
123 const struct xrt_vec2 from_center = {
124 .x = (float)from_center_x,
125 .y = (
float)from_center_y,
129 m_vec2_clamp_scalar(m_vec2_div_scalar(from_center, (
float)calibration.range), -1.0f, 1.0f);
133 .x = m_vec2_cross(raw_dir, calibration.forward_vector),
134 .y = m_vec2_dot(raw_dir, calibration.forward_vector),
138 const float raw_len = m_vec2_len(rotated);
139 const float deadzone =
CLAMP(calibration.deadzone, 0.0f, 1.0f - FLT_EPSILON);
140 if (raw_len <= deadzone) {
145 const float remapped_len =
CLAMP((raw_len - deadzone) / (1.0f - deadzone), 0.0f, 1.0f);
148 return m_vec2_mul(m_vec2_mul_scalar(rotated, remapped_len / raw_len), (
struct xrt_vec2){.x = -1, .y = 1});
157 if (calibration.
max > calibration.
min) {
158 calibration.
min += 5;
159 calibration.
max -= 5;
160 }
else if (calibration.
max <= calibration.
min) {
161 calibration.
min -= 5;
162 calibration.
max += 5;
168 float f = (
CLAMP(adc_value, calibration.
min, calibration.
max) - calibration.
min) /
169 (
float)(calibration.
max - calibration.
min);
175 f = log10f(1.0f + (9.0f * f));
186enum contactglove_calibration_wizard_step
188 CONTACTGLOVE_CALIBRATION_WIZARD_NOT_CALIBRATING,
189 CONTACTGLOVE_CALIBRATION_WIZARD_CALIBRATING_FLEX_SENSORS,
190 CONTACTGLOVE_CALIBRATION_WIZARD_CALIBRATING_JOYSTICK_CENTER,
191 CONTACTGLOVE_CALIBRATION_WIZARD_CALIBRATING_JOYSTICK_RANGE,
192 CONTACTGLOVE_CALIBRATION_WIZARD_CALIBRATING_JOYSTICK_DEADZONE,
193 CONTACTGLOVE_CALIBRATION_WIZARD_CALIBRATING_JOYSTICK_FORWARD,
194 CONTACTGLOVE_CALIBRATION_WIZARD_CALIBRATING_TRIGGER,
195 CONTACTGLOVE_CALIBRATION_WIZARD_WRITING_OUTPUT,
232 bool calibrating_magnetra2;
234 enum contactglove_calibration_wizard_step step;
266 const uint16_t *adc_values);
u_logging_level
Logging level enum.
Definition u_logging.h:45
#define CLAMP(X, A, B)
X clamped to the range [A, B].
Definition m_api.h:78
C interface to math library.
A 2 element vector with single floats.
Definition xrt_defines.h:268
#define XRT_VEC2_ZERO
All-zero value for xrt_vec2.
Definition xrt_defines.h:280
Basic logging functionality.