d/wmr: Return native driver types from create calls

Instead of returning generic xrt_device from the hmd
and controller creation functions, return wmr_hmd
and wmr_base_controller, to enable connecting them
together for controller tracking.
This commit is contained in:
Jan Schmidt committed 2026-03-25 17:50:33 +11:00
1 parent 59a65d0fd3
commit 11aa486655
11 files changed
+96 -67

No files matched your search

+2 -2
View File
@@ -146,7 +146,7 @@ wmr_bt_connection_destroy(struct wmr_controller_connection *base)
*
*/
struct xrt_device *
struct wmr_controller_base *
wmr_bt_controller_create(struct os_hid_device *controller_hid,
enum xrt_device_type controller_type,
uint16_t vid,
@@ -202,5 +202,5 @@ wmr_bt_controller_create(struct os_hid_device *controller_hid,
return NULL;
}
return xdev;
return wcb;
}
+1 -1
View File
@@ -38,7 +38,7 @@ struct wmr_bt_connection
struct os_mutex hid_lock;
};
struct xrt_device *
struct wmr_controller_base *
wmr_bt_controller_create(struct os_hid_device *controller_hid,
enum xrt_device_type controller_type,
uint16_t vid,
+3
View File
@@ -19,6 +19,9 @@
extern "C" {
#endif
/* public type structs forward declarations */
struct wmr_hmd;
struct wmr_controller_base;
/*!
* Headset type, used to select different control and init/shutdown procedures.
+10
View File
@@ -20,6 +20,7 @@
#include "util/u_logging.h"
#include "xrt/xrt_device.h"
#include "wmr_common.h"
#include "wmr_controller_protocol.h"
#include "wmr_config.h"
@@ -174,6 +175,15 @@ wmr_controller_connection_receive_bytes(struct wmr_controller_connection *wcc,
}
}
static inline struct xrt_device *
wmr_controller_base_to_xrt_device(struct wmr_controller_base *wcb)
{
if (wcb != NULL) {
return &wcb->base;
}
return NULL;
}
#ifdef __cplusplus
}
#endif
+4 -4
View File
@@ -1820,10 +1820,10 @@ wmr_hmd_create(enum wmr_headset_type hmd_type,
struct os_hid_device *hid_ctrl,
struct xrt_prober_device *dev_holo,
enum u_logging_level log_level,
struct xrt_device **out_hmd,
struct wmr_hmd **out_hmd,
struct xrt_device **out_handtracker,
struct xrt_device **out_left_controller,
struct xrt_device **out_right_controller)
struct wmr_controller_base **out_left_controller,
struct wmr_controller_base **out_right_controller)
{
DRV_TRACE_MARKER();
@@ -2042,7 +2042,7 @@ wmr_hmd_create(enum wmr_headset_type hmd_type,
wmr_hmd_setup_ui(wh);
*out_hmd = &wh->base;
*out_hmd = wh;
*out_handtracker = hand_device;
os_mutex_lock(&wh->controller_status_lock);
+12 -3
View File
@@ -188,16 +188,25 @@ wmr_hmd(struct xrt_device *p)
return (struct wmr_hmd *)p;
}
static inline struct xrt_device *
wmr_hmd_to_xrt_device(struct wmr_hmd *hmd)
{
if (hmd) {
return &hmd->base;
}
return NULL;
}
void
wmr_hmd_create(enum wmr_headset_type hmd_type,
struct os_hid_device *hid_holo,
struct os_hid_device *hid_ctrl,
struct xrt_prober_device *dev_holo,
enum u_logging_level log_level,
struct xrt_device **out_hmd,
struct wmr_hmd **out_hmd,
struct xrt_device **out_handtracker,
struct xrt_device **out_left_controller,
struct xrt_device **out_right_controller);
struct wmr_controller_base **out_left_controller,
struct wmr_controller_base **out_right_controller);
bool
wmr_hmd_send_controller_packet(struct wmr_hmd *hmd, const uint8_t *buffer, uint32_t buf_size);
+2 -6
View File
@@ -174,13 +174,9 @@ wmr_hmd_controller_create(struct wmr_hmd *hmd,
return conn;
}
struct xrt_device *
struct wmr_controller_base *
wmr_hmd_controller_connection_get_controller(struct wmr_hmd_controller_connection *wcc)
{
struct wmr_controller_base *wcb = wcc->base.wcb;
if (wcb == NULL)
return NULL;
struct xrt_device *xdev = &wcb->base;
return xdev;
return wcb;
}
+1 -1
View File
@@ -46,7 +46,7 @@ wmr_hmd_controller_create(struct wmr_hmd *hmd,
uint16_t pid,
enum u_logging_level log_level);
struct xrt_device *
struct wmr_controller_base *
wmr_hmd_controller_connection_get_controller(struct wmr_hmd_controller_connection *wcc);
#ifdef __cplusplus
+4 -5
View File
@@ -20,7 +20,6 @@
extern "C" {
#endif
/*!
* @defgroup drv_wmr Windows Mixed Reality driver
* @ingroup drv
@@ -134,9 +133,9 @@ wmr_create_headset(struct xrt_prober *xp,
struct xrt_prober_device *xpdev_companion,
enum wmr_headset_type type,
enum u_logging_level log_level,
struct xrt_device **out_hmd,
struct xrt_device **out_left,
struct xrt_device **out_right,
struct wmr_hmd **out_hmd,
struct wmr_controller_base **out_ctrl_left,
struct wmr_controller_base **out_ctrl_right,
struct xrt_device **out_ht_left,
struct xrt_device **out_ht_right);
@@ -149,7 +148,7 @@ xrt_result_t
wmr_create_bt_controller(struct xrt_prober *xp,
struct xrt_prober_device *xpdev,
enum u_logging_level log_level,
struct xrt_device **out_xdev);
struct wmr_controller_base **out_ctrl);
#ifdef __cplusplus
+12 -12
View File
@@ -341,9 +341,9 @@ wmr_create_headset(struct xrt_prober *xp,
struct xrt_prober_device *xpdev_companion,
enum wmr_headset_type type,
enum u_logging_level log_level,
struct xrt_device **out_hmd,
struct xrt_device **out_left,
struct xrt_device **out_right,
struct wmr_hmd **out_hmd,
struct wmr_controller_base **out_ctrl_left,
struct wmr_controller_base **out_ctrl_right,
struct xrt_device **out_ht_left,
struct xrt_device **out_ht_right)
{
@@ -369,10 +369,10 @@ wmr_create_headset(struct xrt_prober *xp,
goto error_holo;
}
struct xrt_device *hmd = NULL;
struct wmr_hmd *hmd = NULL;
struct xrt_device *ht = NULL;
struct xrt_device *two_hands[2] = {NULL, NULL}; // Must initialize, always returned.
struct xrt_device *hmd_left_ctrl = NULL, *hmd_right_ctrl = NULL;
struct wmr_controller_base *hmd_left_ctrl = NULL, *hmd_right_ctrl = NULL;
wmr_hmd_create(type, hid_holo, hid_companion, xpdev_holo, log_level, &hmd, &ht, &hmd_left_ctrl,
&hmd_right_ctrl);
@@ -385,13 +385,13 @@ wmr_create_headset(struct xrt_prober *xp,
#ifdef XRT_BUILD_DRIVER_HANDTRACKING
if (ht != NULL) { // Create hand-tracked controllers
cemu_devices_create(hmd, ht, two_hands);
cemu_devices_create(wmr_hmd_to_xrt_device(hmd), ht, two_hands);
}
#endif
*out_hmd = hmd;
*out_left = hmd_left_ctrl;
*out_right = hmd_right_ctrl;
*out_ctrl_left = hmd_left_ctrl;
*out_ctrl_right = hmd_right_ctrl;
*out_ht_left = two_hands[0];
*out_ht_right = two_hands[1];
@@ -408,7 +408,7 @@ xrt_result_t
wmr_create_bt_controller(struct xrt_prober *xp,
struct xrt_prober_device *xpdev,
enum u_logging_level log_level,
struct xrt_device **out_xdev)
struct wmr_controller_base **out_ctrl)
{
DRV_TRACE_MARKER();
@@ -459,14 +459,14 @@ wmr_create_bt_controller(struct xrt_prober *xp,
}
// Takes ownership of the hid_controller, even on failure
struct xrt_device *xdev =
struct wmr_controller_base *ctrl =
wmr_bt_controller_create(hid_controller, controller_type, xpdev->vendor_id, xpdev->product_id, log_level);
if (xdev == NULL) {
if (ctrl == NULL) {
U_LOG_IFL_E(log_level, "Failed to create WMR controller (Bluetooth)");
return XRT_ERROR_DEVICE_CREATION_FAILED;
}
*out_xdev = xdev;
*out_ctrl = ctrl;
return XRT_SUCCESS;
}
+45 -33
View File
@@ -23,6 +23,8 @@
#include "wmr/wmr_common.h"
#include "wmr/wmr_interface.h"
#include "wmr/wmr_controller_base.h"
#include "wmr/wmr_hmd.h"
#include <assert.h>
@@ -104,7 +106,7 @@ wmr_estimate_system(struct xrt_builder *xb,
struct xrt_builder_estimate *out_estimate)
{
enum u_logging_level log_level = debug_get_log_option_wmr_log();
struct wmr_bt_controllers_search_results ctrls = {0};
struct wmr_bt_controllers_search_results bt_ctrls = {0};
struct wmr_headset_search_results whsr = {0};
struct xrt_builder_estimate estimate = {0};
struct xrt_prober_device **xpdevs = NULL;
@@ -128,15 +130,15 @@ wmr_estimate_system(struct xrt_builder *xb,
wmr_find_headset(xp, xpdevs, xpdev_count, log_level, &whsr);
wmr_find_bt_controller_pair(xp, xpdevs, xpdev_count, log_level, &ctrls);
wmr_find_bt_controller_pair(xp, xpdevs, xpdev_count, log_level, &bt_ctrls);
if (log_level >= U_LOGGING_DEBUG) {
struct u_pp_sink_stack_only sink;
u_pp_delegate_t dg = u_pp_sink_stack_only_init(&sink);
u_pp(dg, "Found:");
print_hmd(dg, "head", whsr.type, whsr.xpdev_holo, whsr.xpdev_companion);
print_ctrl(dg, "left", ctrls.left);
print_ctrl(dg, "right", ctrls.right);
print_ctrl(dg, "left", bt_ctrls.left);
print_ctrl(dg, "right", bt_ctrls.right);
U_LOG_IFL_D(log_level, "%s", sink.buffer);
}
@@ -163,11 +165,11 @@ wmr_estimate_system(struct xrt_builder *xb,
}
}
if (ctrls.left != NULL) {
if (bt_ctrls.left != NULL) {
estimate.certain.left = true;
}
if (ctrls.right != NULL) {
if (bt_ctrls.right != NULL) {
estimate.certain.right = true;
}
@@ -186,13 +188,17 @@ wmr_open_system_impl(struct xrt_builder *xb,
struct u_builder_roles_helper *ubrh)
{
enum u_logging_level log_level = debug_get_log_option_wmr_log();
struct wmr_bt_controllers_search_results ctrls = {0};
struct wmr_bt_controllers_search_results bt_ctrls = {0};
struct wmr_headset_search_results whsr = {0};
struct xrt_prober_device **xpdevs = NULL;
size_t xpdev_count = 0;
xrt_result_t xret_unlock = XRT_SUCCESS;
xrt_result_t xret = XRT_SUCCESS;
struct wmr_hmd *head = NULL;
struct wmr_controller_base *ctrl_left = NULL;
struct wmr_controller_base *ctrl_right = NULL;
/*
* Pre device looking stuff.
*/
@@ -210,7 +216,7 @@ wmr_open_system_impl(struct xrt_builder *xb,
wmr_find_headset(xp, xpdevs, xpdev_count, log_level, &whsr);
wmr_find_bt_controller_pair(xp, xpdevs, xpdev_count, log_level, &ctrls);
wmr_find_bt_controller_pair(xp, xpdevs, xpdev_count, log_level, &bt_ctrls);
/*
@@ -230,9 +236,6 @@ wmr_open_system_impl(struct xrt_builder *xb,
* Creation.
*/
struct xrt_device *head = NULL;
struct xrt_device *left = NULL;
struct xrt_device *right = NULL;
struct xrt_device *ht_left = NULL;
struct xrt_device *ht_right = NULL;
@@ -243,23 +246,23 @@ wmr_open_system_impl(struct xrt_builder *xb,
whsr.type, //
log_level, //
&head, //
&left, //
&right, //
&ctrl_left, //
&ctrl_right, //
&ht_left, //
&ht_right); //
if (xret != XRT_SUCCESS) {
goto error;
}
if (left == NULL && ctrls.left != NULL) {
xret = wmr_create_bt_controller(xp, ctrls.left, log_level, &left);
if (ctrl_left == NULL && bt_ctrls.left != NULL) {
xret = wmr_create_bt_controller(xp, bt_ctrls.left, log_level, &ctrl_left);
if (xret != XRT_SUCCESS) {
goto error;
}
}
if (right == NULL && ctrls.right != NULL) {
xret = wmr_create_bt_controller(xp, ctrls.right, log_level, &right);
if (ctrl_right == NULL && bt_ctrls.right != NULL) {
xret = wmr_create_bt_controller(xp, bt_ctrls.right, log_level, &ctrl_right);
if (xret != XRT_SUCCESS) {
goto error;
}
@@ -274,12 +277,16 @@ wmr_open_system_impl(struct xrt_builder *xb,
assert(xret_unlock == XRT_SUCCESS);
(void)xret_unlock;
xsysd->xdevs[xsysd->xdev_count++] = head;
if (left != NULL) {
xsysd->xdevs[xsysd->xdev_count++] = left;
struct xrt_device *head_xdev = wmr_hmd_to_xrt_device(head);
struct xrt_device *left_xdev = wmr_controller_base_to_xrt_device(ctrl_left);
struct xrt_device *right_xdev = wmr_controller_base_to_xrt_device(ctrl_right);
xsysd->xdevs[xsysd->xdev_count++] = head_xdev;
if (left_xdev != NULL) {
xsysd->xdevs[xsysd->xdev_count++] = left_xdev;
}
if (right != NULL) {
xsysd->xdevs[xsysd->xdev_count++] = right;
if (right_xdev != NULL) {
xsysd->xdevs[xsysd->xdev_count++] = right_xdev;
}
if (ht_left != NULL) {
xsysd->xdevs[xsysd->xdev_count++] = ht_left;
@@ -289,27 +296,32 @@ wmr_open_system_impl(struct xrt_builder *xb,
}
// Use hand tracking if no controllers.
if (left == NULL) {
left = ht_left;
if (left_xdev == NULL) {
left_xdev = ht_left;
}
if (right == NULL) {
right = ht_right;
if (right_xdev == NULL) {
right_xdev = ht_right;
}
// Assign to role(s).
ubrh->head = head;
ubrh->left = left;
ubrh->right = right;
ubrh->head = head_xdev;
ubrh->left = left_xdev;
ubrh->right = right_xdev;
ubrh->hand_tracking.unobstructed.left = ht_left;
ubrh->hand_tracking.unobstructed.right = ht_right;
return XRT_SUCCESS;
error:
xrt_device_destroy(&head);
xrt_device_destroy(&left);
xrt_device_destroy(&right);
error : {
struct xrt_device *head_xdev = wmr_hmd_to_xrt_device(head);
struct xrt_device *left_xdev = wmr_controller_base_to_xrt_device(ctrl_left);
struct xrt_device *right_xdev = wmr_controller_base_to_xrt_device(ctrl_right);
xrt_device_destroy(&head_xdev);
xrt_device_destroy(&left_xdev);
xrt_device_destroy(&right_xdev);
}
xret_unlock = xrt_prober_unlock_list(xp, &xpdevs);
assert(xret_unlock == XRT_SUCCESS);