Monado OpenXR Runtime
Loading...
Searching...
No Matches
rift_driver.c File Reference

Driver for the Oculus Rift. More...

#include "os/os_time.h"
#include "xrt/xrt_defines.h"
#include "xrt/xrt_device.h"
#include "xrt/xrt_results.h"
#include "xrt/xrt_compiler.h"
#include "math/m_relation_history.h"
#include "math/m_clock_tracking.h"
#include "math/m_api.h"
#include "math/m_vec2.h"
#include "math/m_space.h"
#include "math/m_vec3.h"
#include "math/m_mathinclude.h"
#include "tracking/t_dead_reckoning.h"
#include "util/u_debug.h"
#include "util/u_device.h"
#include "util/u_distortion_mesh.h"
#include "util/u_logging.h"
#include "util/u_misc.h"
#include "util/u_time.h"
#include "util/u_var.h"
#include "util/u_visibility_mask.h"
#include "util/u_trace_marker.h"
#include "util/u_linux.h"
#include "util/u_truncate_printf.h"
#include "b_timing_source.h"
#include <stdio.h>
#include <assert.h>
#include <inttypes.h>
#include "rift_distortion.h"
#include "rift_internal.h"
#include "rift_usb.h"
#include "rift_radio.h"
Include dependency graph for rift_driver.c:

Macros

#define RIFT_BACK_STRAP_THRESHOLD_M   0.1f
 LEDs further behind the origin than this, along the device's backward (+Z) axis, are considered part of the back strap and disabled by rift_upload_back_strap_disable_pattern.
 
#define RIFT_CUSTOM_PATTERN_SEQUENCE_LENGTH   10
 
#define PARSE_MICROMETER_TRIPLET(out, values)
 

Functions

static uint32_t rift_custom_pattern_sequence_repeat (enum rift_custom_pattern_state state)
 Repeats a 2-bit LED state across all RIFT_CUSTOM_PATTERN_SEQUENCE_LENGTH phases of a custom pattern sequence.
 
static int rift_sensor_thread_tick (struct rift_hmd *hmd)
 
static void * rift_sensor_thread (void *ptr)
 
static int rift_usb_thread_radio_tick (struct rift_hmd *hmd)
 
static void * rift_radio_thread (void *ptr)
 
static int rift_read_led_model (struct rift_hmd *hmd)
 
static int rift_upload_back_strap_disable_pattern (struct rift_hmd *hmd)
 Uploads a custom pattern that holds every LED high except the back strap LEDs, which are held off, then drops the back strap LEDs from rift_hmd::led_model so the constellation tracker never tries to match blobs against LEDs that are physically dark.
 
static void get_raw_pose (struct rift_hmd *hmd, timepoint_ns when_ns, struct xrt_relation_chain *xrc)
 
static void rift_hmd_destroy (struct xrt_device *xdev)
 
static xrt_result_t rift_hmd_update_inputs (struct xrt_device *xdev)
 
static xrt_result_t rift_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 rift_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)
 
static xrt_result_t rift_hmd_get_visibility_mask (struct xrt_device *xdev, enum xrt_visibility_mask_type type, uint32_t view_index, struct xrt_visibility_mask **out_mask)
 
static void rift_hmd_constellation_tracking_source_get_tracked_pose (struct t_constellation_tracker_tracking_source *tracking_source, timepoint_ns when_ns, struct xrt_space_relation *out_relation)
 
static void rift_hmd_constellation_device_push_constellation_tracker_sample (struct t_constellation_tracker_device *connection, struct t_constellation_tracker_sample *sample)
 
static void rift_frame_node_break_apart (struct xrt_frame_node *node)
 
static void rift_frame_node_destroy (struct xrt_frame_node *node)
 
static const char * variant_name (enum rift_variant variant)
 
int rift_devices_create (struct os_hid_device *hmd_dev, struct os_hid_device *radio_dev, enum rift_variant variant, const char *serial_number, struct xrt_frame_context *xfctx, struct rift_hmd **out_hmd, struct xrt_device **out_xdevs)
 Creates Rift HMD and related devices.
 
bool rift_get_radio_id (struct rift_hmd *hmd, uint8_t out_radio_id[5])
 
bool rift_hmd_frame_timestamp_callback (void *user_data, timepoint_ns *timestamp, timepoint_ns frame_start_ns, uint32_t pts)
 Timestamps a camera frame with the time of the exposure that produced it, which is taken to be the exposure whose IN report arrived within half a frame interval of one whole frame interval before the frame's first packet.
 
int rift_add_to_constellation_tracker (struct rift_hmd *hmd, struct t_constellation_tracker *tracker)
 
struct t_timing_event_sourcerift_hmd_get_timing_event_source (struct rift_hmd *hmd)
 Gets the HMD's timing event source.
 

Detailed Description

Driver for the Oculus Rift.

Based largely on simulated_hmd.c, with reference to the DK2 firmware and OpenHMD's rift driver.

Author
Jakob Bornecrantz jakob.nosp@m.@col.nosp@m.labor.nosp@m.a.co.nosp@m.m
Rylie Pavlik rylie.nosp@m..pav.nosp@m.lik@c.nosp@m.olla.nosp@m.bora..nosp@m.com
Beyley Cardellio ep1cm.nosp@m.1n10.nosp@m.n123@.nosp@m.gmai.nosp@m.l.com

Macro Definition Documentation

◆ PARSE_MICROMETER_TRIPLET

#define PARSE_MICROMETER_TRIPLET (   out,
  values 
)
Value:
do { \
out.x = MICROMETERS_TO_METERS(values[0]); \
out.y = MICROMETERS_TO_METERS(values[1]); \
out.z = MICROMETERS_TO_METERS(values[2]); \
} while (0)

◆ RIFT_BACK_STRAP_THRESHOLD_M

#define RIFT_BACK_STRAP_THRESHOLD_M   0.1f

LEDs further behind the origin than this, along the device's backward (+Z) axis, are considered part of the back strap and disabled by rift_upload_back_strap_disable_pattern.

Function Documentation

◆ rift_custom_pattern_sequence_repeat()

static uint32_t rift_custom_pattern_sequence_repeat ( enum rift_custom_pattern_state  state)
static

Repeats a 2-bit LED state across all RIFT_CUSTOM_PATTERN_SEQUENCE_LENGTH phases of a custom pattern sequence.

Referenced by rift_upload_back_strap_disable_pattern().

◆ rift_devices_create()

int rift_devices_create ( struct os_hid_device hmd_dev,
struct os_hid_device radio_dev,
enum rift_variant  variant,
const char *  serial_number,
struct xrt_frame_context xfctx,
struct rift_hmd **  out_hmd,
struct xrt_device **  out_xdevs 
)

Creates Rift HMD and related devices.

Parameters
hmd_devThe HID device for the HMD.
radio_devThe HID device for the radio, if present (CV1 only).
variantThe Rift variant (DK2 or CV1).
serial_numberThe serial number of the device.
xfctxThe frame context to use for the timing source functions. Non-optional.
out_hmdOutput pointer for the created rift_hmd struct.
out_xdevsOutput array for the created xrt_device pointers. The array must have space for at least 4 devices (HMD, left touch, right touch, remote).
Returns
The number of devices created, or a negative value on error.

References xrt_hmd_parts::blend_modes, xrt_device::compute_distortion, xrt_device::destroy, rift_hmd::device_mutex, xrt_view::display, xrt_hmd_parts::distortion, xrt_hmd_parts::fov, xrt_device::get_tracked_pose, xrt_device::get_view_poses, xrt_device::get_visibility_mask, xrt_device::hmd, xrt_device::inputs, rift_hmd::last_remote_exposure_time_ns, m_clock_windowed_skew_tracker_alloc(), m_ff_f64_alloc(), m_ff_vec3_f32_alloc(), xrt_hmd_parts::models, xrt_device::name, xrt_hmd_parts::nominal_frame_interval_ns, os_nanosleep(), xrt_hmd_parts::preferred, t_constellation_tracker_device::push_constellation_tracker_sample, rift_hmd::radio_state, rift_upload_back_strap_disable_pattern(), xrt_view::rot, xrt_hmd_parts::screens, xrt_device::serial, xrt_device::str, xrt_device::supported, time_s_to_ns(), u_distortion_mesh_fill_in_compute(), U_LOG_CHK_ONLY_PRINT, u_truncate_snprintf(), u_var_add_root(), xrt_device::update_inputs, xrt_view::viewport, xrt_hmd_parts::views, and XRT_INPUT_GENERIC_HEAD_POSE.

◆ rift_hmd_frame_timestamp_callback()

bool rift_hmd_frame_timestamp_callback ( void *  user_data,
timepoint_ns timestamp,
timepoint_ns  frame_start_ns,
uint32_t  pts 
)

Timestamps a camera frame with the time of the exposure that produced it, which is taken to be the exposure whose IN report arrived within half a frame interval of one whole frame interval before the frame's first packet.

Parameters
user_dataThe rift_hmd whose exposures the frame is matched against.
[out]timestampWhere the exposure time is written, only touched when this returns true.
frame_start_nsWhen the frame's first payload packet arrived, in local monotonic time.
ptsThe PTS of the frame, in the camera's own clock. Only used for logging.
Returns
True when an exposure time was written. False when no exposure lines up with the frame, in which case the caller should keep whatever timestamp it already had.

References rift_hmd::exposure_history, rift_hmd::exposure_history_pushed, xrt_device::hmd, rift_exposure_event::recv_timestamp_ns, RIFT_EXPOSURE_HISTORY_SIZE, rift_exposure_event::sequence, and rift_exposure_event::timestamp_ns.

◆ rift_hmd_get_timing_event_source()

struct t_timing_event_source * rift_hmd_get_timing_event_source ( struct rift_hmd hmd)

Gets the HMD's timing event source.

Parameters
hmdThe rift_hmd to get the timing event source from.
Returns
The timing event source for the HMD, or NULL if the timing source is not initialized.

◆ rift_upload_back_strap_disable_pattern()

static int rift_upload_back_strap_disable_pattern ( struct rift_hmd hmd)
static

Uploads a custom pattern that holds every LED high except the back strap LEDs, which are held off, then drops the back strap LEDs from rift_hmd::led_model so the constellation tracker never tries to match blobs against LEDs that are physically dark.

The caller must have already set RIFT_TRACKING_CUSTOM_PATTERN on the tracking report: writes to the CustomPattern report are no-ops until that bit is set.

References t_constellation_tracker_led::id, t_constellation_tracker_led_model::led_count, t_constellation_tracker_led_model::leds, t_constellation_tracker_led::position, RIFT_BACK_STRAP_THRESHOLD_M, and rift_custom_pattern_sequence_repeat().

Referenced by rift_devices_create().