The open source OpenXR runtime
at prediction-2 131 lines 2.4 kB view raw
1// Copyright 2020, Collabora, Ltd. 2// SPDX-License-Identifier: BSL-1.0 3/*! 4 * @file 5 * @brief Interface to @ref drv_vive 6 * @author Christoph Haag <christoph.haag@collabora.com> 7 * @author Rylie Pavlik <rylie.pavlik@collabora.com> 8 * @ingroup drv_vive 9 */ 10 11#pragma once 12 13#include <stdlib.h> 14#include <stdint.h> 15 16#include "xrt/xrt_device.h" 17#include "os/os_threading.h" 18#include "math/m_imu_3dof.h" 19#include "util/u_logging.h" 20#include "util/u_hand_tracking.h" 21#include "vive/vive_config.h" 22 23 24#ifdef __cplusplus 25extern "C" { 26#endif 27/*! 28 * @ingroup drv_vive 29 * 30 * @brief Driver for the HTC Vive and Valve Index controllers. 31 */ 32 33enum watchman_gen 34{ 35 WATCHMAN_GEN1, 36 WATCHMAN_GEN2, 37 WATCHMAN_GEN_UNKNOWN 38}; 39 40/*! 41 * A Vive Controller device, representing just a single controller. 42 * 43 * @ingroup drv_vive 44 * @implements xrt_device 45 */ 46struct vive_controller_device 47{ 48 struct xrt_device base; 49 50 struct os_hid_device *controller_hid; 51 struct os_thread_helper controller_thread; 52 struct os_mutex lock; 53 54 struct 55 { 56 timepoint_ns last_sample_ts_ns; 57 uint32_t last_sample_ticks; 58 } imu; 59 60 struct 61 { 62 struct u_var_button reset_pose_btn; 63 } gui; 64 65 // struct m_imu_3dof fusion; 66 struct 67 { 68 //! Protects all members of the `fusion` substruct. 69 struct os_mutex mutex; 70 71 //! Main fusion calculator. 72 struct m_imu_3dof i3dof; 73 74 //! Prediction 75 struct m_relation_history *relation_hist; 76 } fusion; 77 78 struct 79 { 80 struct xrt_vec3 acc; 81 struct xrt_vec3 gyro; 82 } last; 83 84 enum u_logging_level log_level; 85 86 uint32_t last_ticks; 87 88 //! Which vive controller in the system are we? 89 size_t index; 90 91 struct 92 { 93 struct xrt_vec2 trackpad; 94 float trigger; 95 uint8_t buttons; 96 uint8_t last_buttons; 97 98 uint8_t touch; 99 uint8_t last_touch; 100 101 uint8_t middle_finger_handle; 102 uint8_t ring_finger_handle; 103 uint8_t pinky_finger_handle; 104 uint8_t index_finger_trigger; 105 106 uint8_t squeeze_force; 107 uint8_t trackpad_force; 108 109 bool charging; 110 uint8_t battery; 111 } state; 112 113 enum watchman_gen watchman_gen; 114 115 struct u_hand_tracking hand_tracking; 116 117 struct vive_controller_config config; 118 119 //! Last tracked pose 120 struct xrt_pose pose; 121 122 //! Additional offset to apply to `pose` 123 struct xrt_pose offset; 124}; 125 126struct vive_controller_device * 127vive_controller_create(struct os_hid_device *controller_hid, enum watchman_gen watchman_gen, int controller_num); 128 129#ifdef __cplusplus 130} 131#endif