Monado OpenXR Runtime
psvr_device.c File Reference

PSVR device implementation, imported from OpenHMD. More...

#include "xrt/xrt_compiler.h"
#include "xrt/xrt_tracking.h"
#include "os/os_time.h"
#include "os/os_threading.h"
#include "math/m_api.h"
#include "util/u_var.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 "util/u_distortion_mesh.h"
#include "math/m_imu_3dof.h"
#include "math/m_mathinclude.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "psvr_device.h"
Include dependency graph for psvr_device.c:

Data Structures

struct  psvr_device
 Private struct for the PSVR driver device. More...
 

Macros

#define PSVR_DEBUG(p, ...)   U_LOG_XDEV_IFL_D(&p->base, p->log_level, __VA_ARGS__)
 
#define PSVR_ERROR(p, ...)   U_LOG_XDEV_IFL_E(&p->base, p->log_level, __VA_ARGS__)
 
#define FEATURE_BUFFER_SIZE   256
 
#define PSVR_LED_POWER_OFF   ((uint8_t)0x00)
 
#define PSVR_LED_POWER_MAX   ((uint8_t)0xff)
 
#define PSVR_LED_POWER_WIRE_OFF   ((uint8_t)0)
 
#define PSVR_LED_POWER_WIRE_MAX   ((uint8_t)100)
 

Enumerations

enum  psvr_leds {
  PSVR_LED_A = (1 << 0) , PSVR_LED_B = (1 << 1) , PSVR_LED_C = (1 << 2) , PSVR_LED_D = (1 << 3) ,
  PSVR_LED_E = (1 << 4) , PSVR_LED_F = (1 << 5) , PSVR_LED_G = (1 << 6) , PSVR_LED_H = (1 << 7) ,
  PSVR_LED_I = (1 << 8) , PSVR_LED_FRONT = PSVR_LED_A | PSVR_LED_B | PSVR_LED_C | PSVR_LED_D | PSVR_LED_E | PSVR_LED_F | PSVR_LED_G , PSVR_LED_BACK = PSVR_LED_H | PSVR_LED_I , PSVR_LED_ALL = PSVR_LED_FRONT | PSVR_LED_BACK
}
 

Functions

static struct psvr_devicepsvr_device (struct xrt_device *p)
 
static int open_hid (struct psvr_device *p, struct hid_device_info *dev_info, hid_device **out_dev)
 
static int send_to_control (struct psvr_device *psvr, const uint8_t *data, size_t size)
 
static int send_request_data (struct psvr_device *psvr, uint8_t id, uint8_t num)
 
static uint8_t scale_led_power (uint8_t power)
 
static void read_sample_and_apply_calibration (struct psvr_device *psvr, struct psvr_parsed_sample *sample, struct xrt_vec3 *out_accel, struct xrt_vec3 *out_gyro)
 
static void update_fusion_locked (struct psvr_device *psvr, struct psvr_parsed_sample *sample, uint64_t timestamp_ns)
 
static void update_fusion (struct psvr_device *psvr, struct psvr_parsed_sample *sample, uint64_t timestamp_ns)
 
static uint32_t calc_delta_and_handle_rollover (uint32_t next, uint32_t last)
 
static timepoint_ns ensure_forward_progress_timestamps (struct psvr_device *psvr, timepoint_ns timestamp_ns)
 
static void handle_tracker_sensor_msg (struct psvr_device *psvr, unsigned char *buffer, int size)
 
static void sensor_clear_queue (struct psvr_device *psvr)
 
static int sensor_read_one_packet (struct psvr_device *psvr)
 
static void * sensor_thread (void *ptr)
 
static void handle_control_status_msg (struct psvr_device *psvr, unsigned char *buffer, int size)
 
static void handle_device_name_msg (struct psvr_device *psvr, unsigned char *buffer, int size)
 
static void handle_calibration_msg (struct psvr_device *psvr, const unsigned char *buffer, size_t size)
 
static void handle_control_0x82 (struct psvr_device *psvr, unsigned char *buffer, int size)
 
static void handle_control_0xA0 (struct psvr_device *psvr, unsigned char *buffer, int size)
 
static int read_control_packets (struct psvr_device *psvr)
 
static int read_calibration_data (struct psvr_device *psvr)
 Get the device name data and calibration data, see link below for info. More...
 
static int wait_for_power (struct psvr_device *psvr, bool on)
 
static int wait_for_vr_mode (struct psvr_device *psvr, bool on)
 
static int control_power_and_wait (struct psvr_device *psvr, bool on)
 
static int control_vrmode_and_wait (struct psvr_device *psvr, bool on)
 
static int update_leds_if_changed (struct psvr_device *psvr)
 
static int control_leds (struct psvr_device *psvr, enum psvr_leds adjust, uint8_t power, enum psvr_leds off)
 Control the leds on the headset, allowing you to turn on and off different leds with a single call. More...
 
static int disco_leds (struct psvr_device *psvr)
 
static void teardown (struct psvr_device *psvr)
 
static void psvr_device_update_inputs (struct xrt_device *xdev)
 
static void psvr_device_get_tracked_pose (struct xrt_device *xdev, enum xrt_input_name name, uint64_t at_timestamp_ns, struct xrt_space_relation *out_relation)
 
static void psvr_device_destroy (struct xrt_device *xdev)
 
static bool psvr_compute_distortion (struct xrt_device *xdev, uint32_t view, float u, float v, struct xrt_uv_triplet *result)
 
struct xrt_devicepsvr_device_create_auto_prober (struct hid_device_info *sensor_hid_info, struct hid_device_info *control_hid_info, struct xrt_tracked_psvr *tracker, enum u_logging_level log_level)
 

Variables

static XRT_MAYBE_UNUSED const unsigned char psvr_tracking_on [12]
 

Detailed Description

PSVR device implementation, imported from OpenHMD.

Author
Joey Ferwerda joeyf.nosp@m.erwe.nosp@m.da@gm.nosp@m.ail..nosp@m.com
Philipp Zabel phili.nosp@m.pp.z.nosp@m.abel@.nosp@m.gmai.nosp@m.l.com
Jakob Bornecrantz jakob.nosp@m.@col.nosp@m.labor.nosp@m.a.co.nosp@m.m

Function Documentation

◆ handle_device_name_msg()

static void handle_device_name_msg ( struct psvr_device psvr,
unsigned char *  buffer,
int  size 
)
static
Todo:
Get the name here.

◆ psvr_device_get_tracked_pose()

static void psvr_device_get_tracked_pose ( struct xrt_device xdev,
enum xrt_input_name  name,
uint64_t  at_timestamp_ns,
struct xrt_space_relation out_relation 
)
static
Todo:
Move this to the tracker.

◆ read_calibration_data()

static int read_calibration_data ( struct psvr_device psvr)
static

Get the device name data and calibration data, see link below for info.

https://github.com/gusmanb/PSVRFramework/wiki/Report-0x81-Device-ID-and-Calibration

Variable Documentation

◆ psvr_tracking_on

XRT_MAYBE_UNUSED const unsigned char psvr_tracking_on[12]
static
Initial value:
= {
0x11, 0x00, 0xaa, 0x08, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
}