Monado OpenXR Runtime
vive_controller.c File Reference

Vive Controller prober and driver code. More...

#include "xrt/xrt_defines.h"
#include "xrt/xrt_prober.h"
#include "math/m_imu_3dof.h"
#include "math/m_relation_history.h"
#include "util/u_var.h"
#include "os/os_hid.h"
#include "os/os_threading.h"
#include "os/os_time.h"
#include "math/m_api.h"
#include "math/m_space.h"
#include "math/m_predict.h"
#include "util/u_json.h"
#include "util/u_misc.h"
#include "util/u_time.h"
#include "util/u_debug.h"
#include "util/u_device.h"
#include "util/u_trace_marker.h"
#include "vive/vive_config.h"
#include "vive/vive_bindings.h"
#include "vive/vive_poses.h"
#include "vive.h"
#include "vive_protocol.h"
#include "vive_controller.h"
#include "util/u_hand_simulation.h"
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <math.h>
Include dependency graph for vive_controller.c:

Macros

#define DEFAULT_HAPTIC_FREQ   150.0f
 
#define MIN_HAPTIC_DURATION   0.05f
 
#define FEATURE_BUFFER_SIZE   256
 
#define SET_WAND_INPUT(NAME, NAME2)
 
#define SET_INDEX_INPUT(NAME, NAME2)
 

Enumerations

enum  vive_controller_input_index {
  VIVE_CONTROLLER_INDEX_AIM_POSE = 0 , VIVE_CONTROLLER_INDEX_GRIP_POSE , VIVE_CONTROLLER_INDEX_SYSTEM_CLICK , VIVE_CONTROLLER_INDEX_TRIGGER_CLICK ,
  VIVE_CONTROLLER_INDEX_TRIGGER_VALUE , VIVE_CONTROLLER_INDEX_TRACKPAD , VIVE_CONTROLLER_INDEX_TRACKPAD_TOUCH , VIVE_CONTROLLER_INDEX_SQUEEZE_CLICK ,
  VIVE_CONTROLLER_INDEX_MENU_CLICK , VIVE_CONTROLLER_INDEX_TRACKPAD_CLICK , VIVE_CONTROLLER_INDEX_THUMBSTICK , VIVE_CONTROLLER_INDEX_A_CLICK ,
  VIVE_CONTROLLER_INDEX_B_CLICK , VIVE_CONTROLLER_INDEX_THUMBSTICK_CLICK , VIVE_CONTROLLER_INDEX_THUMBSTICK_TOUCH , VIVE_CONTROLLER_INDEX_SYSTEM_TOUCH ,
  VIVE_CONTROLLER_INDEX_A_TOUCH , VIVE_CONTROLLER_INDEX_B_TOUCH , VIVE_CONTROLLER_INDEX_SQUEEZE_VALUE , VIVE_CONTROLLER_INDEX_SQUEEZE_FORCE ,
  VIVE_CONTROLLER_INDEX_TRIGGER_TOUCH , VIVE_CONTROLLER_INDEX_TRACKPAD_FORCE , VIVE_CONTROLLER_HAND_TRACKING , VIVE_CONTROLLER_MAX_INDEX
}
 

Functions

static struct vive_controller_devicevive_controller_device (struct xrt_device *xdev)
 
static void get_pose (struct vive_controller_device *d, enum xrt_input_name name, int64_t at_timestamp_ns, struct xrt_space_relation *out_relation)
 
static void vive_controller_device_destroy (struct xrt_device *xdev)
 
static xrt_result_t vive_controller_device_wand_update_inputs (struct xrt_device *xdev)
 
static xrt_result_t vive_controller_device_index_update_inputs (struct xrt_device *xdev)
 
static void vive_controller_get_hand_tracking (struct xrt_device *xdev, enum xrt_input_name name, int64_t requested_timestamp_ns, struct xrt_hand_joint_set *out_value, int64_t *out_timestamp_ns)
 
static void vive_controller_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 int vive_controller_haptic_pulse (struct vive_controller_device *d, const union xrt_output_value *value)
 
static void vive_controller_device_set_output (struct xrt_device *xdev, enum xrt_output_name name, const union xrt_output_value *value)
 
static void controller_handle_battery (struct vive_controller_device *d, struct vive_controller_battery_sample *sample)
 
static void controller_handle_buttons (struct vive_controller_device *d, struct vive_controller_button_sample *sample)
 
static void controller_handle_touch_position (struct vive_controller_device *d, struct vive_controller_touch_sample *sample)
 
static void controller_handle_analog_trigger (struct vive_controller_device *d, struct vive_controller_trigger_sample *sample)
 
static void vive_controller_handle_imu_sample (struct vive_controller_device *d, struct watchman_imu_sample *sample)
 
static void controller_handle_touch_force (struct vive_controller_device *d, struct watchman_touch_force *sample)
 
static void vive_controller_handle_lighthousev1 (struct vive_controller_device *d, uint8_t *buf, uint8_t len)
 
static void vive_controller_decode_watchmanv1 (struct vive_controller_device *d, struct vive_controller_message *message)
 
static void vive_controller_decode_watchmanv2 (struct vive_controller_device *d, struct vive_controller_message *message)
 
static void vive_controller_decode_message (struct vive_controller_device *d, struct vive_controller_message *message)
 
static int vive_controller_device_update (struct vive_controller_device *d)
 
static void * vive_controller_run_thread (void *ptr)
 
void vive_controller_reset_pose_cb (void *ptr)
 
static void vive_controller_setup_ui (struct vive_controller_device *d)
 
struct vive_controller_devicevive_controller_create (struct os_hid_device *controller_hid, enum watchman_gen watchman_gen, int controller_num)
 

Detailed Description

Vive Controller prober and driver code.

Author
Christoph Haag chris.nosp@m.toph.nosp@m..gaag.nosp@m.@col.nosp@m.labor.nosp@m.a.co.nosp@m.m
Lubosz Sarnecki lubos.nosp@m.z.sa.nosp@m.rneck.nosp@m.i@co.nosp@m.llabo.nosp@m.ra.c.nosp@m.om
Rylie Pavlik rylie.nosp@m..pav.nosp@m.lik@c.nosp@m.olla.nosp@m.bora..nosp@m.com
Jakob Bornecrantz jakob.nosp@m.@col.nosp@m.labor.nosp@m.a.co.nosp@m.m

Portions based on the VRPN Razer Hydra driver, originally written by Rylie Pavlik and available under the BSL-1.0.

Macro Definition Documentation

◆ SET_INDEX_INPUT

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

◆ SET_WAND_INPUT

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

Function Documentation

◆ get_pose()

static void get_pose ( struct vive_controller_device d,
enum xrt_input_name  name,
int64_t  at_timestamp_ns,
struct xrt_space_relation out_relation 
)
inlinestatic
Todo:
Vive poses only have index poses.

◆ vive_controller_decode_message()

static void vive_controller_decode_message ( struct vive_controller_device d,
struct vive_controller_message message 
)
static
Todo:
: Check if Vive controller on watchman2 is correctly handled with watchman2 codepath

◆ vive_controller_decode_watchmanv2()

static void vive_controller_decode_watchmanv2 ( struct vive_controller_device d,
struct vive_controller_message message 
)
static
Todo:
: Parse lighthouse v2 data

◆ vive_controller_get_hand_tracking()

static void vive_controller_get_hand_tracking ( struct xrt_device xdev,
enum xrt_input_name  name,
int64_t  requested_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