2019-03-18 05:52:32 +00:00
|
|
|
// Copyright 2019, Collabora, Ltd.
|
|
|
|
// SPDX-License-Identifier: BSL-1.0
|
|
|
|
/*!
|
|
|
|
* @file
|
|
|
|
* @brief OSVR HDK prober code.
|
|
|
|
* @author Jakob Bornecrantz <jakob@collabora.com>
|
|
|
|
* @author Ryan Pavlik <ryan.pavlik@collabora.com>
|
2019-04-12 13:08:46 +00:00
|
|
|
* @ingroup drv_hdk
|
2019-03-18 05:52:32 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include "xrt/xrt_prober.h"
|
|
|
|
|
|
|
|
#include "util/u_misc.h"
|
|
|
|
#include "util/u_debug.h"
|
|
|
|
|
2019-06-18 18:24:46 +00:00
|
|
|
#include "hdk_interface.h"
|
2019-03-18 05:52:32 +00:00
|
|
|
#include "hdk_device.h"
|
|
|
|
|
|
|
|
|
|
|
|
DEBUG_GET_ONCE_BOOL_OPTION(hdk_spew, "HDK_PRINT_SPEW", false)
|
|
|
|
DEBUG_GET_ONCE_BOOL_OPTION(hdk_debug, "HDK_PRINT_DEBUG", false)
|
|
|
|
|
2019-06-21 17:46:47 +00:00
|
|
|
static const char HDK2_PRODUCT_STRING[] = "OSVR HDK 2";
|
|
|
|
static const char HDK13_PRODUCT_STRING[] = "OSVR HDK 1.3/1.4";
|
|
|
|
static const char HDK1_PRODUCT_STRING[] = "OSVR HDK 1.x";
|
2019-03-13 18:20:10 +00:00
|
|
|
static const char HDK12_PRODUCT_STRING[] = "OSVR HDK 1.2";
|
2019-03-18 05:52:32 +00:00
|
|
|
|
2019-06-21 17:46:47 +00:00
|
|
|
int
|
|
|
|
hdk_found(struct xrt_prober *xp,
|
|
|
|
struct xrt_prober_device **devices,
|
|
|
|
size_t index,
|
|
|
|
struct xrt_device **out_xdev)
|
2019-03-18 05:52:32 +00:00
|
|
|
{
|
2019-06-21 17:46:47 +00:00
|
|
|
struct xrt_prober_device *dev = devices[index];
|
2019-03-18 05:52:32 +00:00
|
|
|
|
|
|
|
bool print_spew = debug_get_bool_option_hdk_spew();
|
|
|
|
bool print_debug = debug_get_bool_option_hdk_debug();
|
2019-06-21 17:48:09 +00:00
|
|
|
|
2019-06-21 17:46:47 +00:00
|
|
|
unsigned char buf[256] = {0};
|
|
|
|
int result = xrt_prober_get_string_descriptor(
|
|
|
|
xp, dev, XRT_PROBER_STRING_PRODUCT, buf, sizeof(buf));
|
|
|
|
|
2019-03-15 21:39:12 +00:00
|
|
|
enum HDK_VARIANT variant = HDK_UNKNOWN;
|
|
|
|
const char *name = NULL;
|
2019-06-21 17:46:47 +00:00
|
|
|
if (0 == strncmp(HDK2_PRODUCT_STRING, (const char *)buf, sizeof(buf))) {
|
|
|
|
variant = HDK_VARIANT_2;
|
|
|
|
name = HDK2_PRODUCT_STRING;
|
|
|
|
} else if (0 == strncmp(HDK1_PRODUCT_STRING, (const char *)buf,
|
|
|
|
sizeof(buf))) {
|
|
|
|
variant = HDK_VARIANT_1_2;
|
|
|
|
name = HDK12_PRODUCT_STRING;
|
|
|
|
} else {
|
|
|
|
//! @todo just assuming anything else is 1.3 for now
|
|
|
|
variant = HDK_VARIANT_1_3_1_4;
|
|
|
|
name = HDK13_PRODUCT_STRING;
|
2019-03-15 21:39:12 +00:00
|
|
|
}
|
2019-06-21 17:46:47 +00:00
|
|
|
|
|
|
|
printf("%s - Found at least the tracker of some HDK -- %s -- opening\n",
|
|
|
|
__func__, name);
|
|
|
|
|
|
|
|
struct os_hid_device *hid = NULL;
|
|
|
|
// Interface 2 is the HID interface.
|
2019-06-21 17:48:09 +00:00
|
|
|
result = xrt_prober_open_hid_interface(xp, dev, 2, &hid);
|
2019-06-21 17:46:47 +00:00
|
|
|
if (result != 0) {
|
|
|
|
return -1;
|
2019-03-18 05:52:32 +00:00
|
|
|
}
|
|
|
|
struct hdk_device *hd =
|
2019-06-21 17:46:47 +00:00
|
|
|
hdk_device_create(hid, variant, print_spew, print_debug);
|
|
|
|
if (hd == NULL) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
*out_xdev = &hd->base;
|
|
|
|
return 1;
|
2019-03-18 05:52:32 +00:00
|
|
|
}
|