Monado OpenXR Runtime
psvr2.c File Reference

PSVR2 HMD device. More...

#include "xrt/xrt_device.h"
#include "xrt/xrt_prober.h"
#include "xrt/xrt_tracking.h"
#include "os/os_threading.h"
#include "os/os_time.h"
#include "math/m_api.h"
#include "math/m_clock_tracking.h"
#include "math/m_mathinclude.h"
#include "math/m_relation_history.h"
#include "math/m_vec3.h"
#include "math/m_space.h"
#include "tracking/t_dead_reckoning.h"
#include "util/u_misc.h"
#include "util/u_debug.h"
#include "util/u_device.h"
#include "util/u_distortion_mesh.h"
#include "util/u_frame.h"
#include "util/u_logging.h"
#include "util/u_sink.h"
#include "util/u_time.h"
#include "util/u_trace_marker.h"
#include "util/u_var.h"
#include <stdio.h>
#include <assert.h>
#include <inttypes.h>
#include <libusb.h>
#include "psvr2.h"
Include dependency graph for psvr2.c:

Data Structures

struct  psvr2_interface_info
 
struct  distortion_calibration_block
 

Macros

#define SLAM_POSE_CORRECTION   {.orientation = {.x = 0, .y = 0, .z = sqrt(2) / 2, .w = sqrt(2) / 2}}
 
#define TRANSFERS_LIST(_, hmd)
 
#define X(xfer)
 
#define X(xfer)
 

Functions

static void psvr2_usb_stop (struct psvr2_hmd *hmd)
 
static void psvr2_usb_destroy (struct psvr2_hmd *hmd)
 
static void psvr2_hmd_destroy (struct xrt_device *xdev)
 
static xrt_result_t psvr2_compute_distortion (struct xrt_device *xdev, uint32_t view, float u, float v, struct xrt_uv_triplet *result)
 
static xrt_result_t psvr2_hmd_update_inputs (struct xrt_device *xdev)
 
static void hmd_get_raw_tracker_pose (struct psvr2_hmd *hmd, timepoint_ns at_timestamp_ns, struct xrt_space_relation *out_relation)
 
static xrt_result_t psvr2_hmd_get_tracked_pose (struct xrt_device *xdev, enum xrt_input_name name, int64_t at_timestamp_ns, struct xrt_space_relation *out_relation)
 
static xrt_result_t psvr2_get_presence (struct xrt_device *xdev, bool *presence)
 
static xrt_result_t psvr2_hmd_get_view_poses (struct xrt_device *xdev, const struct xrt_vec3 *default_eye_relation, int64_t at_timestamp_ns, enum xrt_view_type view_type, uint32_t view_count, struct xrt_space_relation *out_head_relation, struct xrt_fov *out_fovs, struct xrt_pose *out_poses)
 
void process_imu_record (struct psvr2_hmd *hmd, size_t index, struct imu_usb_record *in, timepoint_ns estimated_sample_time)
 
static void process_status_report (struct psvr2_hmd *hmd, uint8_t *buf, int bytes_read, timepoint_ns received_ns)
 
bool psvr2_usb_xfer_continue (struct libusb_transfer *xfer, const char *type)
 
static void LIBUSB_CALL status_xfer_cb (struct libusb_transfer *xfer)
 
static void LIBUSB_CALL img_xfer_cb (struct libusb_transfer *xfer)
 
static void process_slam_record (struct psvr2_hmd *hmd, uint8_t *buf, int bytes_read)
 
static void LIBUSB_CALL slam_xfer_cb (struct libusb_transfer *xfer)
 
static void LIBUSB_CALL dump_xfer_cb (struct libusb_transfer *xfer)
 
static void * psvr2_usb_thread (void *ptr)
 
static bool psvr2_usb_open (struct psvr2_hmd *hmd, struct xrt_prober_device *xpdev)
 
bool get_psvr2_control (struct psvr2_hmd *hmd, uint16_t report_id, uint8_t subcmd, uint8_t *out_data, uint32_t buf_size)
 
bool send_psvr2_control (struct psvr2_hmd *hmd, uint16_t report_id, uint8_t subcmd, uint8_t *pkt_data, uint32_t pkt_len)
 
bool set_camera_mode (struct psvr2_hmd *hmd, enum psvr2_camera_mode mode)
 
static void toggle_camera_enable (struct psvr2_hmd *hmd)
 
bool set_brightness (struct psvr2_hmd *hmd, float brightness)
 
bool get_serial (struct psvr2_hmd *hmd, char serial[static(14+1)])
 
static xrt_result_t psvr2_get_brightness (struct xrt_device *xdev, float *brightness)
 
static xrt_result_t psvr2_set_brightness (struct xrt_device *xdev, float brightness, bool relative)
 
static xrt_result_t psvr2_hmd_set_output (struct xrt_device *xdev, enum xrt_output_name name, const struct xrt_output_value *value)
 
static xrt_result_t psvr2_hmd_get_compositor_info (struct xrt_device *xdev, const struct xrt_device_compositor_mode *mode, struct xrt_device_compositor_info *out_info)
 
static void cycle_camera_mode (struct psvr2_hmd *hmd)
 
static bool psvr2_usb_start (struct psvr2_hmd *hmd)
 
static void set_slam_correction (struct psvr2_hmd *hmd)
 
static void reset_slam_correction (struct psvr2_hmd *hmd)
 
static void update_brightness (struct psvr2_hmd *hmd)
 
static void psvr2_setup_distortion_and_fovs (struct psvr2_hmd *hmd)
 
struct xrt_devicepsvr2_hmd_create (struct xrt_prober_device *xpdev)
 Create the PS VR2 HMD device. More...
 

Variables

struct psvr2_interface_info interface_list []
 
static struct xrt_binding_input_pair vive_pro_inputs_psvr2 []
 
static struct xrt_binding_input_pair blubur_s1_inputs_psvr2 []
 
static struct xrt_binding_profile psvr2_binding_profiles []
 

Detailed Description

Macro Definition Documentation

◆ TRANSFERS_LIST

#define TRANSFERS_LIST (   _,
  hmd 
)
Value:
for (int i = 0; i < NUM_CAM_XFERS; i++) { \
_(hmd->camera_xfers[i]) \
} \
_(hmd->status_xfer) \
_(hmd->slam_xfer) \
_(hmd->led_detector_xfer) \
_(hmd->relocalizer_xfer) \
_(hmd->vd_xfer) \
_(hmd->gaze_xfer)

◆ X [1/2]

#define X (   xfer)
Value:
if (xfer) { \
ret = libusb_cancel_transfer(xfer); \
assert(ret == 0 || ret == LIBUSB_ERROR_NOT_FOUND); \
}

◆ X [2/2]

#define X (   xfer)
Value:
if (xfer) { \
libusb_free_transfer(xfer); \
xfer = NULL; \
}

Variable Documentation

◆ blubur_s1_inputs_psvr2

struct xrt_binding_input_pair blubur_s1_inputs_psvr2[]
static
Initial value:
= {
{XRT_INPUT_BLUBUR_S1_MENU_CLICK, XRT_INPUT_PSVR2_SYSTEM_CLICK},
}

◆ interface_list

struct psvr2_interface_info interface_list[]
Initial value:
= {
{.interface_no = 7 , .altmode = 1, .name = "status"},
{.interface_no = 3 , .altmode = 0, .name = "SLAM"},
{.interface_no = 5 , .altmode = 0, .name = "Gaze"},
{.interface_no = 6 , .altmode = 0, .name = "Camera"},
{.interface_no = 8 , .altmode = 0, .name = "LED Detector"},
{.interface_no = 9 , .altmode = 0, .name = "Relocalizer"},
{.interface_no = 10 , .altmode = 0, .name = "VD"},
}

◆ psvr2_binding_profiles

struct xrt_binding_profile psvr2_binding_profiles[]
static
Initial value:
= {
{
.name = XRT_DEVICE_VIVE_PRO,
.inputs = vive_pro_inputs_psvr2,
.input_count = ARRAY_SIZE(vive_pro_inputs_psvr2),
},
{
.name = XRT_DEVICE_BLUBUR_S1,
.inputs = blubur_s1_inputs_psvr2,
.input_count = ARRAY_SIZE(blubur_s1_inputs_psvr2),
},
}
#define ARRAY_SIZE(a)
Array size helper.
Definition: xrt_compiler.h:59

◆ vive_pro_inputs_psvr2

struct xrt_binding_input_pair vive_pro_inputs_psvr2[]
static
Initial value:
= {
{XRT_INPUT_VIVEPRO_SYSTEM_CLICK, XRT_INPUT_PSVR2_SYSTEM_CLICK},
}