The open source OpenXR runtime
at main 117 lines 2.4 kB view raw
1/* 2 * Copyright 2020 Jan Schmidt 3 * SPDX-License-Identifier: BSL-1.0 4 * 5 * OpenHMD - Free and Open Source API and drivers for immersive technology. 6 */ 7 8/*! 9 * @file 10 * @brief Oculus Rift S Touch Controller interface 11 * @author Jan Schmidt <jan@centricular.com> 12 * @ingroup drv_rift_s 13 */ 14 15#ifndef RIFT_S_CONTROLLER_H 16#define RIFT_S_CONTROLLER_H 17 18#include "math/m_imu_3dof.h" 19 20#include "os/os_time.h" 21#include "xrt/xrt_device.h" 22 23#include "rift_s.h" 24 25#define MAX_LOG_SIZE 1024 26 27typedef struct 28{ 29 uint16_t accel_limit; 30 uint16_t gyro_limit; 31 uint16_t accel_hz; 32 uint16_t gyro_hz; 33 34 float accel_scale; 35 float gyro_scale; 36} rift_s_controller_config; 37 38struct rift_s_controller 39{ 40 struct xrt_device base; 41 42 struct os_mutex mutex; 43 44 struct xrt_pose pose; 45 46 /* The system this controller belongs to / receives reports from */ 47 struct rift_s_system *sys; 48 49 uint64_t device_id; 50 rift_s_device_type device_type; 51 52 /* Debug logs */ 53 /* 0x04 = new log line 54 * 0x02 = parity bit, toggles each line when receiving log chars 55 * other bits, unknown */ 56 uint8_t log_flags; 57 int log_bytes; 58 uint8_t log[MAX_LOG_SIZE]; 59 60 /* IMU tracking */ 61 bool imu_time_valid; 62 uint32_t imu_timestamp32; 63 timepoint_ns last_imu_device_time_ns; 64 timepoint_ns last_imu_local_time_ns; 65 66 uint16_t imu_unknown_varying2; 67 int16_t raw_accel[3]; 68 int16_t raw_gyro[3]; 69 70 struct xrt_vec3 accel; 71 struct xrt_vec3 gyro; 72 struct xrt_vec3 mag; 73 struct m_imu_3dof fusion; 74 75 /* Controls / buttons state */ 76 timepoint_ns last_controls_local_time_ns; 77 78 /* 0x8, 0x0c 0x0d or 0xe block */ 79 uint8_t mask08; 80 uint8_t buttons; 81 uint8_t fingers; 82 uint8_t mask0e; 83 84 uint16_t trigger; 85 uint16_t grip; 86 87 int16_t joystick_x; 88 int16_t joystick_y; 89 90 uint8_t capsense_a_x; 91 uint8_t capsense_b_y; 92 uint8_t capsense_joystick; 93 uint8_t capsense_trigger; 94 95 uint8_t extra_bytes_len; 96 uint8_t extra_bytes[48]; 97 98 bool reading_config; 99 bool have_config; 100 rift_s_controller_config config; 101 102 bool reading_calibration; 103 bool have_calibration; 104 struct rift_s_controller_imu_calibration calibration; 105}; 106 107struct rift_s_controller * 108rift_s_controller_create(struct rift_s_system *sys, enum xrt_device_type device_type); 109 110void 111rift_s_controller_update_configuration(struct rift_s_controller *ctrl, uint64_t device_id); 112bool 113rift_s_controller_handle_report(struct rift_s_controller *ctrl, 114 timepoint_ns local_ts, 115 rift_s_controller_report_t *report); 116 117#endif