diff --git a/src/main/java/org/lasarobotics/hardware/Compressor.java b/src/main/java/org/lasarobotics/hardware/Compressor.java index bb1dd657..56a50ded 100644 --- a/src/main/java/org/lasarobotics/hardware/Compressor.java +++ b/src/main/java/org/lasarobotics/hardware/Compressor.java @@ -5,11 +5,10 @@ package org.lasarobotics.hardware; import org.littletonrobotics.junction.AutoLog; -import org.littletonrobotics.junction.Logger; import edu.wpi.first.wpilibj.PneumaticsModuleType; -public class Compressor implements LoggableHardware { +public class Compressor implements LoggableHardware, AutoCloseable { /** Compressor ID */ public static class ID { public final String name; @@ -28,6 +27,8 @@ public ID(String name, PneumaticsModuleType moduleType) { @AutoLog public static class CompressorInputs { + boolean isEnabled = false; + boolean digitalPressure = false; double analogPressure = 0.0; } @@ -49,18 +50,14 @@ public Compressor(Compressor.ID id, int module) { } /** - * Create a Solenoid object with built-in logging - * @param id Solenoid ID + * Create a Compressor object with built-in logging + * @param id Compressor ID */ public Compressor(Compressor.ID id) { this.m_id = id; this.m_compressor = new edu.wpi.first.wpilibj.Compressor(m_id.moduleType); } - private void logOutputs(boolean value) { - Logger.recordOutput(m_id.name + VALUE_LOG_ENTRY, value); - } - /** * If supported by the device, returns the pressure (in PSI) read by the analog pressure sensor * (on channel 0). @@ -74,10 +71,30 @@ public double getPressure() { return m_compressor.getPressure(); } + /** + * Returns the state of the pressure switch. + * + * @return True if pressure switch indicates that the system is not full, otherwise false. + */ + public boolean getPressureSwitchValue() { + return m_compressor.getPressureSwitchValue(); + } + + /** + * Returns whether the compressor is active or not. + * + * @return true if the compressor is on - otherwise false. + */ + public boolean isEnabled() { + return m_compressor.isEnabled(); + } + /** * Update sensor input readings */ private void updateInputs() { + m_inputs.isEnabled = isEnabled(); + m_inputs.digitalPressure = getPressureSwitchValue(); m_inputs.analogPressure = getPressure(); } @@ -105,7 +122,6 @@ public CompressorInputsAutoLogged getInputs() { */ public void enableDigital() { m_compressor.enableDigital(); - logOutputs(m_compressor.isEnabled()); } /** @@ -124,7 +140,6 @@ public void enableDigital() { */ public void enableAnalog(double minPressure, double maxPressure) { m_compressor.enableAnalog(minPressure, maxPressure); - logOutputs(m_compressor.isEnabled()); } /** @@ -141,17 +156,16 @@ public void enableAnalog(double minPressure, double maxPressure) { * reaches this value or the pressure switch is disconnected or indicates that the system is * full. */ - public void enableHybrid​(double minPressure, double maxPressure) { + public void enableHybrid(double minPressure, double maxPressure) { m_compressor.enableHybrid(minPressure, maxPressure); - logOutputs(m_compressor.isEnabled()); } /** Disable the compressor. */ public void disable() { m_compressor.disable(); - logOutputs(m_compressor.isEnabled()); } + @Override public void close() { m_compressor.close(); } diff --git a/src/main/java/org/lasarobotics/hardware/DoubleSolenoid.java b/src/main/java/org/lasarobotics/hardware/DoubleSolenoid.java index dcdc7b4e..48ef3101 100644 --- a/src/main/java/org/lasarobotics/hardware/DoubleSolenoid.java +++ b/src/main/java/org/lasarobotics/hardware/DoubleSolenoid.java @@ -9,7 +9,7 @@ import edu.wpi.first.wpilibj.PneumaticsModuleType; -public class DoubleSolenoid implements LoggableHardware { +public class DoubleSolenoid implements LoggableHardware, AutoCloseable { /** DoubleSolenoid ID */ public static class ID { public final String name; @@ -79,6 +79,7 @@ public void set(edu.wpi.first.wpilibj.DoubleSolenoid.Value value) { logOutputs(value.name()); } + @Override public void close() { m_doubleSolenoid.close(); } diff --git a/src/main/java/org/lasarobotics/hardware/Solenoid.java b/src/main/java/org/lasarobotics/hardware/Solenoid.java index eeccbadf..5323f53d 100644 --- a/src/main/java/org/lasarobotics/hardware/Solenoid.java +++ b/src/main/java/org/lasarobotics/hardware/Solenoid.java @@ -9,7 +9,7 @@ import edu.wpi.first.wpilibj.PneumaticsModuleType; -public class Solenoid implements LoggableHardware { +public class Solenoid implements LoggableHardware, AutoCloseable { /** Solenoid ID */ public static class ID { public final String name; @@ -87,6 +87,7 @@ public void toggle() { logOutputs(m_solenoid.get()); } + @Override public void close() { m_solenoid.close(); }