mirror of
https://gitlab.freedesktop.org/monado/monado.git
synced 2025-01-04 06:06:17 +00:00
st/prober: Allow autoprobe function to create more than one device.
This commit is contained in:
parent
f55c0d7bfb
commit
116d77f52e
|
@ -62,11 +62,16 @@ android_prober_destroy(struct xrt_auto_prober *p)
|
|||
}
|
||||
|
||||
//! @public @memberof android_prober
|
||||
static struct xrt_device *
|
||||
android_prober_autoprobe(struct xrt_auto_prober *xap, cJSON *attached_data, bool no_hmds, struct xrt_prober *xp)
|
||||
static int
|
||||
android_prober_autoprobe(struct xrt_auto_prober *xap,
|
||||
cJSON *attached_data,
|
||||
bool no_hmds,
|
||||
struct xrt_prober *xp,
|
||||
struct xrt_device **out_xdevs)
|
||||
{
|
||||
struct android_device *dd = android_device_create();
|
||||
return &dd->base;
|
||||
out_xdevs[0] = &dd->base;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -66,12 +66,16 @@ arduino_prober_destroy(struct xrt_auto_prober *p)
|
|||
}
|
||||
|
||||
//! @public @memberof arduino_prober
|
||||
static struct xrt_device *
|
||||
arduino_prober_autoprobe(struct xrt_auto_prober *xap, cJSON *attached_data, bool no_hmds, struct xrt_prober *xp)
|
||||
static int
|
||||
arduino_prober_autoprobe(struct xrt_auto_prober *xap,
|
||||
cJSON *attached_data,
|
||||
bool no_hmds,
|
||||
struct xrt_prober *xp,
|
||||
struct xrt_device **out_xdevs)
|
||||
{
|
||||
struct arduino_prober *ap = arduino_prober(xap);
|
||||
if (!ap->enabled) {
|
||||
return NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
const char *dev_uuid = "00004242-0000-1000-8000-004242424242";
|
||||
|
@ -80,10 +84,11 @@ arduino_prober_autoprobe(struct xrt_auto_prober *xap, cJSON *attached_data, bool
|
|||
struct os_ble_device *ble = NULL;
|
||||
os_ble_notify_open(dev_uuid, char_uuid, &ble);
|
||||
if (ble == NULL) {
|
||||
return NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
return arduino_device_create(ble);
|
||||
out_xdevs[0] = arduino_device_create(ble);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -66,12 +66,16 @@ daydream_prober_destroy(struct xrt_auto_prober *p)
|
|||
}
|
||||
|
||||
//! @public @memberof daydream_prober
|
||||
static struct xrt_device *
|
||||
daydream_prober_autoprobe(struct xrt_auto_prober *xap, cJSON *attached_data, bool no_hmds, struct xrt_prober *xp)
|
||||
static int
|
||||
daydream_prober_autoprobe(struct xrt_auto_prober *xap,
|
||||
cJSON *attached_data,
|
||||
bool no_hmds,
|
||||
struct xrt_prober *xp,
|
||||
struct xrt_device **out_xdevs)
|
||||
{
|
||||
struct daydream_prober *pdaydream = daydream_prober(xap);
|
||||
if (!pdaydream->enabled) {
|
||||
return NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
const char *dev_uuid = "0000fe55-0000-1000-8000-00805f9b34fb";
|
||||
|
@ -80,12 +84,13 @@ daydream_prober_autoprobe(struct xrt_auto_prober *xap, cJSON *attached_data, boo
|
|||
struct os_ble_device *ble = NULL;
|
||||
os_ble_notify_open(dev_uuid, char_uuid, &ble);
|
||||
if (ble == NULL) {
|
||||
return NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct daydream_device *dd = daydream_device_create(ble);
|
||||
|
||||
return &dd->base;
|
||||
out_xdevs[0] = &dd->base;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -42,18 +42,23 @@ dummy_prober_destroy(struct xrt_auto_prober *p)
|
|||
}
|
||||
|
||||
//! @public @memberof dummy_prober
|
||||
static struct xrt_device *
|
||||
dummy_prober_autoprobe(struct xrt_auto_prober *xap, cJSON *attached_data, bool no_hmds, struct xrt_prober *xp)
|
||||
static int
|
||||
dummy_prober_autoprobe(struct xrt_auto_prober *xap,
|
||||
cJSON *attached_data,
|
||||
bool no_hmds,
|
||||
struct xrt_prober *xp,
|
||||
struct xrt_device **out_xdevs)
|
||||
{
|
||||
struct dummy_prober *dp = dummy_prober(xap);
|
||||
(void)dp;
|
||||
|
||||
// Do not create a dummy HMD if we are not looking for HMDs.
|
||||
if (no_hmds) {
|
||||
return NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
return dummy_hmd_create();
|
||||
out_xdevs[0] = dummy_hmd_create();
|
||||
return 1;
|
||||
}
|
||||
|
||||
struct xrt_auto_prober *
|
||||
|
|
|
@ -40,13 +40,17 @@ ht_prober_destroy(struct xrt_auto_prober *p)
|
|||
}
|
||||
|
||||
//! @public @memberof ht_prober
|
||||
static struct xrt_device *
|
||||
ht_prober_autoprobe(struct xrt_auto_prober *xap, cJSON *attached_data, bool no_hmds, struct xrt_prober *xp)
|
||||
static int
|
||||
ht_prober_autoprobe(struct xrt_auto_prober *xap,
|
||||
cJSON *attached_data,
|
||||
bool no_hmds,
|
||||
struct xrt_prober *xp,
|
||||
struct xrt_device **out_xdevs)
|
||||
{
|
||||
struct xrt_device *xdev = ht_device_create(xap, attached_data, xp);
|
||||
|
||||
if (xdev == NULL) {
|
||||
return NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
xdev->orientation_tracking_supported = true;
|
||||
|
@ -54,7 +58,8 @@ ht_prober_autoprobe(struct xrt_auto_prober *xap, cJSON *attached_data, bool no_h
|
|||
xdev->hand_tracking_supported = true;
|
||||
xdev->device_type = XRT_DEVICE_TYPE_HAND_TRACKER;
|
||||
|
||||
return xdev;
|
||||
out_xdevs[0] = xdev;
|
||||
return 1;
|
||||
}
|
||||
|
||||
struct xrt_auto_prober *
|
||||
|
|
|
@ -33,24 +33,29 @@ illixr_prober_destroy(struct xrt_auto_prober *p)
|
|||
free(dp);
|
||||
}
|
||||
|
||||
static struct xrt_device *
|
||||
illixr_prober_autoprobe(struct xrt_auto_prober *xap, cJSON *attached_data, bool no_hmds, struct xrt_prober *xp)
|
||||
static int
|
||||
illixr_prober_autoprobe(struct xrt_auto_prober *xap,
|
||||
cJSON *attached_data,
|
||||
bool no_hmds,
|
||||
struct xrt_prober *xp,
|
||||
struct xrt_device **out_xdevs)
|
||||
{
|
||||
struct illixr_prober *dp = illixr_prober(xap);
|
||||
(void)dp;
|
||||
|
||||
if (no_hmds) {
|
||||
return NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
const char *illixr_path, *illixr_comp;
|
||||
illixr_path = getenv("ILLIXR_PATH");
|
||||
illixr_comp = getenv("ILLIXR_COMP");
|
||||
if (!illixr_path || !illixr_comp) {
|
||||
return NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
return illixr_hmd_create(illixr_path, illixr_comp);
|
||||
out_xdevs[0] = illixr_hmd_create(illixr_path, illixr_comp);
|
||||
return 1;
|
||||
}
|
||||
|
||||
struct xrt_auto_prober *
|
||||
|
|
|
@ -48,20 +48,25 @@ ns_prober_destroy(struct xrt_auto_prober *p)
|
|||
}
|
||||
|
||||
//! @public @memberof ns_prober
|
||||
static struct xrt_device *
|
||||
ns_prober_autoprobe(struct xrt_auto_prober *xap, cJSON *attached_data, bool no_hmds, struct xrt_prober *xp)
|
||||
static int
|
||||
ns_prober_autoprobe(struct xrt_auto_prober *xap,
|
||||
cJSON *attached_data,
|
||||
bool no_hmds,
|
||||
struct xrt_prober *xp,
|
||||
struct xrt_device **out_xdevs)
|
||||
{
|
||||
struct ns_prober *nsp = ns_prober(xap);
|
||||
|
||||
if (no_hmds) {
|
||||
return NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (nsp->config_path == NULL) {
|
||||
return NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
return ns_hmd_create(nsp->config_path);
|
||||
out_xdevs[0] = ns_hmd_create(nsp->config_path);
|
||||
return 1;
|
||||
}
|
||||
|
||||
struct xrt_auto_prober *
|
||||
|
|
|
@ -53,14 +53,18 @@ oh_prober_destroy(struct xrt_auto_prober *p)
|
|||
}
|
||||
|
||||
//! @public @memberof oh_prober
|
||||
static struct xrt_device *
|
||||
oh_prober_autoprobe(struct xrt_auto_prober *xap, cJSON *attached_data, bool no_hmds, struct xrt_prober *xp)
|
||||
static int
|
||||
oh_prober_autoprobe(struct xrt_auto_prober *xap,
|
||||
cJSON *attached_data,
|
||||
bool no_hmds,
|
||||
struct xrt_prober *xp,
|
||||
struct xrt_device **out_xdevs)
|
||||
{
|
||||
struct oh_prober *ohp = oh_prober(xap);
|
||||
|
||||
// Do not use OpenHMD if we are not looking for HMDs.
|
||||
if (no_hmds) {
|
||||
return NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int device_idx = -1;
|
||||
|
@ -103,13 +107,13 @@ oh_prober_autoprobe(struct xrt_auto_prober *xap, cJSON *attached_data, bool no_h
|
|||
}
|
||||
|
||||
if (device_idx < 0) {
|
||||
return NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
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;
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct xrt_device *xdev = oh_device_create(ohp->ctx, dev, prod);
|
||||
|
@ -118,7 +122,8 @@ oh_prober_autoprobe(struct xrt_auto_prober *xap, cJSON *attached_data, bool no_h
|
|||
xdev->position_tracking_supported = position_tracking_supported;
|
||||
xdev->device_type = XRT_DEVICE_TYPE_HMD;
|
||||
|
||||
return xdev;
|
||||
out_xdevs[0] = xdev;
|
||||
return 1;
|
||||
}
|
||||
|
||||
struct xrt_auto_prober *
|
||||
|
|
|
@ -74,8 +74,12 @@ psvr_prober_destroy(struct xrt_auto_prober *p)
|
|||
}
|
||||
|
||||
//! @public @memberof psvr_prober
|
||||
static struct xrt_device *
|
||||
psvr_prober_autoprobe(struct xrt_auto_prober *xap, cJSON *attached_data, bool no_hmds, struct xrt_prober *xp)
|
||||
static int
|
||||
psvr_prober_autoprobe(struct xrt_auto_prober *xap,
|
||||
cJSON *attached_data,
|
||||
bool no_hmds,
|
||||
struct xrt_prober *xp,
|
||||
struct xrt_device **out_xdevs)
|
||||
{
|
||||
struct psvr_prober *ppsvr = psvr_prober(xap);
|
||||
struct hid_device_info *info_control = NULL;
|
||||
|
@ -86,7 +90,7 @@ psvr_prober_autoprobe(struct xrt_auto_prober *xap, cJSON *attached_data, bool no
|
|||
|
||||
// Do not look for the PSVR if we are not looking for HMDs.
|
||||
if (no_hmds) {
|
||||
return NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
devs = hid_enumerate(PSVR_VID, PSVR_PID);
|
||||
|
@ -110,7 +114,8 @@ psvr_prober_autoprobe(struct xrt_auto_prober *xap, cJSON *attached_data, bool no
|
|||
|
||||
hid_free_enumeration(devs);
|
||||
|
||||
return dev;
|
||||
out_xdevs[0] = dev;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -33,8 +33,10 @@ struct xrt_tracking_factory;
|
|||
struct os_hid_device;
|
||||
|
||||
/*!
|
||||
* The maximum number of devices that a single "found" function called by the
|
||||
* prober can create per-call.
|
||||
* The maximum number of devices that a single
|
||||
* @ref xrt_prober_entry::found or
|
||||
* @ref xrt_auto_prober::lelo_dallas_autoprobe
|
||||
* function called by the prober can create per-call.
|
||||
*
|
||||
* @ingroup xrt_iface
|
||||
*/
|
||||
|
@ -432,13 +434,19 @@ struct xrt_auto_prober
|
|||
* devices.
|
||||
* @param[in] xp Prober: provided for access to the tracking factory,
|
||||
* among other reasons.
|
||||
* @param[out] out_xdevs Array of @ref XRT_MAX_DEVICES_PER_PROBE @c NULL
|
||||
* @ref xrt_device pointers. First elements will be populated with new
|
||||
* devices.
|
||||
*
|
||||
* @return New device implementing the xrt_device interface, or NULL.
|
||||
* @return The amount of devices written into @p out_xdevs, 0 if none.
|
||||
*
|
||||
* @note Leeloo Dallas is a reference to The Fifth Element.
|
||||
*/
|
||||
struct xrt_device *(*lelo_dallas_autoprobe)(struct xrt_auto_prober *xap,
|
||||
cJSON *attached_data,
|
||||
bool no_hmds,
|
||||
struct xrt_prober *xp);
|
||||
int (*lelo_dallas_autoprobe)(struct xrt_auto_prober *xap,
|
||||
cJSON *attached_data,
|
||||
bool no_hmds,
|
||||
struct xrt_prober *xp,
|
||||
struct xrt_device **out_xdevs);
|
||||
/*!
|
||||
* Destroy this auto-prober.
|
||||
*
|
||||
|
|
|
@ -612,13 +612,25 @@ add_from_auto_probers(struct prober *p, struct xrt_device **xdevs, size_t num_xd
|
|||
*/
|
||||
bool no_hmds = *have_hmd;
|
||||
|
||||
struct xrt_device *xdev =
|
||||
p->auto_probers[i]->lelo_dallas_autoprobe(p->auto_probers[i], NULL, no_hmds, &p->base);
|
||||
if (xdev == NULL) {
|
||||
struct xrt_device *new_xdevs[XRT_MAX_DEVICES_PER_PROBE] = {NULL};
|
||||
int num_found =
|
||||
p->auto_probers[i]->lelo_dallas_autoprobe(p->auto_probers[i], NULL, no_hmds, &p->base, new_xdevs);
|
||||
|
||||
if (num_found <= 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
handle_found_device(p, xdevs, num_xdevs, have_hmd, xdev);
|
||||
for (int created_idx = 0; created_idx < num_found; ++created_idx) {
|
||||
if (new_xdevs[created_idx] == NULL) {
|
||||
P_DEBUG(p,
|
||||
"Leaving device creation loop "
|
||||
"early: autoprobe function reported %i "
|
||||
"created, but only %i non-null",
|
||||
num_found, created_idx);
|
||||
continue;
|
||||
}
|
||||
handle_found_device(p, xdevs, num_xdevs, have_hmd, new_xdevs[created_idx]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue