The open source OpenXR runtime
at main 69 lines 1.9 kB view raw
1// Copyright 2019, Collabora, Ltd. 2// SPDX-License-Identifier: BSL-1.0 3/*! 4 * @file 5 * @brief OSVR HDK prober code. 6 * @author Jakob Bornecrantz <jakob@collabora.com> 7 * @author Rylie Pavlik <rylie.pavlik@collabora.com> 8 * @ingroup drv_hdk 9 */ 10 11#include <stdio.h> 12#include <stdlib.h> 13 14#include "xrt/xrt_prober.h" 15 16#include "util/u_misc.h" 17#include "util/u_debug.h" 18 19#include "hdk_interface.h" 20#include "hdk_device.h" 21 22 23static const char HDK2_PRODUCT_STRING[] = "OSVR HDK 2"; 24static const char HDK13_PRODUCT_STRING[] = "OSVR HDK 1.3/1.4"; 25static const char HDK1_PRODUCT_STRING[] = "OSVR HDK 1.x"; 26static const char HDK12_PRODUCT_STRING[] = "OSVR HDK 1.2"; 27 28int 29hdk_found(struct xrt_prober *xp, 30 struct xrt_prober_device **devices, 31 size_t device_count, 32 size_t index, 33 cJSON *attached_data, 34 struct xrt_device **out_xdev) 35{ 36 struct xrt_prober_device *dev = devices[index]; 37 38 unsigned char buf[256] = {0}; 39 int result = xrt_prober_get_string_descriptor(xp, dev, XRT_PROBER_STRING_PRODUCT, buf, sizeof(buf)); 40 41 enum HDK_VARIANT variant = HDK_UNKNOWN; 42 const char *name = NULL; 43 if (0 == strncmp(HDK2_PRODUCT_STRING, (const char *)buf, sizeof(buf))) { 44 variant = HDK_VARIANT_2; 45 name = HDK2_PRODUCT_STRING; 46 } else if (0 == strncmp(HDK1_PRODUCT_STRING, (const char *)buf, sizeof(buf))) { 47 variant = HDK_VARIANT_1_2; 48 name = HDK12_PRODUCT_STRING; 49 } else { 50 //! @todo just assuming anything else is 1.3 for now 51 variant = HDK_VARIANT_1_3_1_4; 52 name = HDK13_PRODUCT_STRING; 53 } 54 55 U_LOG_I("%s - Found at least the tracker of some HDK (%s) -- opening\n", __func__, name); 56 57 struct os_hid_device *hid = NULL; 58 // Interface 2 is the HID interface. 59 result = xrt_prober_open_hid_interface(xp, dev, 2, &hid); 60 if (result != 0) { 61 return -1; 62 } 63 struct hdk_device *hd = hdk_device_create(hid, variant); 64 if (hd == NULL) { 65 return -1; 66 } 67 *out_xdev = &hd->base; 68 return 1; 69}