diff --git a/src/xrt/drivers/vive/vive_device.c b/src/xrt/drivers/vive/vive_device.c index 43fabe175..73158060e 100644 --- a/src/xrt/drivers/vive/vive_device.c +++ b/src/xrt/drivers/vive/vive_device.c @@ -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; } diff --git a/src/xrt/drivers/vive/vive_device.h b/src/xrt/drivers/vive/vive_device.h index cee95b170..043cf57ea 100644 --- a/src/xrt/drivers/vive/vive_device.h +++ b/src/xrt/drivers/vive/vive_device.h @@ -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;