The open source OpenXR runtime
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

d/vive: Drain all imu packets at startup

+28 -6
+28 -6
src/xrt/drivers/vive/vive_device.c
··· 436 436 } 437 437 } 438 438 439 + static void 440 + drain_imu(struct vive_device *d, const void *buffer) 441 + { 442 + // Noop 443 + } 444 + 439 445 440 446 /* 441 447 * ··· 784 790 785 791 U_TRACE_SET_THREAD_NAME("Vive: Sensors"); 786 792 787 - os_thread_helper_lock(&d->sensors_thread); 788 - while (os_thread_helper_is_running_locked(&d->sensors_thread)) { 789 - os_thread_helper_unlock(&d->sensors_thread); 790 793 791 - if (!vive_sensors_read_one_msg(d, d->sensors_dev, VIVE_IMU_REPORT_ID, 52, update_imu)) { 794 + /* 795 + * We want to drain all old packets to avoid old ones, 796 + * read packets with a noop function for 50ms. 797 + */ 798 + 799 + uint64_t then_ns = os_monotonic_get_ns(); 800 + uint64_t future_50ms_ns = then_ns + U_TIME_1MS_IN_NS * (uint64_t)50; 801 + 802 + while (future_50ms_ns > os_monotonic_get_ns() && os_thread_helper_is_running(&d->sensors_thread)) { 803 + // Lock not held. 804 + if (!vive_sensors_read_one_msg(d, d->sensors_dev, VIVE_IMU_REPORT_ID, 52, drain_imu)) { 792 805 return NULL; 793 806 } 807 + } 794 808 795 - // Just keep swimming. 796 - os_thread_helper_lock(&d->sensors_thread); 809 + 810 + /* 811 + * Now read the packets. 812 + */ 813 + 814 + while (os_thread_helper_is_running(&d->sensors_thread)) { 815 + // Lock not held. 816 + if (!vive_sensors_read_one_msg(d, d->sensors_dev, VIVE_IMU_REPORT_ID, 52, update_imu)) { 817 + return NULL; 818 + } 797 819 } 798 820 799 821 return NULL;