From 08c6fe974435a0a6481aee777121ceaa345ba5b1 Mon Sep 17 00:00:00 2001 From: Christoph Haag Date: Thu, 2 Jul 2020 00:39:07 +0200 Subject: [PATCH] d/vive_controller: Fix imu timestamp calculation Philipp Zabel looked into it and it turns out the timestamp from the imu sample should be the third byte, not the fourth. --- src/xrt/drivers/vive/vive_controller_driver.c | 2 +- src/xrt/drivers/vive/vive_protocol.h | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/xrt/drivers/vive/vive_controller_driver.c b/src/xrt/drivers/vive/vive_controller_driver.c index 253dfa002..efb1f7d6d 100644 --- a/src/xrt/drivers/vive/vive_controller_driver.c +++ b/src/xrt/drivers/vive/vive_controller_driver.c @@ -652,7 +652,7 @@ vive_controller_handle_imu_sample(struct vive_controller_device *d, struct watchman_imu_sample *sample) { /* ouvrt: "Time in 48 MHz ticks, but we are missing the low byte" */ - uint32_t time_raw = d->last_ticks | sample->timestamp_lo; + uint32_t time_raw = d->last_ticks | (sample->timestamp_hi << 8); uint32_t dt_raw = calc_dt_raw_and_handle_overflow(d, time_raw); uint64_t dt_ns = cald_dt_ns(dt_raw); diff --git a/src/xrt/drivers/vive/vive_protocol.h b/src/xrt/drivers/vive/vive_protocol.h index 9a2c8aef5..3900d7a64 100644 --- a/src/xrt/drivers/vive/vive_protocol.h +++ b/src/xrt/drivers/vive/vive_protocol.h @@ -185,9 +185,9 @@ struct watchman_imu_sample * The full timestamp is 4 bytes, formed by * first byte : vive_controller_message.timestamp_hi * second byte: vive_controller_message.timestamp_lo - * fourth byte: watchman_imu_sample.timestamp_lo */ - //! @todo: confirm timestamp_lo shouldn't be third byte instead. - uint8_t timestamp_lo; + * third byte: watchman_imu_sample.timestamp_hi + * fourth byte: remains zero */ + uint8_t timestamp_hi; uint16_t acc[3]; uint16_t gyro[3]; } __attribute__((packed));