2019-03-18 05:52:32 +00:00
|
|
|
// Copyright 2019, Collabora, Ltd.
|
|
|
|
// SPDX-License-Identifier: BSL-1.0
|
|
|
|
/*!
|
|
|
|
* @file
|
|
|
|
* @brief OpenHMD prober code.
|
|
|
|
* @author Jakob Bornecrantz <jakob@collabora.com>
|
2019-04-12 13:08:46 +00:00
|
|
|
* @ingroup drv_ohmd
|
2019-03-18 05:52:32 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include "openhmd.h"
|
|
|
|
#include "xrt/xrt_prober.h"
|
|
|
|
|
|
|
|
#include "util/u_misc.h"
|
|
|
|
#include "util/u_debug.h"
|
|
|
|
|
2019-06-18 18:24:55 +00:00
|
|
|
#include "oh_interface.h"
|
2019-03-18 05:52:32 +00:00
|
|
|
#include "oh_device.h"
|
|
|
|
|
|
|
|
|
|
|
|
DEBUG_GET_ONCE_BOOL_OPTION(oh_spew, "OH_PRINT_SPEW", false)
|
|
|
|
DEBUG_GET_ONCE_BOOL_OPTION(oh_debug, "OH_PRINT_DEBUG", false)
|
|
|
|
|
|
|
|
struct oh_prober
|
|
|
|
{
|
2019-04-22 20:36:59 +00:00
|
|
|
struct xrt_auto_prober base;
|
2019-03-18 05:52:32 +00:00
|
|
|
ohmd_context *ctx;
|
|
|
|
bool print_spew;
|
|
|
|
bool print_debug;
|
|
|
|
};
|
|
|
|
|
|
|
|
static inline struct oh_prober *
|
2019-04-22 20:36:59 +00:00
|
|
|
oh_prober(struct xrt_auto_prober *p)
|
2019-03-18 05:52:32 +00:00
|
|
|
{
|
|
|
|
return (struct oh_prober *)p;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-04-22 20:36:59 +00:00
|
|
|
oh_prober_destroy(struct xrt_auto_prober *p)
|
2019-03-18 05:52:32 +00:00
|
|
|
{
|
|
|
|
struct oh_prober *ohp = oh_prober(p);
|
|
|
|
|
|
|
|
if (ohp->ctx != NULL) {
|
|
|
|
ohmd_ctx_destroy(ohp->ctx);
|
|
|
|
ohp->ctx = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
free(ohp);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct xrt_device *
|
2019-04-22 20:36:59 +00:00
|
|
|
oh_prober_autoprobe(struct xrt_auto_prober *p)
|
2019-03-18 05:52:32 +00:00
|
|
|
{
|
|
|
|
struct oh_prober *ohp = oh_prober(p);
|
|
|
|
|
|
|
|
int device_idx = -1;
|
|
|
|
|
|
|
|
/* Probe for devices */
|
|
|
|
int num_devices = ohmd_ctx_probe(ohp->ctx);
|
|
|
|
|
|
|
|
/* Then loop */
|
|
|
|
for (int i = 0; i < num_devices; i++) {
|
|
|
|
int device_class = 0, device_flags = 0;
|
|
|
|
|
|
|
|
ohmd_list_geti(ohp->ctx, i, OHMD_DEVICE_CLASS, &device_class);
|
|
|
|
ohmd_list_geti(ohp->ctx, i, OHMD_DEVICE_FLAGS, &device_flags);
|
|
|
|
|
|
|
|
if (device_class != OHMD_DEVICE_CLASS_HMD) {
|
|
|
|
OH_DEBUG(ohp, "Rejecting device idx %i, is not a HMD.",
|
|
|
|
i);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (device_flags & OHMD_DEVICE_FLAGS_NULL_DEVICE) {
|
|
|
|
OH_DEBUG(ohp,
|
|
|
|
"Rejecting device idx %i, is a NULL device.",
|
|
|
|
i);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
OH_DEBUG(ohp, "Selecting device idx %i", i);
|
|
|
|
device_idx = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (device_idx < 0) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *prod = ohmd_list_gets(ohp->ctx, device_idx, OHMD_PRODUCT);
|
|
|
|
ohmd_device *dev = ohmd_list_open_device(ohp->ctx, device_idx);
|
|
|
|
if (dev == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct oh_device *ohd = oh_device_create(
|
|
|
|
ohp->ctx, dev, prod, ohp->print_spew, ohp->print_debug);
|
|
|
|
return &ohd->base;
|
|
|
|
}
|
|
|
|
|
2019-04-22 20:36:59 +00:00
|
|
|
struct xrt_auto_prober *
|
|
|
|
oh_create_auto_prober()
|
2019-03-18 05:52:32 +00:00
|
|
|
{
|
2019-03-21 20:19:52 +00:00
|
|
|
struct oh_prober *ohp = U_TYPED_CALLOC(struct oh_prober);
|
2019-03-18 05:52:32 +00:00
|
|
|
ohp->base.destroy = oh_prober_destroy;
|
|
|
|
ohp->base.lelo_dallas_autoprobe = oh_prober_autoprobe;
|
|
|
|
ohp->ctx = ohmd_ctx_create();
|
|
|
|
ohp->print_spew = debug_get_bool_option_oh_spew();
|
|
|
|
ohp->print_debug = debug_get_bool_option_oh_debug();
|
|
|
|
|
|
|
|
return &ohp->base;
|
|
|
|
}
|