mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-21 01:01:43 +00:00
[wpilib] Add Toggle() function to solenoid classes (#2635)
Toggling a solenoid on a button press is a common idiom, so this provides a more readable way of accomplishing that.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2008-2019 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2008-2020 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
@@ -133,11 +133,27 @@ public class DoubleSolenoid extends SolenoidBase implements Sendable, AutoClosea
|
||||
|
||||
if (valueForward) {
|
||||
return Value.kForward;
|
||||
}
|
||||
if (valueReverse) {
|
||||
} else if (valueReverse) {
|
||||
return Value.kReverse;
|
||||
} else {
|
||||
return Value.kOff;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggle the value of the solenoid.
|
||||
*
|
||||
* <p>If the solenoid is set to forward, it'll be set to reverse. If the solenoid is set to
|
||||
* reverse, it'll be set to forward. If the solenoid is set to off, nothing happens.
|
||||
*/
|
||||
public void toggle() {
|
||||
Value value = get();
|
||||
|
||||
if (value == Value.kForward) {
|
||||
set(Value.kReverse);
|
||||
} else if (value == Value.kReverse) {
|
||||
set(Value.kForward);
|
||||
}
|
||||
return Value.kOff;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2008-2019 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2008-2020 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
@@ -77,6 +77,16 @@ public class Solenoid extends SolenoidBase implements Sendable, AutoCloseable {
|
||||
return SolenoidJNI.getSolenoid(m_solenoidHandle);
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggle the value of the solenoid.
|
||||
*
|
||||
* <p>If the solenoid is set to on, it'll be turned off. If the solenoid is set to off, it'll be
|
||||
* turned on.
|
||||
*/
|
||||
public void toggle() {
|
||||
set(!get());
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if solenoid is blacklisted. If a solenoid is shorted, it is added to the blacklist and
|
||||
* disabled until power cycle, or until faults are cleared.
|
||||
|
||||
Reference in New Issue
Block a user