File: hid-bigendian.patch

package info (click to toggle)
flightgear 1%3A2020.3.16%2Bdfsg-1%2Bdeb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 50,944 kB
  • sloc: cpp: 245,473; ansic: 181,318; sh: 13,686; perl: 4,475; python: 3,139; xml: 899; asm: 642; makefile: 349; java: 314
file content (31 lines) | stat: -rw-r--r-- 988 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
From: Joel Ray Holveck <joelh@piquan.org>
Date: Tue, 13 Oct 2020 13:57:27 +0200
Subject: hid-bigendian

===================================================================
---
 src/Input/FGHIDEventInput.cxx | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/src/Input/FGHIDEventInput.cxx b/src/Input/FGHIDEventInput.cxx
index 182d704..6a446de 100644
--- a/src/Input/FGHIDEventInput.cxx
+++ b/src/Input/FGHIDEventInput.cxx
@@ -27,6 +27,8 @@
 #include <cassert>
 #include <algorithm>
 
+#include <endian.h>
+
 #include <hidapi/hidapi.h>
 #include <hidapi/hidparse.h>
 
@@ -865,6 +867,8 @@ int extractBits(uint8_t* bytes, size_t lengthInBytes, size_t bitOffset, size_t b
     uint32_t v = 0;
     // this goes from byte alignment to word alignment safely
     memcpy((void*) &v, bytes + wholeBytesToSkip, bytesToCopy);
+    // the memcpy arranges v in little-endian order, so swap if needed
+    v = le32toh(v);
 
     // shift down so lowest bit is aligned
     v = v >> offsetInByte;