From 67de595c85fe5fbc12eddd7df5bf2db26d15273a Mon Sep 17 00:00:00 2001 From: PJ Reiniger Date: Sat, 3 Mar 2018 04:57:45 -0500 Subject: [PATCH] ADXRS450_Gyro: Add null check around reset (#948) Reset() is the only function without a null check around it. We call the function on startup, which means if it is unplugged the robot crashes. Also added an accessor for checking if it is connected, as some teams (us) would like to handle the case where it was not connected on startup. --- .../main/java/edu/wpi/first/wpilibj/ADXRS450_Gyro.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/ADXRS450_Gyro.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/ADXRS450_Gyro.java index bbef3c5517..1449a80682 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/ADXRS450_Gyro.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/ADXRS450_Gyro.java @@ -80,6 +80,10 @@ public class ADXRS450_Gyro extends GyroBase implements Gyro, PIDSource, Sendable setName("ADXRS450_Gyro", port.value); } + public boolean isConnected() { + return m_spi != null; + } + @Override public void calibrate() { if (m_spi == null) { @@ -128,7 +132,9 @@ public class ADXRS450_Gyro extends GyroBase implements Gyro, PIDSource, Sendable @Override public void reset() { - m_spi.resetAccumulator(); + if (m_spi != null) { + m_spi.resetAccumulator(); + } } /**