Monado OpenXR Runtime
survive_driver.c File Reference

Adapter to Libsurvive. More...

#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include "math/m_api.h"
#include "math/m_space.h"
#include "tracking/t_tracking.h"
#include "xrt/xrt_device.h"
#include "util/u_debug.h"
#include "util/u_device.h"
#include "util/u_misc.h"
#include "util/u_var.h"
#include "util/u_time.h"
#include "util/u_distortion_mesh.h"
#include "util/u_config_json.h"
#include "os/os_threading.h"
#include "os/os_time.h"
#include "xrt/xrt_prober.h"
#include "survive_interface.h"
#include "survive_api.h"
#include "util/u_json.h"
#include "util/u_hand_tracking.h"
#include "util/u_hand_simulation.h"
#include "util/u_logging.h"
#include "math/m_relation_history.h"
#include "math/m_predict.h"
#include "vive/vive_config.h"
#include "vive/vive_bindings.h"
#include "vive/vive_poses.h"
#include "util/u_trace_marker.h"
Include dependency graph for survive_driver.c:

Data Structures

struct  survive_device
 
struct  survive_system
 
struct  Button
 
struct  Axis
 

Macros

#define DEFAULT_WAIT_TIMEOUT   3.5f
 
#define SURVIVE_LEFT_CONTROLLER_INDEX   0
 
#define SURVIVE_RIGHT_CONTROLLER_INDEX   1
 
#define SURVIVE_NON_CONTROLLER_START   2
 
#define MAX_TRACKED_DEVICE_COUNT   16
 excl HMD we support 16 devices (controllers, trackers, ...) More...
 
#define SURVIVE_TRACE(d, ...)   U_LOG_XDEV_IFL_T(&d->base, d->sys->log_level, __VA_ARGS__)
 
#define SURVIVE_DEBUG(d, ...)   U_LOG_XDEV_IFL_D(&d->base, d->sys->log_level, __VA_ARGS__)
 
#define SURVIVE_INFO(d, ...)   U_LOG_XDEV_IFL_I(&d->base, d->sys->log_level, __VA_ARGS__)
 
#define SURVIVE_WARN(d, ...)   U_LOG_XDEV_IFL_W(&d->base, d->sys->log_level, __VA_ARGS__)
 
#define SURVIVE_ERROR(d, ...)   U_LOG_XDEV_IFL_E(&d->base, d->sys->log_level, __VA_ARGS__)
 
#define SET_WAND_INPUT(NAME, NAME2)
 
#define SET_INDEX_INPUT(NAME, NAME2)
 

Enumerations

enum  input_index {
  VIVE_CONTROLLER_AIM_POSE = 0 , VIVE_CONTROLLER_GRIP_POSE , VIVE_CONTROLLER_SYSTEM_CLICK , VIVE_CONTROLLER_TRIGGER_CLICK ,
  VIVE_CONTROLLER_TRIGGER_VALUE , VIVE_CONTROLLER_TRACKPAD , VIVE_CONTROLLER_TRACKPAD_TOUCH , VIVE_CONTROLLER_SQUEEZE_CLICK ,
  VIVE_CONTROLLER_MENU_CLICK , VIVE_CONTROLLER_TRACKPAD_CLICK , VIVE_CONTROLLER_THUMBSTICK , VIVE_CONTROLLER_A_CLICK ,
  VIVE_CONTROLLER_B_CLICK , VIVE_CONTROLLER_THUMBSTICK_CLICK , VIVE_CONTROLLER_THUMBSTICK_TOUCH , VIVE_CONTROLLER_SYSTEM_TOUCH ,
  VIVE_CONTROLLER_A_TOUCH , VIVE_CONTROLLER_B_TOUCH , VIVE_CONTROLLER_SQUEEZE_VALUE , VIVE_CONTROLLER_SQUEEZE_FORCE ,
  VIVE_CONTROLLER_TRIGGER_TOUCH , VIVE_CONTROLLER_TRACKPAD_FORCE , VIVE_CONTROLLER_HAND_TRACKING , VIVE_TRACKER_POSE ,
  VIVE_CONTROLLER_MAX_INDEX
}
 
enum  DeviceType { DEVICE_TYPE_HMD , DEVICE_TYPE_CONTROLLER }
 
enum  InputComponent { COMP_1D , COMP_2DX , COMP_2DY }
 

Functions

static void survive_device_destroy (struct xrt_device *xdev)
 
static double survive_timecode_now_s (void)
 
static timepoint_ns survive_timecode_to_monotonic (struct survive_device *survive, double timecode)
 
static void pose_to_relation (const SurvivePose *pose, const SurviveVelocity *vel, struct xrt_space_relation *out_relation)
 
static bool verify_device_name (struct survive_device *survive, enum xrt_input_name name)
 
static xrt_result_t survive_device_get_tracked_pose (struct xrt_device *xdev, enum xrt_input_name name, int64_t at_timestamp_ns, struct xrt_space_relation *out_relation)
 
static xrt_result_t survive_device_get_battery_status (struct xrt_device *xdev, bool *out_present, bool *out_charging, float *out_charge)
 
static int survive_controller_haptic_pulse (struct survive_device *survive, const union xrt_output_value *value)
 
static void survive_controller_device_set_output (struct xrt_device *xdev, enum xrt_output_name name, const union xrt_output_value *value)
 
static void survive_controller_get_hand_tracking (struct xrt_device *xdev, enum xrt_input_name name, int64_t at_timestamp_ns, struct xrt_hand_joint_set *out_value, int64_t *out_timestamp_ns)
 
static void survive_device_get_view_poses (struct xrt_device *xdev, const struct xrt_vec3 *default_eye_relation, int64_t at_timestamp_ns, uint32_t view_count, struct xrt_space_relation *out_head_relation, struct xrt_fov *out_fovs, struct xrt_pose *out_poses)
 
static bool update_axis (struct survive_device *survive, struct Axis *axis, const SurviveSimpleButtonEvent *e, int i, uint64_t now)
 
static bool update_button (struct survive_device *survive, const struct SurviveSimpleButtonEvent *e, timepoint_ns ts)
 
static float _calculate_squeeze_value (struct survive_device *survive)
 
static void _process_button_event (struct survive_device *survive, const struct SurviveSimpleButtonEvent *e)
 
static void _process_hmd_button_event (struct survive_device *survive, const struct SurviveSimpleButtonEvent *e)
 
static struct survive_deviceget_device_by_object (struct survive_system *sys, const SurviveSimpleObject *object)
 
static void add_device (struct survive_system *ss, const struct SurviveSimpleConfigEvent *e)
 
static void _process_pose_event (struct survive_device *survive, const struct SurviveSimplePoseUpdatedEvent *e)
 
static void _process_event (struct survive_system *ss, struct SurviveSimpleEvent *event)
 
static xrt_result_t survive_device_update_inputs (struct xrt_device *xdev)
 
static bool compute_distortion (struct xrt_device *xdev, uint32_t view, float u, float v, struct xrt_uv_triplet *result)
 
static bool _create_hmd_device (struct survive_system *sys, const struct SurviveSimpleObject *sso, char *conf_str)
 
static bool _create_controller_device (struct survive_system *sys, const SurviveSimpleObject *sso, struct vive_controller_config *config)
 
static bool add_connected_devices (struct survive_system *ss)
 
static void * run_event_thread (void *ptr)
 
int survive_get_devices (struct xrt_device **out_xdevs, struct vive_config **out_vive_config)
 

Variables

struct Button buttons [255]
 
static struct Axis axes [255]
 

Detailed Description

Macro Definition Documentation

◆ MAX_TRACKED_DEVICE_COUNT

#define MAX_TRACKED_DEVICE_COUNT   16

excl HMD we support 16 devices (controllers, trackers, ...)

◆ SET_INDEX_INPUT

#define SET_INDEX_INPUT (   NAME,
  NAME2 
)
Value:
do { \
(survive->base.inputs[VIVE_CONTROLLER_##NAME].name = XRT_INPUT_INDEX_##NAME2); \
} while (0)

◆ SET_WAND_INPUT

#define SET_WAND_INPUT (   NAME,
  NAME2 
)
Value:
do { \
(survive->base.inputs[VIVE_CONTROLLER_##NAME].name = XRT_INPUT_VIVE_##NAME2); \
} while (0)

Function Documentation

◆ _calculate_squeeze_value()

static float _calculate_squeeze_value ( struct survive_device survive)
static
Todo:
find a good formula for squeeze value

◆ _process_hmd_button_event()

static void _process_hmd_button_event ( struct survive_device survive,
const struct SurviveSimpleButtonEvent *  e 
)
static
Todo:
engagement changed

◆ add_connected_devices()

static bool add_connected_devices ( struct survive_system ss)
static
Todo:
We don't know how many device added events we will get. After 25ms Index HMD + Controllers are added here. So 250ms should be a safe value. Device added just means libsurvive knows the usb devices, the config will then be loaded asynchronously.

References os_monotonic_get_ns(), os_nanosleep(), and U_LOG_IFL_D.

◆ survive_controller_get_hand_tracking()

static void survive_controller_get_hand_tracking ( struct xrt_device xdev,
enum xrt_input_name  name,
int64_t  at_timestamp_ns,
struct xrt_hand_joint_set out_value,
int64_t *  out_timestamp_ns 
)
static
Todo:
place thumb preciely on the button that is touched/pressed

References xrt_device::name.

Variable Documentation

◆ buttons

uint8_t buttons
Initial value:
= {
[SURVIVE_BUTTON_A] = {.click = VIVE_CONTROLLER_A_CLICK, .touch = VIVE_CONTROLLER_A_TOUCH},
[SURVIVE_BUTTON_B] = {.click = VIVE_CONTROLLER_B_CLICK, .touch = VIVE_CONTROLLER_B_TOUCH},
[SURVIVE_BUTTON_TRACKPAD] = {.click = VIVE_CONTROLLER_TRACKPAD_CLICK, .touch = VIVE_CONTROLLER_TRACKPAD_TOUCH},
[SURVIVE_BUTTON_THUMBSTICK] = {.click = VIVE_CONTROLLER_THUMBSTICK_CLICK,
.touch = VIVE_CONTROLLER_THUMBSTICK_TOUCH},
[SURVIVE_BUTTON_SYSTEM] = {.click = VIVE_CONTROLLER_SYSTEM_CLICK, .touch = VIVE_CONTROLLER_SYSTEM_TOUCH},
[SURVIVE_BUTTON_MENU] = {.click = VIVE_CONTROLLER_MENU_CLICK,
.touch = 0},
[SURVIVE_BUTTON_GRIP] = {.click = VIVE_CONTROLLER_SQUEEZE_CLICK,
.touch = 0},
[SURVIVE_BUTTON_TRIGGER] = {.click = VIVE_CONTROLLER_TRIGGER_CLICK, .touch = VIVE_CONTROLLER_TRIGGER_TOUCH},
}