Monado OpenXR Runtime
Loading...
Searching...
No Matches
contactglove_calibration.c File Reference

ContactGlove device calibration implementation. More...

#include "xrt/xrt_defines.h"
#include "util/u_file.h"
#include "contactglove_calibration.h"
#include "contactglove_internal.h"
#include <errno.h>
Include dependency graph for contactglove_calibration.c:

Macros

#define CONTACTGLOVE_CONFIG_DIR   "contactglove"
 
#define WIZARD_TRACE(wizard, ...)   U_LOG_IFL_T(wizard->log_level, __VA_ARGS__)
 
#define WIZARD_DEBUG(wizard, ...)   U_LOG_IFL_D(wizard->log_level, __VA_ARGS__)
 
#define WIZARD_INFO(wizard, ...)   U_LOG_IFL_I(wizard->log_level, __VA_ARGS__)
 
#define WIZARD_WARN(wizard, ...)   U_LOG_IFL_W(wizard->log_level, __VA_ARGS__)
 
#define WIZARD_ERROR(wizard, ...)   U_LOG_IFL_E(wizard->log_level, __VA_ARGS__)
 
#define READ_U8(out)
 
#define READ_LE16(out)
 
#define READ_LE32(out)
 
#define READ_BE32(out)
 
#define WRITE_U8(value)
 
#define WRITE_LE16(out)
 
#define WRITE_LE32(out)
 
#define WRITE_BE32(out)
 
#define ADD_CALIBRATION(calibration, prefix)
 

Functions

static void get_config_filename (char *out_name, size_t out_name_size, enum xrt_hand hand, const char *device_serial)
 
static FILE * open_config_file (struct contactglove_calibration_wizard *wizard, const char *mode)
 
static void fill_default_calib (struct contactglove_calibration *calibration)
 
static bool contactglove_calibration_load_file (struct contactglove_calibration_wizard *wizard)
 
static int fwrite_all (FILE *f, void *raw_ptr, size_t n)
 
static bool contactglove_calibration_write_file (struct contactglove_calibration_wizard *wizard)
 
static void contactglove_calibration_wizard_set_step (struct contactglove_calibration_wizard *wizard, enum contactglove_calibration_wizard_step step)
 
static void start_button_cb (void *ptr)
 
void contactglove_calibration_wizard_init (struct contactglove_calibration_wizard *wizard, struct contactglove_device *glove)
 
void contactglove_calibration_wizard_deinit (struct contactglove_calibration_wizard *wizard)
 
void contactglove_calibration_wizard_start (struct contactglove_calibration_wizard *wizard, bool calibrating_magnetra2)
 
void contactglove_calibration_wizard_push_button (struct contactglove_calibration_wizard *wizard, bool button)
 
void contactglove_calibration_wizard_push_flex_sensors (struct contactglove_calibration_wizard *wizard, const uint16_t *adc_values)
 
void contactglove_calibration_wizard_push_joystick (struct contactglove_calibration_wizard *wizard, uint8_t adc_x, uint8_t adc_y)
 
void contactglove_calibration_wizard_push_trigger (struct contactglove_calibration_wizard *wizard, uint8_t adc)
 

Detailed Description

ContactGlove device calibration implementation.

Author
Beyley Cardellio ep1cm.nosp@m.1n10.nosp@m.n123@.nosp@m.gmai.nosp@m.l.com

Macro Definition Documentation

◆ ADD_CALIBRATION

#define ADD_CALIBRATION (   calibration,
  prefix 
)
Value:
do { \
for (size_t i = 0; i < ARRAY_SIZE(calibration.flex_sensors); i++) { \
char buf[] = prefix " Flex Sensor NN NNN"; \
snprintf(buf, sizeof(buf), prefix " Flex Sensor %zu Min", i); \
u_var_add_ro_u16(wizard, &calibration.flex_sensors[i].min, buf); \
\
snprintf(buf, sizeof(buf), prefix " Flex Sensor %zu Max", i); \
u_var_add_ro_u16(wizard, &calibration.flex_sensors[i].max, buf); \
} \
\
u_var_add_ro_u8(wizard, &calibration.joystick.stick_center_x, prefix " Stick Center X"); \
u_var_add_ro_u8(wizard, &calibration.joystick.stick_center_y, prefix " Stick Center Y"); \
u_var_add_ro_u8(wizard, &calibration.joystick.range, prefix " Stick Range"); \
u_var_add_ro_f32(wizard, &calibration.joystick.forward_vector.x, prefix " Stick Forward X"); \
u_var_add_ro_f32(wizard, &calibration.joystick.forward_vector.y, prefix " Stick Forward Y"); \
u_var_add_ro_f32(wizard, &calibration.joystick.deadzone, prefix " Stick Deadzone"); \
\
u_var_add_ro_u8(wizard, &calibration.trigger.min, prefix " Trigger Min"); \
u_var_add_ro_u8(wizard, &calibration.trigger.max, prefix " Trigger Max"); \
} while (0)
#define ARRAY_SIZE(a)
Array size helper.
Definition xrt_compiler.h:59

◆ READ_BE32

#define READ_BE32 (   out)
Value:
do { \
if (ptr >= size) { \
WIZARD_ERROR(wizard, "Tried to read be32, reached end of file (len=%zu).", size); \
ret = false; \
goto load_out; \
} \
memcpy(&out, (file_contents + ptr), sizeof(__be32)); \
out = __be32_to_cpu(out); \
ptr += sizeof(__be32); \
} while (0)

◆ READ_LE16

#define READ_LE16 (   out)
Value:
do { \
if (ptr >= size) { \
WIZARD_ERROR(wizard, "Tried to read le16, reached end of file (len=%zu).", size); \
ret = false; \
goto load_out; \
} \
memcpy(&out, (file_contents + ptr), sizeof(__le16)); \
out = __le16_to_cpu(out); \
ptr += sizeof(__le16); \
} while (0)

◆ READ_LE32

#define READ_LE32 (   out)
Value:
do { \
if (ptr >= size) { \
WIZARD_ERROR(wizard, "Tried to read le32, reached end of file (len=%zu).", size); \
ret = false; \
goto load_out; \
} \
memcpy(&out, (file_contents + ptr), sizeof(__le32)); \
out = __le32_to_cpu(out); \
ptr += sizeof(__le32); \
} while (0)

◆ READ_U8

#define READ_U8 (   out)
Value:
do { \
if (ptr >= size) { \
WIZARD_ERROR(wizard, "Tried to read u8, reached end of file (len=%zu).", size); \
ret = false; \
goto load_out; \
} \
memcpy(&out, (file_contents + ptr), sizeof(uint8_t)); \
ptr += sizeof(uint8_t); \
} while (0)

◆ WRITE_BE32

#define WRITE_BE32 (   out)
Value:
do { \
__be32 real = __cpu_to_be32(out); \
int ret = fwrite_all(file, &real, sizeof(real)); \
if (ret < 0) { \
WIZARD_ERROR(wizard, "Failed to write be32 to stream, got err %s", strerror(ret)); \
ret = false; \
goto write_out; \
} \
} while (0)

◆ WRITE_LE16

#define WRITE_LE16 (   out)
Value:
do { \
__le16 real = __cpu_to_le16(out); \
int ret = fwrite_all(file, &real, sizeof(real)); \
if (ret < 0) { \
WIZARD_ERROR(wizard, "Failed to write le16 to stream, got err %s", strerror(ret)); \
ret = false; \
goto write_out; \
} \
} while (0)

◆ WRITE_LE32

#define WRITE_LE32 (   out)
Value:
do { \
__le32 real = __cpu_to_le32(out); \
int ret = fwrite_all(file, &real, sizeof(real)); \
if (ret < 0) { \
WIZARD_ERROR(wizard, "Failed to write le32 to stream, got err %s", strerror(ret)); \
ret = false; \
goto write_out; \
} \
} while (0)

◆ WRITE_U8

#define WRITE_U8 (   value)
Value:
do { \
uint8_t real = (value); \
int ret = fwrite_all(file, &real, sizeof(real)); \
if (ret < 0) { \
WIZARD_ERROR(wizard, "Failed to write u8 to stream, got err %s", strerror(ret)); \
ret = false; \
goto write_out; \
} \
} while (0)