The open source OpenXR runtime
at prediction-2 70 lines 1.7 kB view raw
1// Copyright 2020-2024, Collabora, Ltd. 2// SPDX-License-Identifier: BSL-1.0 3/*! 4 * @file 5 * @brief "auto-prober" for Sample HMD that can be autodetected but not through USB VID/PID. 6 * @author Jakob Bornecrantz <jakob@collabora.com> 7 * @ingroup drv_sample 8 */ 9 10#include "xrt/xrt_prober.h" 11 12#include "util/u_misc.h" 13 14#include "sample_interface.h" 15 16 17/*! 18 * @implements xrt_auto_prober 19 */ 20struct sample_auto_prober 21{ 22 struct xrt_auto_prober base; 23}; 24 25//! @private @memberof sample_auto_prober 26static inline struct sample_auto_prober * 27sample_auto_prober(struct xrt_auto_prober *xap) 28{ 29 return (struct sample_auto_prober *)xap; 30} 31 32//! @private @memberof sample_auto_prober 33static void 34sample_auto_prober_destroy(struct xrt_auto_prober *p) 35{ 36 struct sample_auto_prober *ap = sample_auto_prober(p); 37 38 free(ap); 39} 40 41//! @public @memberof sample_auto_prober 42static int 43sample_auto_prober_autoprobe(struct xrt_auto_prober *xap, 44 cJSON *attached_data, 45 bool no_hmds, 46 struct xrt_prober *xp, 47 struct xrt_device **out_xdevs) 48{ 49 struct sample_auto_prober *ap = sample_auto_prober(xap); 50 (void)ap; 51 52 // Do not create an HMD device if we are not looking for HMDs. 53 if (no_hmds) { 54 return 0; 55 } 56 57 out_xdevs[0] = sample_hmd_create(); 58 return 1; 59} 60 61struct xrt_auto_prober * 62sample_create_auto_prober(void) 63{ 64 struct sample_auto_prober *ap = U_TYPED_CALLOC(struct sample_auto_prober); 65 ap->base.name = "Sample HMD Auto-Prober"; 66 ap->base.destroy = sample_auto_prober_destroy; 67 ap->base.lelo_dallas_autoprobe = sample_auto_prober_autoprobe; 68 69 return &ap->base; 70}