From e5ab98d5fc360a924a7db9feb88668fc6938cb9e Mon Sep 17 00:00:00 2001 From: Thilo Graf Date: Mon, 2 Sep 2024 21:06:01 +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. Origin commit data ------------------ Branch: ni/coolstream Commit: https://github.com/neutrino-images/ni-neutrino/commit/f65209c56cb758a9627dbadd927612fe9486dff4 Author: Thilo Graf Date: 2024-09-02 (Mon, 02 Sep 2024) Origin message was: ------------------ 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. ------------------ This commit was generated by Migit --- 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 d048cee1f..1c71ae994 100644 --- a/src/driver/rcinput.cpp +++ b/src/driver/rcinput.cpp @@ -1343,10 +1343,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); }