Monado OpenXR Runtime
rift_s_controller.c File Reference

Oculus Rift S Touch Controller driver. More...

#include <string.h>
#include <stdio.h>
#include <assert.h>
#include "math/m_api.h"
#include "math/m_space.h"
#include "math/m_vec3.h"
#include "os/os_hid.h"
#include "util/u_device.h"
#include "util/u_trace_marker.h"
#include "util/u_var.h"
#include "rift_s.h"
#include "rift_s_hmd.h"
#include "rift_s_radio.h"
#include "rift_s_protocol.h"
#include "rift_s_controller.h"
Include dependency graph for rift_s_controller.c:

Macros

#define DUMP_CONTROLLER_STATE   0
 
#define DEG_TO_RAD(D)   ((D)*M_PI / 180.)
 
#define SET_TOUCH_INPUT(d, NAME)   ((d)->base.inputs[OCULUS_TOUCH_##NAME].name = XRT_INPUT_TOUCH_##NAME)
 
#define DEBUG_TOUCH_INPUT_BOOL(d, NAME, label)    u_var_add_bool((d), &(d)->base.inputs[OCULUS_TOUCH_##NAME].value.boolean, label)
 
#define DEBUG_TOUCH_INPUT_F32(d, NAME, label)    u_var_add_f32((d), &(d)->base.inputs[OCULUS_TOUCH_##NAME].value.vec1.x, label)
 
#define DEBUG_TOUCH_INPUT_VEC2(d, NAME, label1, label2)
 
#define READ_LE16(b)   (b)[0] | ((b)[1]) << 8
 
#define READ_LE32(b)   (b)[0] | ((b)[1]) << 8 | ((b)[2]) << 16 | ((b)[3]) << 24
 
#define READ_LEFLOAT32(b)   (*(float *)(b));
 

Enumerations

enum  touch_controller_input_index {
  OCULUS_TOUCH_X_CLICK = 0 , OCULUS_TOUCH_X_TOUCH , OCULUS_TOUCH_Y_CLICK , OCULUS_TOUCH_Y_TOUCH ,
  OCULUS_TOUCH_MENU_CLICK , OCULUS_TOUCH_A_CLICK = 0 , OCULUS_TOUCH_A_TOUCH , OCULUS_TOUCH_B_CLICK ,
  OCULUS_TOUCH_B_TOUCH , OCULUS_TOUCH_SYSTEM_CLICK , OCULUS_TOUCH_SQUEEZE_VALUE , OCULUS_TOUCH_TRIGGER_TOUCH ,
  OCULUS_TOUCH_TRIGGER_VALUE , OCULUS_TOUCH_THUMBSTICK_CLICK , OCULUS_TOUCH_THUMBSTICK_TOUCH , OCULUS_TOUCH_THUMBSTICK ,
  OCULUS_TOUCH_THUMBREST_TOUCH , OCULUS_TOUCH_GRIP_POSE , OCULUS_TOUCH_AIM_POSE , INPUT_INDICES_LAST
}
 

Functions

static void handle_imu_update (struct rift_s_controller *ctrl, timepoint_ns local_ts, uint32_t imu_timestamp, const int16_t raw_accel[3], const int16_t raw_gyro[3])
 
bool rift_s_controller_handle_report (struct rift_s_controller *ctrl, timepoint_ns local_ts, rift_s_controller_report_t *report)
 
static void ctrl_config_cb (bool success, uint8_t *response_bytes, int response_bytes_len, struct rift_s_controller *ctrl)
 
static void ctrl_json_cb (bool success, uint8_t *response_bytes, int response_bytes_len, struct rift_s_controller *ctrl)
 
static void rift_s_update_input_bool (struct rift_s_controller *ctrl, int index, int64_t when_ns, int val)
 
static void rift_s_update_input_analog (struct rift_s_controller *ctrl, int index, int64_t when_ns, float val)
 
static void rift_s_update_input_vec2 (struct rift_s_controller *ctrl, int index, int64_t when_ns, float x, float y)
 
static xrt_result_t rift_s_controller_update_inputs (struct xrt_device *xdev)
 
static void rift_s_controller_set_output (struct xrt_device *xdev, enum xrt_output_name name, const union xrt_output_value *value)
 
static void rift_s_controller_get_fusion_pose (struct rift_s_controller *ctrl, enum xrt_input_name name, int64_t at_timestamp_ns, struct xrt_space_relation *out_relation)
 
static xrt_result_t rift_s_controller_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 rift_s_controller_destroy (struct xrt_device *xdev)
 
struct rift_s_controllerrift_s_controller_create (struct rift_s_system *sys, enum xrt_device_type device_type)
 
void rift_s_controller_update_configuration (struct rift_s_controller *ctrl, uint64_t device_id)
 

Variables

static struct xrt_binding_input_pair simple_inputs_rift_s [4]
 
static struct xrt_binding_output_pair simple_outputs_rift_s [1]
 
static struct xrt_binding_profile binding_profiles_rift_s [1]
 

Detailed Description

Oculus Rift S Touch Controller driver.

Handles communication and calibration information for the Touch Controllers

Ported from OpenHMD

Author
Jan Schmidt jan@c.nosp@m.entr.nosp@m.icula.nosp@m.r.co.nosp@m.m

Macro Definition Documentation

◆ DEBUG_TOUCH_INPUT_VEC2

#define DEBUG_TOUCH_INPUT_VEC2 (   d,
  NAME,
  label1,
  label2 
)
Value:
u_var_add_f32((d), &(d)->base.inputs[OCULUS_TOUCH_##NAME].value.vec2.x, label1); \
u_var_add_f32((d), &(d)->base.inputs[OCULUS_TOUCH_##NAME].value.vec2.y, label2)

Function Documentation

◆ rift_s_controller_get_fusion_pose()

static void rift_s_controller_get_fusion_pose ( struct rift_s_controller ctrl,
enum xrt_input_name  name,
int64_t  at_timestamp_ns,
struct xrt_space_relation out_relation 
)
static
Todo:
This is hack, fusion reports angvel relative to the device but it needs to be in relation to the base space. Rotating it with the device orientation is enough to get it into the right space, angular velocity is a derivative so needs a special rotation.

References m_imu_3dof::gyro, and xrt_quat::math_quat_rotate_derivative().

Variable Documentation

◆ binding_profiles_rift_s

struct xrt_binding_profile binding_profiles_rift_s[1]
static
Initial value:
= {
{
.name = XRT_DEVICE_SIMPLE_CONTROLLER,
.inputs = simple_inputs_rift_s,
.input_count = ARRAY_SIZE(simple_inputs_rift_s),
.outputs = simple_outputs_rift_s,
.output_count = ARRAY_SIZE(simple_outputs_rift_s),
},
}
#define ARRAY_SIZE(a)
Array size helper.
Definition: xrt_compiler.h:30

◆ simple_inputs_rift_s

struct xrt_binding_input_pair simple_inputs_rift_s[4]
static
Initial value:
= {
{XRT_INPUT_SIMPLE_SELECT_CLICK, XRT_INPUT_TOUCH_TRIGGER_VALUE},
{XRT_INPUT_SIMPLE_MENU_CLICK, XRT_INPUT_TOUCH_MENU_CLICK},
{XRT_INPUT_SIMPLE_GRIP_POSE, XRT_INPUT_TOUCH_GRIP_POSE},
{XRT_INPUT_SIMPLE_AIM_POSE, XRT_INPUT_TOUCH_AIM_POSE},
}

◆ simple_outputs_rift_s

struct xrt_binding_output_pair simple_outputs_rift_s[1]
static
Initial value:
= {
{XRT_OUTPUT_NAME_SIMPLE_VIBRATION, XRT_OUTPUT_NAME_TOUCH_HAPTIC},
}