From 37b84d66bab2bc7121945d01fd9cd1ca0660de8f Mon Sep 17 00:00:00 2001 From: Thad House Date: Sun, 24 Nov 2024 22:11:45 -0800 Subject: [PATCH 1/2] Fix ADIS16470 Gyro in Java --- wpilibj/src/main/java/edu/wpi/first/wpilibj/ADIS16470_IMU.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/ADIS16470_IMU.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/ADIS16470_IMU.java index 4e38b713bf2..c9807efea64 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/ADIS16470_IMU.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/ADIS16470_IMU.java @@ -609,7 +609,7 @@ private int readRegister(int reg) { m_spi.write(buf, 2); m_spi.read(false, buf, 2); - return (buf[0] << 8) & buf[1]; + return (buf[0] << 8) | buf[1]; } private void writeRegister(int reg, int val) { From 913cde3eb809e3d45649525314a5d06491bd0c05 Mon Sep 17 00:00:00 2001 From: Thad House Date: Sun, 24 Nov 2024 23:10:09 -0800 Subject: [PATCH 2/2] Toushort --- .../src/main/java/edu/wpi/first/wpilibj/ADIS16470_IMU.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/ADIS16470_IMU.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/ADIS16470_IMU.java index c9807efea64..c2700b82c9b 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/ADIS16470_IMU.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/ADIS16470_IMU.java @@ -426,6 +426,10 @@ public boolean isConnected() { return m_connected; } + private static int toUShort(int upper, int lower) { + return ((upper & 0xFF) << 8) + (lower & 0xFF); + } + private static int toShort(int upper, int lower) { return (short) (((upper & 0xFF) << 8) + (lower & 0xFF)); } @@ -609,7 +613,7 @@ private int readRegister(int reg) { m_spi.write(buf, 2); m_spi.read(false, buf, 2); - return (buf[0] << 8) | buf[1]; + return toUShort(buf[0], buf[1]); } private void writeRegister(int reg, int val) {