Monado OpenXR Runtime
vive_device.c File Reference

Vive device implementation. More...

#include <stdio.h>
#include <assert.h>
#include <math.h>
#include <zlib.h>
#include "util/u_device.h"
#include "util/u_debug.h"
#include "util/u_var.h"
#include "util/u_time.h"
#include "util/u_trace_marker.h"
#include "util/u_linux.h"
#include "math/m_api.h"
#include "math/m_predict.h"
#include "os/os_hid.h"
#include "os/os_time.h"
#include "vive.h"
#include "vive_device.h"
#include "vive_protocol.h"
#include "vive_source.h"
#include "xrt/xrt_tracking.h"
#include "xrt/xrt_config_have.h"
#include "xrt/xrt_config_build.h"
Include dependency graph for vive_device.c:

Macros

#define VIVE_IMU_RANGE_CONVERSION_VALUE   (32768.0)
 

Functions

static bool vive_mainboard_power_off (struct vive_device *d)
 
static struct vive_devicevive_device (struct xrt_device *xdev)
 
static void vive_device_destroy (struct xrt_device *xdev)
 
static xrt_result_t vive_device_update_inputs (struct xrt_device *xdev)
 
static xrt_result_t vive_device_get_3dof_tracked_pose (struct xrt_device *xdev, enum xrt_input_name name, uint64_t at_timestamp_ns, struct xrt_space_relation *out_relation)
 
static XRT_MAYBE_UNUSED struct xrt_pose vive_device_correct_pose_from_basalt (struct xrt_pose pose)
 Specific pose corrections for Basalt and a Valve Index headset. More...
 
static void vive_device_get_slam_tracked_pose (struct xrt_device *xdev, enum xrt_input_name name, uint64_t at_timestamp_ns, struct xrt_space_relation *out_relation)
 
static xrt_result_t vive_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 void vive_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 int vive_mainboard_get_device_info (struct vive_device *d)
 
static bool vive_mainboard_power_on (struct vive_device *d)
 
static void vive_mainboard_decode_message (struct vive_device *d, struct vive_mainboard_status_report *report)
 
static int oldest_sequence_index (uint8_t a, uint8_t b, uint8_t c)
 
static void convert_imu_to_openxr (struct vive_device *d, struct xrt_vec3 *gyro, struct xrt_vec3 *accel)
 
static void update_imu (struct vive_device *d, const void *buffer)
 
static void drain_imu (struct vive_device *d, const void *buffer)
 
static bool vive_mainboard_read_one_msg (struct vive_device *d)
 
static void * vive_mainboard_run_thread (void *ptr)
 
static int vive_sensors_enable_watchman (struct vive_device *d, bool enable_sensors)
 
static void _print_v1_pulse (struct vive_device *d, uint8_t sensor_id, uint32_t timestamp, uint16_t duration)
 
static void _decode_pulse_report (struct vive_device *d, const void *buffer)
 
static const char * _sensors_get_report_string (uint32_t report_id)
 
static bool _is_report_size_valid (struct vive_device *d, int size, int report_size, int report_id)
 
static bool vive_sensors_read_one_msg (struct vive_device *d, struct os_hid_device *dev, uint32_t report_id, int report_size, void(*process_cb)(struct vive_device *d, const void *buffer))
 
static void _print_v2_pulse (struct vive_device *d, uint8_t sensor_id, uint8_t flag, uint32_t timestamp, uint32_t data, uint32_t mask)
 
static bool _print_pulse_report_v2 (struct vive_device *d, const void *buffer)
 
static bool vive_sensors_read_lighthouse_msg (struct vive_device *d)
 
static void * vive_watchman_run_thread (void *ptr)
 
static void * vive_sensors_run_thread (void *ptr)
 
static void vive_device_switch_hmd_tracker (void *d_ptr)
 
static void vive_device_setup_ui (struct vive_device *d)
 
static bool compute_distortion (struct xrt_device *xdev, uint32_t view, float u, float v, struct xrt_uv_triplet *result)
 
void vive_set_trackers_status (struct vive_device *d, struct vive_tracking_status status)
 
static void precompute_sensor_transforms (struct vive_device *d)
 Precompute transforms to convert between OpenXR and device coordinate systems. More...
 
struct vive_devicevive_device_create (struct os_hid_device *mainboard_dev, struct os_hid_device *sensors_dev, struct os_hid_device *watchman_dev, enum VIVE_VARIANT variant, struct vive_tracking_status tstatus, struct vive_source *vs)
 

Detailed Description

Function Documentation

◆ precompute_sensor_transforms()

static void precompute_sensor_transforms ( struct vive_device d)
static

Precompute transforms to convert between OpenXR and device coordinate systems.

OpenXR: X: Right, Y: Up, Z: Backward Index / tracking reference / tr: X: Left, Y: Up, Z: Forward

References xrt_pose::math_pose_invert(), xrt_pose::math_pose_transform(), xrt_quat::math_quat_rotate(), vive_device::P_imu_me, and vive_config::trackref.

◆ vive_device_correct_pose_from_basalt()

static XRT_MAYBE_UNUSED struct xrt_pose vive_device_correct_pose_from_basalt ( struct xrt_pose  pose)
inlinestatic

Specific pose corrections for Basalt and a Valve Index headset.

Todo:
Test and fix for other headsets (vive/vivepro)