Monado OpenXR Runtime
PS Move driver

Driver for the Sony PlayStation Move Controller. More...

Collaboration diagram for PS Move driver:

Files

file  psmv_driver.c
 PlayStation Move motion controller prober and driver code.
 
file  psmv_interface.h
 Interface to PS Move driver.
 

Data Structures

struct  psmv_set_led
 Led setting packet. More...
 
struct  psmv_f32_wire
 Wire encoding of a single 32 bit float, "little" endian. More...
 
struct  psmv_vec3_f32_wire
 Wire encoding of three 32 bit float, "little" endian. More...
 
struct  psmv_u16_wire
 Wire encoding of a single 16 bit integer, little endian. More...
 
struct  psmv_vec3_u16_wire
 Wire encoding of three 16 bit integers, little endian. More...
 
struct  psmv_i16_wire
 Wire encoding of a single 16 bit integer, little endian. More...
 
struct  psmv_vec3_i16_wire
 Wire encoding of three 16 bit integers, little endian. More...
 
struct  psmv_calibration_part
 Part of a calibration data, multiple packets make up a single data packet. More...
 
struct  psmv_calibration_zcm1
 Calibration data, multiple packets goes into this. More...
 
struct  psmv_parsed_calibration_zcm1
 Parsed calibration data from a ZCM1 device. More...
 
struct  psmv_calibration_zcm2
 Calibration data, multiple packets goes into this. More...
 
struct  psmv_parsed_calibration_zcm2
 Parsed calibration data from a ZCM2 device. More...
 
struct  psmv_input_zcm1
 Input package for ZCM1. More...
 
struct  psmv_input_zcm2
 Input package for ZCM2. More...
 
struct  psmv_parsed_sample
 A parsed sample of accel and gyro. More...
 
struct  psmv_parsed_input
 A parsed input packet. More...
 
struct  psmv_device
 A single PlayStation Move Controller. More...
 

Macros

#define PSMV_BALL_DIAMETER_M   0.045
 
#define PSMV_BALL_FROM_IMU_Y_M   0.09
 
#define PSMV_TRACE(p, ...)   U_LOG_XDEV_IFL_T(&p->base, p->log_level, __VA_ARGS__)
 
#define PSMV_DEBUG(p, ...)   U_LOG_XDEV_IFL_D(&p->base, p->log_level, __VA_ARGS__)
 
#define PSMV_ERROR(p, ...)   U_LOG_XDEV_IFL_E(&p->base, p->log_level, __VA_ARGS__)
 
#define SET_INPUT(NAME)   (psmv->base.inputs[PSMV_INDEX_##NAME].name = XRT_INPUT_PSMV_##NAME)
 

Enumerations

enum  psmv_input_index {
  PSMV_INDEX_PS_CLICK , PSMV_INDEX_MOVE_CLICK , PSMV_INDEX_START_CLICK , PSMV_INDEX_SELECT_CLICK ,
  PSMV_INDEX_SQUARE_CLICK , PSMV_INDEX_CROSS_CLICK , PSMV_INDEX_CIRCLE_CLICK , PSMV_INDEX_TRIANGLE_CLICK ,
  PSMV_INDEX_TRIGGER_VALUE , PSMV_INDEX_GRIP_POSE , PSMV_INDEX_AIM_POSE , PSMV_INDEX_BODY_CENTER_POSE ,
  PSMV_INDEX_BALL_CENTER_POSE
}
 Indices where each input is in the input list. More...
 
enum  psmv_button_bit {
  PSMV_BUTTON_BIT_MOVE_F2 = (1 << 6) , PSMV_BUTTON_BIT_TRIGGER_F2 = (1 << 7) , PSMV_BUTTON_BIT_PS = (1 << 8) , PSMV_BUTTON_BIT_MOVE_F1 = (1 << 11) ,
  PSMV_BUTTON_BIT_TRIGGER_F1 = (1 << 12) , PSMV_BUTTON_BIT_TRIANGLE = (1 << 20) , PSMV_BUTTON_BIT_CIRCLE = (1 << 21) , PSMV_BUTTON_BIT_CROSS = (1 << 22) ,
  PSMV_BUTTON_BIT_SQUARE = (1 << 23) , PSMV_BUTTON_BIT_START = (1 << 27) , PSMV_BUTTON_BIT_SELECT = (1 << 24) , PSMV_BUTTON_BIT_MOVE_ANY ,
  PSMV_BUTTON_BIT_TRIGGER_ANY
}
 Mask for the button in the button uint32_t. More...
 

Functions

static int psmv_get_calibration (struct psmv_device *psmv)
 
static int psmv_parse_input (struct psmv_device *psmv, void *data, struct psmv_parsed_input *input)
 
static struct psmv_devicepsmv_device (struct xrt_device *xdev)
 
static uint32_t psmv_calc_delta_and_handle_rollover (uint32_t next, uint32_t last)
 
static uint8_t psmv_clamp_zero_to_one_float_to_u8 (float v)
 
static void psmv_update_input_click (struct psmv_device *psmv, int index, int64_t when_ns, uint32_t bit)
 
static void psmv_update_trigger_value (struct psmv_device *psmv, int index, int64_t when_ns)
 
static int psmv_send_led_control_locked (volatile struct psmv_device *psmv, uint8_t red, uint8_t green, uint8_t blue, uint8_t rumble)
 Does the actual sending of the led control package to the device. More...
 
static void psmv_led_and_trigger_update_locked (volatile struct psmv_device *psmv, int64_t time)
 
static void psmv_led_and_trigger_update (struct psmv_device *psmv, int64_t time)
 
static void update_fusion (struct psmv_device *psmv, struct psmv_parsed_sample *sample, timepoint_ns timestamp_ns, time_duration_ns delta_ns)
 
static bool psmv_read_one_packet (struct psmv_device *psmv, uint8_t *buffer, size_t size)
 Reads one packet from the device, handles time out, locking and checking if the thread has been told to shut down. More...
 
static void * psmv_run_thread (void *ptr)
 
static void psmv_get_fusion_pose (struct psmv_device *psmv, enum xrt_input_name name, timepoint_ns when, struct xrt_space_relation *out_relation)
 
static void psmv_push_pose_offset (enum xrt_input_name name, struct xrt_relation_chain *xrc)
 
static void psmv_device_destroy (struct xrt_device *xdev)
 
static void psmv_device_update_inputs (struct xrt_device *xdev)
 
static xrt_result_t psmv_device_get_relation_chain (struct xrt_device *xdev, enum xrt_input_name name, uint64_t at_timestamp_ns, struct xrt_relation_chain *xrc)
 
static void psmv_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 float amp_scale (struct psmv_device *psmv, float amp)
 
static void psmv_device_set_output (struct xrt_device *xdev, enum xrt_output_name name, const union xrt_output_value *value)
 
int psmv_found (struct xrt_prober *xp, struct xrt_prober_device **devices, size_t device_count, size_t index, cJSON *attached_data, struct xrt_device **out_xdevs)
 Probing function for the PS Move devices. More...
 
struct xrt_devicepsmv_device_create (struct xrt_prober *xp, struct xrt_prober_device *xpdev, struct xrt_tracked_psmv *tracker)
 Function to create a PSMV device. More...
 
static void psmv_i32_from_u16_wire (int32_t *to, const struct psmv_u16_wire *from)
 
static void psmv_i32_from_i16_wire (int32_t *to, const struct psmv_i16_wire *from)
 
static void psmv_from_vec3_u16_wire (struct xrt_vec3_i32 *to, const struct psmv_vec3_u16_wire *from)
 
static void psmv_from_vec3_i16_wire (struct xrt_vec3_i32 *to, const struct psmv_vec3_i16_wire *from)
 
static void psmv_f32_from_wire (float *to, const struct psmv_f32_wire *from)
 
static void psmv_from_vec3_f32_wire (struct xrt_vec3 *to, const struct psmv_vec3_f32_wire *from)
 
static int psmv_get_calibration_zcm1 (struct psmv_device *psmv)
 
static int psmv_parse_input_zcm1 (struct psmv_device *psmv, struct psmv_input_zcm1 *data, struct psmv_parsed_input *input)
 
static int psmv_get_calibration_zcm2 (struct psmv_device *psmv)
 
static int psmv_parse_input_zcm2 (struct psmv_device *psmv, struct psmv_input_zcm2 *data, struct psmv_parsed_input *input)
 

Variables

static struct xrt_binding_input_pair simple_inputs [4]
 
static struct xrt_binding_output_pair simple_outputs [1]
 
static struct xrt_binding_profile binding_profiles [1]
 

Detailed Description

Driver for the Sony PlayStation Move Controller.

Enumeration Type Documentation

◆ psmv_button_bit

#include <drivers/psmv/psmv_driver.c>

Mask for the button in the button uint32_t.

◆ psmv_input_index

#include <drivers/psmv/psmv_driver.c>

Indices where each input is in the input list.

Function Documentation

◆ psmv_device_create()

struct xrt_device * psmv_device_create ( struct xrt_prober xp,
struct xrt_prober_device xpdev,
struct xrt_tracked_psmv tracker 
)

#include <drivers/psmv/psmv_driver.c>

Function to create a PSMV device.

See also
xrt_builder
Todo:
measure!
Todo:
cleanup to not leak

References xrt_prober::xrt_prober_open_hid_interface().

◆ psmv_found()

int psmv_found ( struct xrt_prober xp,
struct xrt_prober_device **  devices,
size_t  device_count,
size_t  index,
cJSON *  attached_data,
struct xrt_device **  out_xdevs 
)

#include <drivers/psmv/psmv_driver.c>

Probing function for the PS Move devices.

See also
xrt_prober_found_func_t

◆ psmv_get_fusion_pose()

static void psmv_get_fusion_pose ( struct psmv_device psmv,
enum xrt_input_name  name,
timepoint_ns  when,
struct xrt_space_relation out_relation 
)
static

#include <drivers/psmv/psmv_driver.c>

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.
Todo:
assuming that orientation is actually currently tracked.

References xrt_quat::math_quat_rotate_derivative().

◆ psmv_read_one_packet()

static bool psmv_read_one_packet ( struct psmv_device psmv,
uint8_t *  buffer,
size_t  size 
)
static

#include <drivers/psmv/psmv_driver.c>

Reads one packet from the device, handles time out, locking and checking if the thread has been told to shut down.

References os_hid_device::os_hid_read(), os_thread_helper::os_thread_helper_is_running_locked(), os_thread_helper::os_thread_helper_lock(), and os_thread_helper::os_thread_helper_unlock().

◆ psmv_send_led_control_locked()

static int psmv_send_led_control_locked ( volatile struct psmv_device psmv,
uint8_t  red,
uint8_t  green,
uint8_t  blue,
uint8_t  rumble 
)
static

#include <drivers/psmv/psmv_driver.c>

Does the actual sending of the led control package to the device.

References os_hid_device::os_hid_write(), and U_ZERO.

Variable Documentation

◆ binding_profiles

struct xrt_binding_profile binding_profiles[1]
static

#include <drivers/psmv/psmv_driver.c>

Initial value:
= {
{
.name = XRT_DEVICE_SIMPLE_CONTROLLER,
.inputs = simple_inputs,
.input_count = ARRAY_SIZE(simple_inputs),
.outputs = simple_outputs,
.output_count = ARRAY_SIZE(simple_outputs),
},
}
#define ARRAY_SIZE(a)
Array size helper.
Definition: xrt_compiler.h:29

◆ simple_inputs

struct xrt_binding_input_pair simple_inputs[4]
static

#include <drivers/psmv/psmv_driver.c>

Initial value:
= {
{XRT_INPUT_SIMPLE_SELECT_CLICK, XRT_INPUT_PSMV_TRIGGER_VALUE},
{XRT_INPUT_SIMPLE_MENU_CLICK, XRT_INPUT_PSMV_MOVE_CLICK},
{XRT_INPUT_SIMPLE_GRIP_POSE, XRT_INPUT_PSMV_GRIP_POSE},
{XRT_INPUT_SIMPLE_AIM_POSE, XRT_INPUT_PSMV_AIM_POSE},
}

◆ simple_outputs

struct xrt_binding_output_pair simple_outputs[1]
static

#include <drivers/psmv/psmv_driver.c>

Initial value:
= {
{XRT_OUTPUT_NAME_SIMPLE_VIBRATION, XRT_OUTPUT_NAME_PSMV_RUMBLE_VIBRATION},
}