d/vive: Run watchman poll in separate thread

Watchman polling times out after 1 second when basestations are not present/off.
This should not block reading the IMU.
This commit is contained in:
Christoph Haag 2020-08-04 00:41:47 +02:00 committed by Christoph Haag
parent 07f2e62e76
commit 3a68f60d47
2 changed files with 30 additions and 4 deletions

View file

@ -51,6 +51,7 @@ vive_device_destroy(struct xrt_device *xdev)
// Destroy the thread object.
os_thread_helper_destroy(&d->sensors_thread);
os_thread_helper_destroy(&d->watchman_thread);
os_thread_helper_destroy(&d->mainboard_thread);
m_imu_3dof_close(&d->fusion);
@ -724,6 +725,26 @@ vive_sensors_read_lighthouse_msg(struct vive_device *d)
return true;
}
static void *
vive_watchman_run_thread(void *ptr)
{
struct vive_device *d = (struct vive_device *)ptr;
os_thread_helper_lock(&d->watchman_thread);
while (os_thread_helper_is_running_locked(&d->watchman_thread)) {
os_thread_helper_unlock(&d->watchman_thread);
if (d->watchman_dev)
if (!vive_sensors_read_lighthouse_msg(d))
return NULL;
// Just keep swimming.
os_thread_helper_lock(&d->watchman_thread);
}
return NULL;
}
static void *
vive_sensors_run_thread(void *ptr)
{
@ -739,10 +760,6 @@ vive_sensors_run_thread(void *ptr)
return NULL;
}
if (d->watchman_dev)
if (!vive_sensors_read_lighthouse_msg(d))
return NULL;
// Just keep swimming.
os_thread_helper_lock(&d->sensors_thread);
}
@ -964,5 +981,13 @@ vive_device_create(struct os_hid_device *mainboard_dev,
return NULL;
}
ret = os_thread_helper_start(&d->watchman_thread,
vive_watchman_run_thread, d);
if (ret != 0) {
VIVE_ERROR(d, "Failed to start watchman thread!");
vive_device_destroy((struct xrt_device *)d);
return NULL;
}
return d;
}

View file

@ -66,6 +66,7 @@ struct vive_device
enum VIVE_VARIANT variant;
struct os_thread_helper sensors_thread;
struct os_thread_helper watchman_thread;
struct os_thread_helper mainboard_thread;
struct lh_model lh;