The open source OpenXR runtime
at main 84 lines 1.9 kB view raw
1// Copyright 2020-2023, Collabora, Ltd. 2// SPDX-License-Identifier: BSL-1.0 3/*! 4 * @file 5 * @brief Simulated prober code. 6 * @author Jakob Bornecrantz <jakob@collabora.com> 7 * @ingroup drv_simulated 8 */ 9 10#include <stdio.h> 11#include <stdlib.h> 12 13#include "xrt/xrt_prober.h" 14 15#include "util/u_misc.h" 16#include "util/u_debug.h" 17 18#include "simulated_interface.h" 19 20 21DEBUG_GET_ONCE_BOOL_OPTION(simulated_rotate, "SIMULATED_ROTATE", false) 22 23/*! 24 * @implements xrt_auto_prober 25 */ 26struct simulated_prober 27{ 28 struct xrt_auto_prober base; 29}; 30 31//! @private @memberof simulated_prober 32static inline struct simulated_prober * 33simulated_prober(struct xrt_auto_prober *p) 34{ 35 return (struct simulated_prober *)p; 36} 37 38//! @public @memberof simulated_prober 39static void 40simulated_prober_destroy(struct xrt_auto_prober *p) 41{ 42 struct simulated_prober *dp = simulated_prober(p); 43 44 free(dp); 45} 46 47//! @public @memberof simulated_prober 48static int 49simulated_prober_autoprobe(struct xrt_auto_prober *xap, 50 cJSON *attached_data, 51 bool no_hmds, 52 struct xrt_prober *xp, 53 struct xrt_device **out_xdevs) 54{ 55 struct simulated_prober *dp = simulated_prober(xap); 56 (void)dp; 57 58 // Do not create a simulated HMD if we are not looking for HMDs. 59 if (no_hmds) { 60 return 0; 61 } 62 63 // Select the type of movement. 64 enum simulated_movement movement = SIMULATED_MOVEMENT_WOBBLE; 65 if (debug_get_bool_option_simulated_rotate()) { 66 movement = SIMULATED_MOVEMENT_ROTATE; 67 } 68 69 const struct xrt_pose center = XRT_POSE_IDENTITY; 70 out_xdevs[0] = simulated_hmd_create(movement, &center); 71 72 return 1; 73} 74 75struct xrt_auto_prober * 76simulated_create_auto_prober(void) 77{ 78 struct simulated_prober *dp = U_TYPED_CALLOC(struct simulated_prober); 79 dp->base.name = "Simulated"; 80 dp->base.destroy = simulated_prober_destroy; 81 dp->base.lelo_dallas_autoprobe = simulated_prober_autoprobe; 82 83 return &dp->base; 84}