2020-07-23 11:12:29 +00:00
|
|
|
// Copyright 2019-2020, Collabora, Ltd.
|
2019-05-07 12:47:18 +00:00
|
|
|
// SPDX-License-Identifier: BSL-1.0
|
|
|
|
/*!
|
|
|
|
* @file
|
|
|
|
* @brief Various helpers for accessing @ref xrt_device.
|
|
|
|
* @author Jakob Bornecrantz <jakob@collabora.com>
|
|
|
|
* @ingroup oxr_main
|
|
|
|
*/
|
|
|
|
|
2020-04-16 12:23:12 +00:00
|
|
|
#include "os/os_time.h"
|
2020-07-23 11:12:29 +00:00
|
|
|
|
2019-05-07 12:47:18 +00:00
|
|
|
#include "math/m_api.h"
|
2020-07-23 11:12:29 +00:00
|
|
|
#include "math/m_space.h"
|
|
|
|
|
2020-04-16 12:23:12 +00:00
|
|
|
#include "util/u_time.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"
|
|
|
|
|
2020-04-16 12:23:12 +00:00
|
|
|
#include <assert.h>
|
|
|
|
|
2019-05-07 12:47:18 +00:00
|
|
|
|
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
|
2020-04-16 12:23:12 +00:00
|
|
|
oxr_xdev_update(struct xrt_device *xdev)
|
2019-05-07 12:47:18 +00:00
|
|
|
{
|
|
|
|
if (xdev != NULL) {
|
2020-04-16 12:23:12 +00:00
|
|
|
xdev->update_inputs(xdev);
|
2019-05-07 12:47:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-21 23:39:20 +00:00
|
|
|
bool
|
2021-01-14 14:13:48 +00:00
|
|
|
oxr_xdev_find_input(struct xrt_device *xdev, enum xrt_input_name name, struct xrt_input **out_input)
|
2019-05-07 12:47:18 +00:00
|
|
|
{
|
|
|
|
*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
|
2021-01-14 14:13:48 +00:00
|
|
|
oxr_xdev_find_output(struct xrt_device *xdev, enum xrt_output_name name, struct xrt_output **out_output)
|
2019-05-07 12:47:18 +00:00
|
|
|
{
|
|
|
|
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
|
2020-07-23 11:12:29 +00:00
|
|
|
oxr_xdev_get_space_graph(struct oxr_logger *log,
|
2020-04-16 12:23:12 +00:00
|
|
|
struct oxr_instance *inst,
|
|
|
|
struct xrt_device *xdev,
|
|
|
|
enum xrt_input_name name,
|
|
|
|
XrTime at_time,
|
2020-07-23 11:12:29 +00:00
|
|
|
struct xrt_space_graph *xsg)
|
2019-05-07 12:47:18 +00:00
|
|
|
{
|
2020-07-23 11:12:29 +00:00
|
|
|
// Convert at_time to monotonic and give to device.
|
2021-01-14 14:13:48 +00:00
|
|
|
uint64_t at_timestamp_ns = time_state_ts_to_monotonic_ns(inst->timekeeping, at_time);
|
2019-05-07 12:47:18 +00:00
|
|
|
|
2020-07-23 11:12:29 +00:00
|
|
|
struct xrt_space_relation *rel = m_space_graph_reserve(xsg);
|
xrt: implement multi device wrappers for tracking overrides
Example config ~/.config/monado/config_v0.json
{
"active": "tracking",
"tracking": {
"version": 0,
"tracking_overrides": [
{
"target_device_serial": "LHR-E8CC625B",
"tracker_device_serial": "LHR-1D80A098",
"offset": {
"orientation": {
"x": 0,
"y": 0,
"z": 0,
"w": 1
},
"position": {
"x": 0,
"y": 0,
"z": 0
}
}
}
]
}
}
v2: Add multi device wrapper
2021-02-09 02:19:56 +00:00
|
|
|
|
2020-09-04 13:37:50 +00:00
|
|
|
xrt_device_get_tracked_pose(xdev, name, at_timestamp_ns, rel);
|
2019-05-07 12:47:18 +00:00
|
|
|
|
|
|
|
// Add in the offset from the tracking system.
|
2020-07-23 11:12:29 +00:00
|
|
|
m_space_graph_add_pose(xsg, &xdev->tracking_origin->offset);
|
2020-04-16 12:23:12 +00:00
|
|
|
}
|
|
|
|
|
2020-10-12 00:09:19 +00:00
|
|
|
void
|
|
|
|
oxr_xdev_get_hand_tracking_at(struct oxr_logger *log,
|
|
|
|
struct oxr_instance *inst,
|
|
|
|
struct xrt_device *xdev,
|
|
|
|
enum xrt_input_name name,
|
|
|
|
XrTime at_time,
|
2020-11-13 00:30:25 +00:00
|
|
|
struct xrt_hand_joint_set *out_value)
|
2020-10-12 00:09:19 +00:00
|
|
|
{
|
2021-09-30 00:05:23 +00:00
|
|
|
//! @todo Moses doesn't know what he's doing here!
|
2020-08-17 14:44:21 +00:00
|
|
|
//! Convert at_time to monotonic and give to device.
|
2021-01-14 14:13:48 +00:00
|
|
|
uint64_t at_timestamp_ns = time_state_ts_to_monotonic_ns(inst->timekeeping, at_time);
|
2020-10-12 00:09:19 +00:00
|
|
|
|
2020-11-13 00:30:25 +00:00
|
|
|
struct xrt_hand_joint_set value;
|
2020-10-12 00:09:19 +00:00
|
|
|
|
2021-09-30 00:05:23 +00:00
|
|
|
uint64_t ignored;
|
|
|
|
|
|
|
|
xrt_device_get_hand_tracking(xdev, name, at_timestamp_ns, &value, &ignored);
|
2020-10-12 00:09:19 +00:00
|
|
|
|
|
|
|
*out_value = value;
|
|
|
|
}
|
2020-04-16 12:23:12 +00:00
|
|
|
void
|
2020-07-23 11:12:29 +00:00
|
|
|
oxr_xdev_get_space_relation(struct oxr_logger *log,
|
|
|
|
struct oxr_instance *inst,
|
|
|
|
struct xrt_device *xdev,
|
|
|
|
enum xrt_input_name name,
|
|
|
|
XrTime at_time,
|
|
|
|
struct xrt_space_relation *out_relation)
|
2020-04-16 12:23:12 +00:00
|
|
|
{
|
2020-07-23 11:12:29 +00:00
|
|
|
struct xrt_space_graph xsg = {0};
|
|
|
|
oxr_xdev_get_space_graph(log, inst, xdev, name, at_time, &xsg);
|
|
|
|
m_space_graph_resolve(&xsg, out_relation);
|
2019-05-07 12:47:18 +00:00
|
|
|
}
|