2019-05-07 12:47:18 +00:00
|
|
|
// Copyright 2019, Collabora, Ltd.
|
|
|
|
// SPDX-License-Identifier: BSL-1.0
|
|
|
|
/*!
|
|
|
|
* @file
|
|
|
|
* @brief Various helpers for accessing @ref xrt_device.
|
|
|
|
* @author Jakob Bornecrantz <jakob@collabora.com>
|
|
|
|
* @ingroup oxr_main
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "math/m_api.h"
|
2019-06-18 19:03:42 +00:00
|
|
|
#include "util/u_misc.h"
|
|
|
|
|
2019-05-07 12:47:18 +00:00
|
|
|
#include "oxr_objects.h"
|
|
|
|
|
|
|
|
|
2019-07-24 16:15:15 +00:00
|
|
|
void
|
|
|
|
oxr_xdev_destroy(struct xrt_device **xdev_ptr)
|
|
|
|
{
|
|
|
|
struct xrt_device *xdev = *xdev_ptr;
|
|
|
|
|
|
|
|
if (xdev == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
xdev->destroy(xdev);
|
|
|
|
*xdev_ptr = NULL;
|
|
|
|
}
|
|
|
|
|
2019-05-07 12:47:18 +00:00
|
|
|
void
|
2019-06-18 17:04:05 +00:00
|
|
|
oxr_xdev_update(struct xrt_device *xdev, struct time_state *timekeeping)
|
2019-05-07 12:47:18 +00:00
|
|
|
{
|
|
|
|
if (xdev != NULL) {
|
|
|
|
xdev->update_inputs(xdev, timekeeping);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-21 23:39:20 +00:00
|
|
|
bool
|
2019-05-07 12:47:18 +00:00
|
|
|
oxr_xdev_find_input(struct xrt_device *xdev,
|
|
|
|
enum xrt_input_name name,
|
|
|
|
struct xrt_input **out_input)
|
|
|
|
{
|
|
|
|
*out_input = NULL;
|
|
|
|
if (xdev == NULL) {
|
2019-06-21 23:39:20 +00:00
|
|
|
return false;
|
2019-05-07 12:47:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < xdev->num_inputs; i++) {
|
|
|
|
if (xdev->inputs[i].name != name) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
*out_input = &xdev->inputs[i];
|
2019-06-21 23:39:20 +00:00
|
|
|
return true;
|
2019-05-07 12:47:18 +00:00
|
|
|
}
|
2019-06-21 23:39:20 +00:00
|
|
|
return false;
|
2019-05-07 12:47:18 +00:00
|
|
|
}
|
|
|
|
|
2019-08-16 15:52:15 +00:00
|
|
|
bool
|
2019-05-07 12:47:18 +00:00
|
|
|
oxr_xdev_find_output(struct xrt_device *xdev,
|
|
|
|
enum xrt_output_name name,
|
|
|
|
struct xrt_output **out_output)
|
|
|
|
{
|
|
|
|
if (xdev == NULL) {
|
2019-08-16 15:52:15 +00:00
|
|
|
return false;
|
2019-05-07 12:47:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < xdev->num_outputs; i++) {
|
|
|
|
if (xdev->outputs[i].name != name) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
*out_output = &xdev->outputs[i];
|
2019-08-16 15:52:15 +00:00
|
|
|
return true;
|
2019-05-07 12:47:18 +00:00
|
|
|
}
|
2019-08-16 15:52:15 +00:00
|
|
|
return false;
|
2019-05-07 12:47:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
oxr_xdev_get_pose_at(struct oxr_logger *log,
|
|
|
|
struct oxr_instance *inst,
|
|
|
|
struct xrt_device *xdev,
|
|
|
|
enum xrt_input_name name,
|
|
|
|
struct xrt_pose *pose,
|
|
|
|
int64_t *timestamp)
|
|
|
|
{
|
2019-06-24 18:06:45 +00:00
|
|
|
struct xrt_pose *offset = &xdev->tracking_origin->offset;
|
2019-05-07 12:47:18 +00:00
|
|
|
|
2019-06-18 19:03:42 +00:00
|
|
|
struct xrt_space_relation relation;
|
|
|
|
U_ZERO(&relation);
|
2019-05-07 12:47:18 +00:00
|
|
|
xdev->get_tracked_pose(xdev, name, inst->timekeeping, timestamp,
|
|
|
|
&relation);
|
|
|
|
|
|
|
|
// Add in the offset from the tracking system.
|
|
|
|
math_relation_accumulate_transform(offset, &relation);
|
|
|
|
|
|
|
|
// clang-format off
|
|
|
|
bool valid_pos = (relation.relation_flags & XRT_SPACE_RELATION_POSITION_VALID_BIT) != 0;
|
|
|
|
bool valid_ori = (relation.relation_flags & XRT_SPACE_RELATION_ORIENTATION_VALID_BIT) != 0;
|
|
|
|
// clang-format on
|
|
|
|
|
|
|
|
if (valid_ori) {
|
|
|
|
pose->orientation = relation.pose.orientation;
|
|
|
|
} else {
|
|
|
|
// If the orientation is not valid just use the offset.
|
|
|
|
pose->orientation = offset->orientation;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (valid_pos) {
|
|
|
|
pose->position = relation.pose.position;
|
|
|
|
} else {
|
|
|
|
// If the position is not valid just use the offset.
|
|
|
|
pose->position = offset->position;
|
|
|
|
}
|
|
|
|
}
|