From 637539bdee673927c498f8e1c0d7dda435b2226b Mon Sep 17 00:00:00 2001 From: Thilo Graf Date: Thu, 4 Jul 2024 16:08:36 +0200 Subject: [PATCH] rcinput: ensure backward compatibility supplement to commit: rcinput: Fix build issues with _TIME_BITS=64 - Ensured compatibility with various definitions of input_event structure as per input.h. - Added conditional compilation to check for input_event_sec macro. - Used input_event_sec and input_event_usec macros if defined. - Provided fallback to direct timeval members for versions without the macros. This ensures compatibility with both newer and older kernel versions, different C library implementations, and possible standard settings of build systems. Addressing different definitions of the input_event structure maintains robustness across kernel, library, and build system configurations. --- src/driver/rcinput.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/driver/rcinput.cpp b/src/driver/rcinput.cpp index 365977198..f8a4ee270 100644 --- a/src/driver/rcinput.cpp +++ b/src/driver/rcinput.cpp @@ -1339,10 +1339,21 @@ void CRCInput::getMsg_us(neutrino_msg_t * msg, neutrino_msg_data_t * data, uint6 * Everything would be much easier if we could use the post-kernel 3.4 * EVIOCSCLOCKID ioctl :-) */ struct timespec t1; - now_pressed = ev.input_event_sec * 1000000ULL + ev.input_event_usec; + // Check if input_event_sec macro is defined + #ifdef input_event_sec + // Use input_event_sec and input_event_usec macros if they are defined + now_pressed = ev.input_event_sec * 1000000ULL + ev.input_event_usec; + #else + // Fallback for older versions that use timeval directly + now_pressed = ev.time.tv_sec * 1000000ULL + ev.time.tv_usec; + #endif + + // Get the current time using clock_gettime if (!clock_gettime(CLOCK_MONOTONIC, &t1)) { struct timeval t2; + // Get the current time using gettimeofday gettimeofday(&t2, NULL); + // Calculate now_pressed using timespec and timeval now_pressed += t1.tv_sec * 1000000ULL + t1.tv_nsec / 1000; now_pressed -= (t2.tv_usec + t2.tv_sec * 1000000ULL); }