diff --git a/cscore/src/main/java/edu/wpi/cscore/VideoListener.java b/cscore/src/main/java/edu/wpi/cscore/VideoListener.java index 6bd433a0e1..187eae09d1 100644 --- a/cscore/src/main/java/edu/wpi/cscore/VideoListener.java +++ b/cscore/src/main/java/edu/wpi/cscore/VideoListener.java @@ -13,7 +13,7 @@ import java.util.function.Consumer; * An event listener. This calls back to a desigated callback function when * an event matching the specified mask is generated by the library. */ -public class VideoListener { +public class VideoListener implements AutoCloseable { /** * Create an event listener. * @param listener Listener function @@ -26,7 +26,13 @@ public class VideoListener { m_handle = CameraServerJNI.addListener(listener, eventMask, immediateNotify); } - public synchronized void free() { + @Deprecated + public void free() { + close(); + } + + @Override + public synchronized void close() { if (m_handle != 0) { CameraServerJNI.removeListener(m_handle); } diff --git a/cscore/src/main/java/edu/wpi/cscore/VideoSink.java b/cscore/src/main/java/edu/wpi/cscore/VideoSink.java index 4196f3da19..86e5eb14d6 100644 --- a/cscore/src/main/java/edu/wpi/cscore/VideoSink.java +++ b/cscore/src/main/java/edu/wpi/cscore/VideoSink.java @@ -12,7 +12,7 @@ package edu.wpi.cscore; * consist of multiple images (e.g. from a stereo or depth camera); these * are called channels. */ -public class VideoSink { +public class VideoSink implements AutoCloseable { public enum Kind { kUnknown(0), kMjpeg(2), kCv(4); private int value; @@ -38,7 +38,13 @@ public class VideoSink { m_handle = handle; } - public synchronized void free() { + @Deprecated + public void free() { + close(); + } + + @Override + public synchronized void close() { if (m_handle != 0) { CameraServerJNI.releaseSink(m_handle); } diff --git a/cscore/src/main/java/edu/wpi/cscore/VideoSource.java b/cscore/src/main/java/edu/wpi/cscore/VideoSource.java index 5f4acc11e9..1471ba5b45 100644 --- a/cscore/src/main/java/edu/wpi/cscore/VideoSource.java +++ b/cscore/src/main/java/edu/wpi/cscore/VideoSource.java @@ -12,7 +12,7 @@ package edu.wpi.cscore; * consist of multiple images (e.g. from a stereo or depth camera); these * are called channels. */ -public class VideoSource { +public class VideoSource implements AutoCloseable { public enum Kind { kUnknown(0), kUsb(1), kHttp(2), kCv(4); private int value; @@ -39,7 +39,13 @@ public class VideoSource { m_handle = handle; } - public synchronized void free() { + @Deprecated + public void free() { + close(); + } + + @Override + public synchronized void close() { if (m_handle != 0) { CameraServerJNI.releaseSource(m_handle); } diff --git a/hal/src/main/java/edu/wpi/first/wpilibj/sim/CallbackStore.java b/hal/src/main/java/edu/wpi/first/wpilibj/sim/CallbackStore.java index 5e307cf138..ca3bb53d49 100644 --- a/hal/src/main/java/edu/wpi/first/wpilibj/sim/CallbackStore.java +++ b/hal/src/main/java/edu/wpi/first/wpilibj/sim/CallbackStore.java @@ -7,9 +7,7 @@ package edu.wpi.first.wpilibj.sim; -import java.io.Closeable; - -public class CallbackStore implements Closeable { +public class CallbackStore implements AutoCloseable { interface CancelCallbackFunc { void cancel(int index, int uid); } diff --git a/ntcore/src/main/java/edu/wpi/first/networktables/NetworkTableInstance.java b/ntcore/src/main/java/edu/wpi/first/networktables/NetworkTableInstance.java index 2c82a67cfd..758902aca1 100644 --- a/ntcore/src/main/java/edu/wpi/first/networktables/NetworkTableInstance.java +++ b/ntcore/src/main/java/edu/wpi/first/networktables/NetworkTableInstance.java @@ -34,7 +34,7 @@ import java.util.function.Consumer; * A reference must be kept to the NetworkTableInstance returned by this * function to keep it from being garbage collected. */ -public final class NetworkTableInstance { +public final class NetworkTableInstance implements AutoCloseable { /** * Client/server mode flag values (as returned by {@link #getNetworkMode()}). * This is a bitmask. @@ -59,10 +59,16 @@ public final class NetworkTableInstance { m_handle = handle; } + @Deprecated + public void free() { + close(); + } + /** * Destroys the instance (if created by {@link #create()}). */ - public synchronized void free() { + @Override + public synchronized void close() { if (m_owned && m_handle != 0) { NetworkTablesJNI.destroyInstance(m_handle); } diff --git a/ntcore/src/main/java/edu/wpi/first/networktables/RpcAnswer.java b/ntcore/src/main/java/edu/wpi/first/networktables/RpcAnswer.java index 0879563cf9..03c6fca4fb 100644 --- a/ntcore/src/main/java/edu/wpi/first/networktables/RpcAnswer.java +++ b/ntcore/src/main/java/edu/wpi/first/networktables/RpcAnswer.java @@ -10,7 +10,7 @@ package edu.wpi.first.networktables; /** * NetworkTables Remote Procedure Call (Server Side). */ -public final class RpcAnswer { +public final class RpcAnswer implements AutoCloseable { /** Entry handle. */ public final int entry; @@ -46,10 +46,16 @@ public final class RpcAnswer { static final byte[] emptyResponse = new byte[] {}; + @Deprecated + public void free() { + close(); + } + /** * Posts an empty response if one was not previously sent. */ - public synchronized void free() { + @Override + public synchronized void close() { if (call != 0) { postResponse(emptyResponse); } diff --git a/ntcore/src/main/java/edu/wpi/first/networktables/RpcCall.java b/ntcore/src/main/java/edu/wpi/first/networktables/RpcCall.java index 6ce4fe2413..d2a37cb9ba 100644 --- a/ntcore/src/main/java/edu/wpi/first/networktables/RpcCall.java +++ b/ntcore/src/main/java/edu/wpi/first/networktables/RpcCall.java @@ -10,7 +10,7 @@ package edu.wpi.first.networktables; /** * NetworkTables Remote Procedure Call. */ -public final class RpcCall { +public final class RpcCall implements AutoCloseable{ /** Constructor. * This should generally only be used internally to NetworkTables. * @param entry Entry @@ -21,10 +21,16 @@ public final class RpcCall { m_call = call; } + @Deprecated + public void free() { + close(); + } + /** * Cancels the result if no other action taken. */ - public synchronized void free() { + @Override + public synchronized void close() { if (m_call != 0) { cancelResult(); } diff --git a/ntcore/src/test/java/edu/wpi/first/networktables/ConnectionListenerTest.java b/ntcore/src/test/java/edu/wpi/first/networktables/ConnectionListenerTest.java index 08f3aa798a..10033af05d 100644 --- a/ntcore/src/test/java/edu/wpi/first/networktables/ConnectionListenerTest.java +++ b/ntcore/src/test/java/edu/wpi/first/networktables/ConnectionListenerTest.java @@ -26,8 +26,8 @@ public class ConnectionListenerTest extends TestCase { @Override protected void tearDown() throws Exception { - clientInst.free(); - serverInst.free(); + clientInst.close(); + serverInst.close(); } private void connect() { diff --git a/ntcore/src/test/java/edu/wpi/first/networktables/EntryListenerTest.java b/ntcore/src/test/java/edu/wpi/first/networktables/EntryListenerTest.java index 141ce1b6fd..18b992a1f3 100644 --- a/ntcore/src/test/java/edu/wpi/first/networktables/EntryListenerTest.java +++ b/ntcore/src/test/java/edu/wpi/first/networktables/EntryListenerTest.java @@ -26,8 +26,8 @@ public class EntryListenerTest extends TestCase { @Override protected void tearDown() throws Exception { - clientInst.free(); - serverInst.free(); + clientInst.close(); + serverInst.close(); } private void connect() { diff --git a/ntcore/src/test/java/edu/wpi/first/networktables/LoggerTest.java b/ntcore/src/test/java/edu/wpi/first/networktables/LoggerTest.java index d67a18350d..d02b2afc76 100644 --- a/ntcore/src/test/java/edu/wpi/first/networktables/LoggerTest.java +++ b/ntcore/src/test/java/edu/wpi/first/networktables/LoggerTest.java @@ -21,7 +21,7 @@ public class LoggerTest extends TestCase { @Override protected void tearDown() throws Exception { - clientInst.free(); + clientInst.close(); } public void testLogger() { diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/ADXL345_I2C.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/ADXL345_I2C.java index ea21f8130c..d7994550d8 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/ADXL345_I2C.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/ADXL345_I2C.java @@ -93,9 +93,9 @@ public class ADXL345_I2C extends SensorBase implements Accelerometer, Sendable { } @Override - public void free() { - super.free(); - m_i2c.free(); + public void close() { + super.close(); + m_i2c.close(); } @Override diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/ADXL345_SPI.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/ADXL345_SPI.java index c6a0185cfb..429a017777 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/ADXL345_SPI.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/ADXL345_SPI.java @@ -79,9 +79,9 @@ public class ADXL345_SPI extends SensorBase implements Accelerometer, Sendable { } @Override - public void free() { - super.free(); - m_spi.free(); + public void close() { + super.close(); + m_spi.close(); } /** diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/ADXL362.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/ADXL362.java index 5bb8461842..aebdd66f79 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/ADXL362.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/ADXL362.java @@ -93,7 +93,7 @@ public class ADXL362 extends SensorBase implements Accelerometer, Sendable { transferBuffer.put(1, kPartIdRegister); m_spi.transaction(transferBuffer, transferBuffer, 3); if (transferBuffer.get(2) != (byte) 0xF2) { - m_spi.free(); + m_spi.close(); m_spi = null; DriverStation.reportError("could not find ADXL362 on SPI port " + port.value, false); return; @@ -112,10 +112,10 @@ public class ADXL362 extends SensorBase implements Accelerometer, Sendable { } @Override - public void free() { - super.free(); + public void close() { + super.close(); if (m_spi != null) { - m_spi.free(); + m_spi.close(); m_spi = null; } } 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 1eaec6c0c2..a27db2a04f 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 @@ -64,7 +64,7 @@ public class ADXRS450_Gyro extends GyroBase implements Gyro, PIDSource, Sendable // Validate the part ID if ((readRegister(kPIDRegister) & 0xff00) != 0x5200) { - m_spi.free(); + m_spi.close(); m_spi = null; DriverStation.reportError("could not find ADXRS450 gyro on SPI port " + port.value, false); @@ -141,10 +141,10 @@ public class ADXRS450_Gyro extends GyroBase implements Gyro, PIDSource, Sendable * Delete (free) the spi port used for the gyro and stop accumulating. */ @Override - public void free() { - super.free(); + public void close() { + super.close(); if (m_spi != null) { - m_spi.free(); + m_spi.close(); m_spi = null; } } diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/AnalogAccelerometer.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/AnalogAccelerometer.java index a7c2c82d75..f5fc17e648 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/AnalogAccelerometer.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/AnalogAccelerometer.java @@ -67,10 +67,10 @@ public class AnalogAccelerometer extends SensorBase implements PIDSource, Sendab * Delete the analog components used for the accelerometer. */ @Override - public void free() { - super.free(); + public void close() { + super.close(); if (m_analogChannel != null && m_allocatedChannel) { - m_analogChannel.free(); + m_analogChannel.close(); } m_analogChannel = null; } diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/AnalogGyro.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/AnalogGyro.java index b03fa9985c..9decb29986 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/AnalogGyro.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/AnalogGyro.java @@ -119,10 +119,10 @@ public class AnalogGyro extends GyroBase implements Gyro, PIDSource, Sendable { * Delete (free) the accumulator and the analog components used for the gyro. */ @Override - public void free() { - super.free(); + public void close() { + super.close(); if (m_analog != null && m_channelAllocated) { - m_analog.free(); + m_analog.close(); } m_analog = null; AnalogGyroJNI.freeAnalogGyro(m_gyroHandle); diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/AnalogInput.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/AnalogInput.java index bd2ba2e9bf..cb902e5e73 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/AnalogInput.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/AnalogInput.java @@ -54,8 +54,8 @@ public class AnalogInput extends SensorBase implements PIDSource, Sendable { * Channel destructor. */ @Override - public void free() { - super.free(); + public void close() { + super.close(); AnalogJNI.freeAnalogInputPort(m_port); m_port = 0; m_channel = 0; diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/AnalogOutput.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/AnalogOutput.java index 258fa34529..4d0783a805 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/AnalogOutput.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/AnalogOutput.java @@ -40,8 +40,8 @@ public class AnalogOutput extends SendableBase implements Sendable { * Channel destructor. */ @Override - public void free() { - super.free(); + public void close() { + super.close(); AnalogJNI.freeAnalogOutputPort(m_port); m_port = 0; m_channel = 0; diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/AnalogPotentiometer.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/AnalogPotentiometer.java index d2ae80b1ac..4c2e136681 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/AnalogPotentiometer.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/AnalogPotentiometer.java @@ -158,10 +158,10 @@ public class AnalogPotentiometer extends SensorBase implements Potentiometer, Se * Frees this resource. */ @Override - public void free() { - super.free(); + public void close() { + super.close(); if (m_initAnalogInput) { - m_analogInput.free(); + m_analogInput.close(); m_analogInput = null; m_initAnalogInput = false; } diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/AnalogTrigger.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/AnalogTrigger.java index f7f7c1ef71..090c24d297 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/AnalogTrigger.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/AnalogTrigger.java @@ -78,12 +78,12 @@ public class AnalogTrigger extends SensorBase implements Sendable { * Release the resources used by this object. */ @Override - public void free() { - super.free(); + public void close() { + super.close(); AnalogJNI.cleanAnalogTrigger(m_port); m_port = 0; if (m_ownsAnalog && m_analogInput != null) { - m_analogInput.free(); + m_analogInput.close(); } } diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/Counter.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/Counter.java index e0ae1e4a6c..c059190b15 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/Counter.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/Counter.java @@ -180,8 +180,8 @@ public class Counter extends SensorBase implements CounterBase, Sendable, PIDSou } @Override - public void free() { - super.free(); + public void close() { + super.close(); setUpdateWhenEmpty(true); clearUpSource(); @@ -222,7 +222,7 @@ public class Counter extends SensorBase implements CounterBase, Sendable, PIDSou */ public void setUpSource(DigitalSource source) { if (m_upSource != null && m_allocatedUpSource) { - m_upSource.free(); + m_upSource.close(); m_allocatedUpSource = false; } m_upSource = source; @@ -263,7 +263,7 @@ public class Counter extends SensorBase implements CounterBase, Sendable, PIDSou */ public void clearUpSource() { if (m_upSource != null && m_allocatedUpSource) { - m_upSource.free(); + m_upSource.close(); m_allocatedUpSource = false; } m_upSource = null; @@ -292,7 +292,7 @@ public class Counter extends SensorBase implements CounterBase, Sendable, PIDSou requireNonNull(source, "The Digital Source given was null"); if (m_downSource != null && m_allocatedDownSource) { - m_downSource.free(); + m_downSource.close(); m_allocatedDownSource = false; } CounterJNI.setCounterDownSource(m_counter, source.getPortHandleForRouting(), @@ -332,7 +332,7 @@ public class Counter extends SensorBase implements CounterBase, Sendable, PIDSou */ public void clearDownSource() { if (m_downSource != null && m_allocatedDownSource) { - m_downSource.free(); + m_downSource.close(); m_allocatedDownSource = false; } m_downSource = null; diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/DigitalGlitchFilter.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/DigitalGlitchFilter.java index 2082647433..ad4a6173ba 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/DigitalGlitchFilter.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/DigitalGlitchFilter.java @@ -43,8 +43,8 @@ public class DigitalGlitchFilter extends SensorBase { /** * Free the resources used by this object. */ - public void free() { - super.free(); + public void close() { + super.close(); if (m_channelIndex >= 0) { synchronized (m_mutex) { m_filterAllocated[m_channelIndex] = false; diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/DigitalInput.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/DigitalInput.java index b6d57c3d73..b4da7ef667 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/DigitalInput.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/DigitalInput.java @@ -40,8 +40,8 @@ public class DigitalInput extends DigitalSource implements Sendable { /** * Frees the resources for this output. */ - public void free() { - super.free(); + public void close() { + super.close(); if (m_interrupt != 0) { cancelInterrupts(); } diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/DigitalOutput.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/DigitalOutput.java index 0df04216a6..b2cdccfe76 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/DigitalOutput.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/DigitalOutput.java @@ -44,8 +44,8 @@ public class DigitalOutput extends SendableBase implements Sendable { * Free the resources associated with a digital output. */ @Override - public void free() { - super.free(); + public void close() { + super.close(); // disable the pwm only if we have allocated it if (m_pwmGenerator != invalidPwmGenerator) { disablePWM(); diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/DoubleSolenoid.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/DoubleSolenoid.java index 9f4207abc7..521d3af350 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/DoubleSolenoid.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/DoubleSolenoid.java @@ -86,11 +86,10 @@ public class DoubleSolenoid extends SolenoidBase implements Sendable { * Destructor. */ @Override - public synchronized void free() { - super.free(); + public synchronized void close() { + super.close(); SolenoidJNI.freeSolenoidPort(m_forwardHandle); SolenoidJNI.freeSolenoidPort(m_reverseHandle); - super.free(); } /** diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/Encoder.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/Encoder.java index 93d70f1e82..93a862834f 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/Encoder.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/Encoder.java @@ -294,18 +294,18 @@ public class Encoder extends SensorBase implements CounterBase, PIDSource, Senda * Free the resources used by this object. */ @Override - public void free() { - super.free(); + public void close() { + super.close(); if (m_aSource != null && m_allocatedA) { - m_aSource.free(); + m_aSource.close(); m_allocatedA = false; } if (m_bSource != null && m_allocatedB) { - m_bSource.free(); + m_bSource.close(); m_allocatedB = false; } if (m_indexSource != null && m_allocatedI) { - m_indexSource.free(); + m_indexSource.close(); m_allocatedI = false; } diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/I2C.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/I2C.java index 7c76ac9a7d..37f442571a 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/I2C.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/I2C.java @@ -22,7 +22,7 @@ import static java.util.Objects.requireNonNull; *

This class is intended to be used by sensor (and other I2C device) drivers. It probably should * not be used directly. */ -public class I2C { +public class I2C implements AutoCloseable { public enum Port { kOnboard(0), kMXP(1); @@ -52,10 +52,16 @@ public class I2C { HAL.report(tResourceType.kResourceType_I2C, deviceAddress); } + @Deprecated + public void free() { + close(); + } + /** * Destructor. */ - public void free() { + @Override + public void close() { I2CJNI.i2CClose(m_port); } diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/InterruptableSensorBase.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/InterruptableSensorBase.java index f690d3a745..29008f731b 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/InterruptableSensorBase.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/InterruptableSensorBase.java @@ -48,8 +48,8 @@ public abstract class InterruptableSensorBase extends SensorBase { * Frees the resources for this output. */ @Override - public void free() { - super.free(); + public void close() { + super.close(); if (m_interrupt != 0) { cancelInterrupts(); } diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/NidecBrushless.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/NidecBrushless.java index 427cb5948f..198e64e42e 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/NidecBrushless.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/NidecBrushless.java @@ -53,10 +53,10 @@ public class NidecBrushless extends SendableBase implements SpeedController, Mot * Free the resources used by this object. */ @Override - public void free() { - super.free(); - m_dio.free(); - m_pwm.free(); + public void close() { + super.close(); + m_dio.close(); + m_pwm.close(); } /** diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/PIDController.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/PIDController.java index 20c0622de0..f6c768cbb5 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/PIDController.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/PIDController.java @@ -92,8 +92,8 @@ public class PIDController extends PIDBase implements Controller { * Free the PID object. */ @Override - public void free() { - super.free(); + public void close() { + super.close(); m_controlLoop.stop(); m_thisMutex.lock(); try { diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/PWM.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/PWM.java index 4f6a98c967..d8d09a45c2 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/PWM.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/PWM.java @@ -71,8 +71,8 @@ public class PWM extends SendableBase implements Sendable { *

Free the resource associated with the PWM channel and set the value to 0. */ @Override - public void free() { - super.free(); + public void close() { + super.close(); if (m_handle == 0) { return; } diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/Relay.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/Relay.java index 25323f0ee3..af5e6ee605 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/Relay.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/Relay.java @@ -141,8 +141,8 @@ public class Relay extends SendableBase implements MotorSafety, Sendable { } @Override - public void free() { - super.free(); + public void close() { + super.close(); freeRelay(); } diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/RobotBase.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/RobotBase.java index ade0e07308..b80d48f36a 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/RobotBase.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/RobotBase.java @@ -32,7 +32,7 @@ import edu.wpi.first.wpilibj.util.WPILibVersion; * run to completion before the OperatorControl code could start. In the future the Autonomous code * might be spawned as a task, then killed at the end of the Autonomous period. */ -public abstract class RobotBase { +public abstract class RobotBase implements AutoCloseable { /** * The ID of the main Java thread. */ @@ -93,10 +93,15 @@ public abstract class RobotBase { LiveWindow.setEnabled(false); } + @Deprecated + public void free() { + } + /** * Free the resources for a RobotBase class. */ - public void free() { + @Override + public void close() { } /** diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/RobotDrive.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/RobotDrive.java index b47e3e157e..8c69eff9b7 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/RobotDrive.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/RobotDrive.java @@ -25,7 +25,7 @@ import static java.util.Objects.requireNonNull; * or {@link edu.wpi.first.wpilibj.drive.MecanumDrive} classes instead. */ @Deprecated -public class RobotDrive implements MotorSafety { +public class RobotDrive implements MotorSafety, AutoCloseable { protected MotorSafetyHelper m_safetyHelper; /** @@ -662,22 +662,28 @@ public class RobotDrive implements MotorSafety { m_maxOutput = maxOutput; } + @Deprecated + public void free() { + close(); + } + /** * Free the speed controllers if they were allocated locally. */ - public void free() { + @Override + public void close() { if (m_allocatedSpeedControllers) { if (m_frontLeftMotor != null) { - ((PWM) m_frontLeftMotor).free(); + ((PWM) m_frontLeftMotor).close(); } if (m_frontRightMotor != null) { - ((PWM) m_frontRightMotor).free(); + ((PWM) m_frontRightMotor).close(); } if (m_rearLeftMotor != null) { - ((PWM) m_rearLeftMotor).free(); + ((PWM) m_rearLeftMotor).close(); } if (m_rearRightMotor != null) { - ((PWM) m_rearRightMotor).free(); + ((PWM) m_rearRightMotor).close(); } } } diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/SPI.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/SPI.java index 3ee373930d..b882f9be92 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/SPI.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/SPI.java @@ -16,7 +16,7 @@ import edu.wpi.first.wpilibj.hal.SPIJNI; /** * Represents a SPI bus port. */ -public class SPI { +public class SPI implements AutoCloseable { public enum Port { kOnboardCS0(0), kOnboardCS1(1), kOnboardCS2(2), kOnboardCS3(3), kMXP(4); @@ -49,12 +49,19 @@ public class SPI { HAL.report(tResourceType.kResourceType_SPI, devices); } + + @Deprecated + public void free() { + close(); + } + /** * Free the resources used by this object. */ - public void free() { + @Override + public void close() { if (m_accum != null) { - m_accum.free(); + m_accum.close(); m_accum = null; } SPIJNI.spiClose(m_port); @@ -416,7 +423,7 @@ public class SPI { private static final int kAccumulateDepth = 2048; - private static class Accumulator { + private static class Accumulator implements AutoCloseable { Accumulator(int port, int xferSize, int validMask, int validValue, int dataShift, int dataSize, boolean isSigned, boolean bigEndian) { m_notifier = new Notifier(this::update); @@ -432,7 +439,8 @@ public class SPI { m_port = port; } - void free() { + @Override + public void close() { m_notifier.stop(); } @@ -570,7 +578,7 @@ public class SPI { */ public void freeAccumulator() { if (m_accum != null) { - m_accum.free(); + m_accum.close(); m_accum = null; } freeAuto(); diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/SendableBase.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/SendableBase.java index ffa64ffc9f..8937c408c2 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/SendableBase.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/SendableBase.java @@ -13,7 +13,7 @@ import edu.wpi.first.wpilibj.livewindow.LiveWindow; * Base class for all sensors. Stores most recent status information as well as containing utility * functions for checking channels and error processing. */ -public abstract class SendableBase implements Sendable { +public abstract class SendableBase implements Sendable, AutoCloseable { private String m_name = ""; private String m_subsystem = "Ungrouped"; @@ -35,10 +35,16 @@ public abstract class SendableBase implements Sendable { } } + @Deprecated + public void free() { + close(); + } + /** * Free the resources used by this object. */ - public void free() { + @Override + public void close() { LiveWindow.remove(this); } diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/SerialPort.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/SerialPort.java index fabff3f474..c2bbaf53a2 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/SerialPort.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/SerialPort.java @@ -197,7 +197,7 @@ public class SerialPort { /** * Destructor. */ - public void free() { + public void close() { SerialPortJNI.serialClose(m_port); } diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/Solenoid.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/Solenoid.java index a50c5fc161..c61e140ebb 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/Solenoid.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/Solenoid.java @@ -55,8 +55,8 @@ public class Solenoid extends SolenoidBase implements Sendable { * Destructor. */ @Override - public synchronized void free() { - super.free(); + public synchronized void close() { + super.close(); SolenoidJNI.freeSolenoidPort(m_solenoidHandle); m_solenoidHandle = 0; } diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/Ultrasonic.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/Ultrasonic.java index a89f088db7..3ebb8a0b27 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/Ultrasonic.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/Ultrasonic.java @@ -191,21 +191,21 @@ public class Ultrasonic extends SensorBase implements PIDSource, Sendable { * sensor). */ @Override - public synchronized void free() { - super.free(); + public synchronized void close() { + super.close(); final boolean wasAutomaticMode = m_automaticEnabled; setAutomaticMode(false); if (m_allocatedChannels) { if (m_pingChannel != null) { - m_pingChannel.free(); + m_pingChannel.close(); } if (m_echoChannel != null) { - m_echoChannel.free(); + m_echoChannel.close(); } } if (m_counter != null) { - m_counter.free(); + m_counter.close(); m_counter = null; } diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/interfaces/Gyro.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/interfaces/Gyro.java index 42774256b7..a752d6ed72 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/interfaces/Gyro.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/interfaces/Gyro.java @@ -10,7 +10,7 @@ package edu.wpi.first.wpilibj.interfaces; /** * Interface for yaw rate gyros. */ -public interface Gyro { +public interface Gyro extends AutoCloseable { /** * Calibrate the gyro by running for a number of samples and computing the center value. Then use * the center value as the Accumulator center value for subsequent measurements. It's important to @@ -52,5 +52,12 @@ public interface Gyro { /** * Free the resources used by the gyro. */ + @Deprecated void free(); + + /** + * Free the resources used by the gyro. + */ + @Override + void close(); } diff --git a/wpilibj/src/test/java/edu/wpi/first/wpilibj/PIDToleranceTest.java b/wpilibj/src/test/java/edu/wpi/first/wpilibj/PIDToleranceTest.java index 1da0c9f14b..fe79ffccf8 100644 --- a/wpilibj/src/test/java/edu/wpi/first/wpilibj/PIDToleranceTest.java +++ b/wpilibj/src/test/java/edu/wpi/first/wpilibj/PIDToleranceTest.java @@ -66,7 +66,7 @@ public class PIDToleranceTest { @After public void tearDown() throws Exception { - m_pid.free(); + m_pid.close(); m_pid = null; } diff --git a/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/AnalogCrossConnectTest.java b/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/AnalogCrossConnectTest.java index 6ccff8c79a..2c680a2e0d 100644 --- a/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/AnalogCrossConnectTest.java +++ b/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/AnalogCrossConnectTest.java @@ -78,7 +78,7 @@ public class AnalogCrossConnectTest extends AbstractInterruptTest { assertFalse("Analog trigger is in the window (2V, 3V)", trigger.getInWindow()); assertFalse("Analog trigger is on", trigger.getTriggerState()); - trigger.free(); + trigger.close(); } @Test @@ -95,7 +95,7 @@ public class AnalogCrossConnectTest extends AbstractInterruptTest { assertTrue("Analog trigger is not in the window (2V, 3V)", trigger.getInWindow()); assertFalse("Analog trigger is on", trigger.getTriggerState()); - trigger.free(); + trigger.close(); } @Test @@ -112,7 +112,7 @@ public class AnalogCrossConnectTest extends AbstractInterruptTest { assertFalse("Analog trigger is in the window (2V, 3V)", trigger.getInWindow()); assertTrue("Analog trigger is not on", trigger.getTriggerState()); - trigger.free(); + trigger.close(); } @Test @@ -167,9 +167,9 @@ public class AnalogCrossConnectTest extends AbstractInterruptTest { @Override void freeInterruptableSensorBase() { m_interruptTriggerOutput.cancelInterrupts(); - m_interruptTriggerOutput.free(); + m_interruptTriggerOutput.close(); m_interruptTriggerOutput = null; - m_interruptTrigger.free(); + m_interruptTrigger.close(); m_interruptTrigger = null; } diff --git a/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/AnalogPotentiometerTest.java b/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/AnalogPotentiometerTest.java index dce2ac80e7..1af02f0605 100644 --- a/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/AnalogPotentiometerTest.java +++ b/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/AnalogPotentiometerTest.java @@ -42,7 +42,7 @@ public class AnalogPotentiometerTest extends AbstractComsSetup { @After public void tearDown() throws Exception { m_potSource.reset(); - m_pot.free(); + m_pot.close(); m_analogIO.teardown(); } diff --git a/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/DigitalGlitchFilterTest.java b/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/DigitalGlitchFilterTest.java index e3e1569132..2b91208546 100644 --- a/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/DigitalGlitchFilterTest.java +++ b/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/DigitalGlitchFilterTest.java @@ -69,14 +69,14 @@ public class DigitalGlitchFilterTest extends AbstractComsSetup { filter3.remove(encoder5); filter3.remove(counter7); - input1.free(); - input2.free(); - input3.free(); - input4.free(); - encoder5.free(); - counter7.free(); - filter1.free(); - filter2.free(); - filter3.free(); + input1.close(); + input2.close(); + input3.close(); + input4.close(); + encoder5.close(); + counter7.close(); + filter1.close(); + filter2.close(); + filter3.close(); } } diff --git a/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/MotorEncoderTest.java b/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/MotorEncoderTest.java index fa1b5868c3..f41096f1de 100644 --- a/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/MotorEncoderTest.java +++ b/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/MotorEncoderTest.java @@ -189,7 +189,7 @@ public class MotorEncoderTest extends AbstractComsSetup { "PID loop did not reach setpoint within 10 seconds. The current error was" + pid .getError(), pid.onTarget()); - pid.free(); + pid.close(); } @Test @@ -210,7 +210,7 @@ public class MotorEncoderTest extends AbstractComsSetup { "PID loop did not reach setpoint within 10 seconds. The error was: " + pid.getError(), pid.onTarget()); - pid.free(); + pid.close(); } /** diff --git a/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/PCMTest.java b/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/PCMTest.java index 4a0eae039b..4e05a9cbb0 100644 --- a/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/PCMTest.java +++ b/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/PCMTest.java @@ -63,13 +63,13 @@ public class PCMTest extends AbstractComsSetup { @AfterClass public static void tearDownAfterClass() throws Exception { - compressor.free(); + compressor.close(); - fakePressureSwitch.free(); - fakeCompressor.free(); + fakePressureSwitch.close(); + fakeCompressor.close(); - fakeSolenoid1.free(); - fakeSolenoid2.free(); + fakeSolenoid1.close(); + fakeSolenoid2.close(); } @Before @@ -145,8 +145,8 @@ public class PCMTest extends AbstractComsSetup { assertTrue("Solenoid #1 did not report on", solenoid1.get()); assertTrue("Solenoid #2 did not report on", solenoid2.get()); - solenoid1.free(); - solenoid2.free(); + solenoid1.close(); + solenoid2.close(); } /** @@ -177,7 +177,7 @@ public class PCMTest extends AbstractComsSetup { assertTrue("DoubleSolenoid did not report Reverse", solenoid.get() == DoubleSolenoid.Value .kReverse); - solenoid.free(); + solenoid.close(); } /** @@ -265,8 +265,8 @@ public class PCMTest extends AbstractComsSetup { assertFalse("Solenoid #1 did not report off", solenoid1.get()); assertFalse("Solenoid #2 did not report off", solenoid2.get()); - solenoid1.free(); - solenoid2.free(); + solenoid1.close(); + solenoid2.close(); } protected Logger getClassLogger() { diff --git a/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/PDPTest.java b/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/PDPTest.java index 22e42efcb0..e00c7001b8 100644 --- a/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/PDPTest.java +++ b/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/PDPTest.java @@ -47,7 +47,7 @@ public class PDPTest extends AbstractComsSetup { @AfterClass public static void tearDownAfterClass() throws Exception { - pdp.free(); + pdp.close(); pdp = null; me.teardown(); me = null; diff --git a/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/PIDTest.java b/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/PIDTest.java index f9120b4e1f..35f5064b17 100644 --- a/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/PIDTest.java +++ b/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/PIDTest.java @@ -116,7 +116,7 @@ public class PIDTest extends AbstractComsSetup { public void tearDown() throws Exception { logger.fine("Teardown: " + me.getType()); m_controller.disable(); - m_controller.free(); + m_controller.close(); m_controller = null; me.reset(); } diff --git a/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/fixtures/AnalogCrossConnectFixture.java b/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/fixtures/AnalogCrossConnectFixture.java index f14ceaaaa9..ece1dc93f8 100644 --- a/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/fixtures/AnalogCrossConnectFixture.java +++ b/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/fixtures/AnalogCrossConnectFixture.java @@ -64,8 +64,8 @@ public abstract class AnalogCrossConnectFixture implements ITestFixture { */ @Override public boolean teardown() { - m_input.free(); - m_output.free(); + m_input.close(); + m_output.close(); return true; } diff --git a/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/fixtures/DIOCrossConnectFixture.java b/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/fixtures/DIOCrossConnectFixture.java index de77fb973e..ade9e69e84 100644 --- a/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/fixtures/DIOCrossConnectFixture.java +++ b/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/fixtures/DIOCrossConnectFixture.java @@ -80,8 +80,8 @@ public class DIOCrossConnectFixture implements ITestFixture { public boolean teardown() { logger.log(Level.FINE, "Begining teardown"); if (m_allocated) { - m_input.free(); - m_output.free(); + m_input.close(); + m_output.close(); m_allocated = false; } return true; diff --git a/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/fixtures/FakeCounterFixture.java b/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/fixtures/FakeCounterFixture.java index bff0e4c431..a944421722 100644 --- a/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/fixtures/FakeCounterFixture.java +++ b/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/fixtures/FakeCounterFixture.java @@ -99,8 +99,8 @@ public class FakeCounterFixture implements ITestFixture { @Override public boolean teardown() { logger.log(Level.FINE, "Begining teardown"); - m_counter.free(); - m_source.free(); + m_counter.close(); + m_source.close(); if (m_allocated) { // Only tear down the dio if this class allocated it m_dio.teardown(); m_allocated = false; diff --git a/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/fixtures/FakeEncoderFixture.java b/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/fixtures/FakeEncoderFixture.java index 372b2d80fa..2b2b852af6 100644 --- a/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/fixtures/FakeEncoderFixture.java +++ b/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/fixtures/FakeEncoderFixture.java @@ -101,9 +101,9 @@ public class FakeEncoderFixture implements ITestFixture { @Override public boolean teardown() { logger.fine("Begining teardown"); - m_source.free(); + m_source.close(); logger.finer("Source freed " + m_sourcePort[0] + ", " + m_sourcePort[1]); - m_encoder.free(); + m_encoder.close(); logger.finer("Encoder freed " + m_encoderPort[0] + ", " + m_encoderPort[1]); if (m_allocated) { m_dio1.teardown(); diff --git a/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/fixtures/MotorEncoderFixture.java b/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/fixtures/MotorEncoderFixture.java index 0a78583526..fab33060ad 100644 --- a/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/fixtures/MotorEncoderFixture.java +++ b/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/fixtures/MotorEncoderFixture.java @@ -181,37 +181,37 @@ public abstract class MotorEncoderFixture implements if (!m_tornDown) { boolean wasNull = false; if (m_motor instanceof PWM && m_motor != null) { - ((PWM) m_motor).free(); + ((PWM) m_motor).close(); m_motor = null; } else if (m_motor == null) { wasNull = true; } if (m_encoder != null) { - m_encoder.free(); + m_encoder.close(); m_encoder = null; } else { wasNull = true; } if (m_counters[0] != null) { - m_counters[0].free(); + m_counters[0].close(); m_counters[0] = null; } else { wasNull = true; } if (m_counters[1] != null) { - m_counters[1].free(); + m_counters[1].close(); m_counters[1] = null; } else { wasNull = true; } if (m_alphaSource != null) { - m_alphaSource.free(); + m_alphaSource.close(); m_alphaSource = null; } else { wasNull = true; } if (m_betaSource != null) { - m_betaSource.free(); + m_betaSource.close(); m_betaSource = null; } else { wasNull = true; diff --git a/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/fixtures/RelayCrossConnectFixture.java b/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/fixtures/RelayCrossConnectFixture.java index ee19c9a2ee..382b4bb304 100644 --- a/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/fixtures/RelayCrossConnectFixture.java +++ b/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/fixtures/RelayCrossConnectFixture.java @@ -84,9 +84,9 @@ public abstract class RelayCrossConnectFixture implements ITestFixture { @Override public boolean teardown() { if (!m_freed) { - m_relay.free(); - m_inputOne.free(); - m_inputTwo.free(); + m_relay.close(); + m_inputOne.close(); + m_inputTwo.close(); m_freed = true; } else { throw new RuntimeException("You attempted to free the " diff --git a/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/fixtures/TiltPanCameraFixture.java b/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/fixtures/TiltPanCameraFixture.java index 096c5592d6..afeaf38ec4 100644 --- a/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/fixtures/TiltPanCameraFixture.java +++ b/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/fixtures/TiltPanCameraFixture.java @@ -92,22 +92,22 @@ public abstract class TiltPanCameraFixture implements ITestFixture { } public void freeGyro() { - m_gyro.free(); + m_gyro.close(); m_gyro = null; } @Override public boolean teardown() { - m_tilt.free(); + m_tilt.close(); m_tilt = null; - m_pan.free(); + m_pan.close(); m_pan = null; if (m_gyro != null) { //in case not freed during gyro tests - m_gyro.free(); + m_gyro.close(); m_gyro = null; } if (m_gyroParam != null) { //in case gyro tests failed before getting to this point - m_gyroParam.free(); + m_gyroParam.close(); m_gyroParam = null; } return true; diff --git a/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/mockhardware/FakeCounterSource.java b/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/mockhardware/FakeCounterSource.java index a3fc9386ec..b82cb41973 100644 --- a/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/mockhardware/FakeCounterSource.java +++ b/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/mockhardware/FakeCounterSource.java @@ -13,7 +13,7 @@ import edu.wpi.first.wpilibj.Timer; /** * Simulates an encoder for testing purposes. */ -public class FakeCounterSource { +public class FakeCounterSource implements AutoCloseable { private Thread m_task; private int m_count; private int m_milliSec; @@ -70,10 +70,10 @@ public class FakeCounterSource { /** * Destroy Object with minimum memory leak. */ - public void free() { + public void close() { m_task = null; if (m_allocated) { - m_output.free(); + m_output.close(); m_output = null; m_allocated = false; } diff --git a/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/mockhardware/FakeEncoderSource.java b/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/mockhardware/FakeEncoderSource.java index 934d19d82f..dc85ec2ed3 100644 --- a/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/mockhardware/FakeEncoderSource.java +++ b/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/mockhardware/FakeEncoderSource.java @@ -13,7 +13,7 @@ import edu.wpi.first.wpilibj.Timer; /** * Emulates a quadrature encoder. */ -public class FakeEncoderSource { +public class FakeEncoderSource implements AutoCloseable { private Thread m_task; private int m_count; private int m_milliSec; @@ -93,11 +93,11 @@ public class FakeEncoderSource { /** * Frees the resource. */ - public void free() { + public void close() { m_task = null; if (m_allocatedOutputs) { - m_outputA.free(); - m_outputB.free(); + m_outputA.close(); + m_outputB.close(); } } diff --git a/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/mockhardware/FakePotentiometerSource.java b/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/mockhardware/FakePotentiometerSource.java index 397baa8ce0..13306d366c 100644 --- a/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/mockhardware/FakePotentiometerSource.java +++ b/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/mockhardware/FakePotentiometerSource.java @@ -12,7 +12,7 @@ import edu.wpi.first.wpilibj.AnalogOutput; /** * A fake source to provide output to a {@link edu.wpi.first.wpilibj.interfaces.Potentiometer}. */ -public class FakePotentiometerSource { +public class FakePotentiometerSource implements AutoCloseable { private AnalogOutput m_output; private boolean m_initOutput; private double m_potMaxAngle; @@ -83,9 +83,9 @@ public class FakePotentiometerSource { /** * Frees the resouce. */ - public void free() { + public void close() { if (m_initOutput) { - m_output.free(); + m_output.close(); m_output = null; m_initOutput = false; }