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.
This commit is contained in:
PJ Reiniger
2018-03-03 04:57:45 -05:00
committed by Peter Johnson
parent 82152e90fe
commit 67de595c85

View File

@@ -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();
}
}
/**