From 3afb257ec3776cbd5ac2710ff4cd7e7b0571b6dd Mon Sep 17 00:00:00 2001 From: Denis Date: Sat, 18 Nov 2023 14:49:44 +0100 Subject: [PATCH] try to reduce output noise --- virt_ds4.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/virt_ds4.c b/virt_ds4.c index 261ebb0..68cd5b1 100644 --- a/virt_ds4.c +++ b/virt_ds4.c @@ -525,12 +525,18 @@ static int send_data(int fd, logic_t *const logic, uint8_t counter) { return gs_copy_res; } + if (first_read_time_arrived == 0) { + first_read_time = gs.last_motion_time; + first_read_time_arrived = 1; + } + // Calculate the time difference in microseconds - int64_t timeDiffMicroseconds = ((int64_t)gs.last_motion_time.tv_sec - (int64_t)first_read_time.tv_sec) * (int64_t)1000000 + ((int64_t)gs.last_motion_time.tv_usec - (int64_t)first_read_time.tv_usec); + const int64_t timeDiffMicroseconds = (((int64_t)gs.last_motion_time.tv_sec - (int64_t)first_read_time.tv_sec) * (int64_t)1000000) + + ((int64_t)gs.last_motion_time.tv_usec - (int64_t)first_read_time.tv_usec) * (int64_t)100; // Calculate the time difference in multiples of 0.33 microseconds - int64_t timeDiffInMultiples = ((double)timeDiffMicroseconds + (double)0.33 - (double)1.0) / (double)0.33; - uint16_t timestamp = timeDiffInMultiples; + const int64_t timeDiffInMultiples = (timeDiffMicroseconds / (int64_t)33 - (int64_t)100) / (int64_t)33; + uint16_t timestamp = timeDiffInMultiples / (int64_t)100; /* Example data: