Skip to content

Commit 513384a

Browse files
committed
documentation
1 parent 426e82c commit 513384a

6 files changed

Lines changed: 246 additions & 9 deletions

File tree

src/main/java/org/carlmontrobotics/lib199/safeMode/SafeCommand.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,19 @@
55
import edu.wpi.first.wpilibj2.command.FunctionalCommand;
66
import edu.wpi.first.wpilibj2.command.Subsystem;
77

8+
/**
9+
* A command that only runs when safe-mode is enabled and returns {@code isFinished() = true} otherwise.
10+
*
11+
* Note that this does not block calls to {@link #end(boolean)} (If the command is scheduled when safe-mode is disabled, {@link #end(boolean)} will be called immediately})
12+
*/
813
public class SafeCommand extends FunctionalCommand {
914

1015
private final Command command;
1116

17+
/**
18+
* Creates a new SafeCommand
19+
* @param command The command to run
20+
*/
1221
public SafeCommand(Command command) {
1322
super(
1423
() -> { if(SafeMode.isEnabled()) command.initialize(); },

src/main/java/org/carlmontrobotics/lib199/safeMode/SafeExecuteBlockingCommand.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@
55
import edu.wpi.first.wpilibj2.command.FunctionalCommand;
66
import edu.wpi.first.wpilibj2.command.Subsystem;
77

8-
// These are suitable for cases where the command should keep running such as a default command where isFinished must always return false
8+
/**
9+
* A command that only runs its {@link #execute()} method when safe-mode is enabled, and continues running as long as the underlying command is not finished.
10+
*
11+
* Keep in mind that this does not block calls to {@link #initialize()} or {@link #end(boolean)}, so it is not appropriate for wrapping commands such as {@link edu.wpi.first.wpilibj2.command.InstantCommand}.
12+
* It is intended for cases where the command should keep running such as a default command where {@link #isFinished()} must always return {@code false}
13+
*/
914
public class SafeExecuteBlockingCommand extends FunctionalCommand {
1015

1116
private final Command command;

src/main/java/org/carlmontrobotics/lib199/safeMode/SafeJoystick.java

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,35 @@
55

66
import edu.wpi.first.wpilibj.GenericHID;
77

8+
/**
9+
* A wrapper for a {@link GenericHID} that implements safe-mode features.
10+
*
11+
* This class is designed for internal use via {@link org.carlmontrobotics.lib199.Mocks}.
12+
* As such it provides re-implementations for {@link GenericHID} methods without extending {@link GenericHID}
13+
* to allow for the extension of subclasses such as {@link edu.wpi.first.wpilibj.Joystick}, {@link edu.wpi.first.wpilibj.PS4Controller},
14+
* {@link edu.wpi.first.wpilibj.XboxController}, etc. To wrap a joystick, call {@link SafeMode#makeSafe(GenericHID)}.
15+
*/
816
public class SafeJoystick {
917

18+
/**
19+
* The unsafe joystick that this class wraps.
20+
*/
1021
public final GenericHID unsafeJoystick;
1122

1223
private final Set<Integer> safeDisabledButtons;
1324
private final Set<Integer> safeDisabledAxes;
1425
private final Map<Integer, Double> safeScaledAxes;
1526
private final Map<Integer, Set<Integer>> safeDisabledPOV;
1627

17-
// Use AtomicBoolean so that the boolean is passed by reference
28+
/**
29+
* Creates a new SafeJoystick
30+
*
31+
* @param unsafeJoystick The unsafe joystick to wrap
32+
* @param safeDisabledButtons The buttons that should be disabled in safe-mode
33+
* @param safeDisabledAxes The axes that should be disabled in safe-mode
34+
* @param safeScaledAxes The axes that should be scaled in safe-mode (key: axis, value: scale factor)
35+
* @param safeDisabledPOV The POVs that should be disabled in safe-mode (key: POV, value: set of disabled values)
36+
*/
1837
public SafeJoystick(GenericHID unsafeJoystick, Set<Integer> safeDisabledButtons, Set<Integer> safeDisabledAxes, Map<Integer, Double> safeScaledAxes, Map<Integer, Set<Integer>> safeDisabledPOV) {
1938
this.unsafeJoystick = unsafeJoystick;
2039
this.safeDisabledButtons = safeDisabledButtons;
@@ -25,6 +44,12 @@ public SafeJoystick(GenericHID unsafeJoystick, Set<Integer> safeDisabledButtons,
2544

2645
// All other methods always fall through to these five
2746

47+
/**
48+
* Safe version of {@link GenericHID#getRawButton(int)}.
49+
*
50+
* @param button The button to read
51+
* @return The state of the button
52+
*/
2853
public boolean getRawButton(int button) {
2954
if (SafeMode.isEnabled() && safeDisabledButtons.contains(button)) {
3055
return false;
@@ -33,6 +58,12 @@ public boolean getRawButton(int button) {
3358
}
3459
}
3560

61+
/**
62+
* Safe version of {@link GenericHID#getRawButtonPressed(int)(int)}.
63+
*
64+
* @param button The button to read
65+
* @return Whether the button was pressed since the last check
66+
*/
3667
public boolean getRawButtonPressed(int button) {
3768
if (SafeMode.isEnabled() && safeDisabledButtons.contains(button)) {
3869
return false;
@@ -41,6 +72,12 @@ public boolean getRawButtonPressed(int button) {
4172
}
4273
}
4374

75+
/**
76+
* Safe version of {@link GenericHID#getRawButtonReleased(int)(int)}.
77+
*
78+
* @param button The button to read
79+
* @return Whether the button was released since the last check
80+
*/
4481
public boolean getRawButtonReleased(int button) {
4582
if (SafeMode.isEnabled() && safeDisabledButtons.contains(button)) {
4683
return false;
@@ -49,6 +86,12 @@ public boolean getRawButtonReleased(int button) {
4986
}
5087
}
5188

89+
/**
90+
* Safe version of {@link GenericHID#getRawAxis(int)}.
91+
*
92+
* @param axis The axis to read
93+
* @return The value of the axis
94+
*/
5295
public double getRawAxis(int axis) {
5396
if (SafeMode.isEnabled() && safeDisabledAxes.contains(axis)) {
5497
return 0;
@@ -59,6 +102,12 @@ public double getRawAxis(int axis) {
59102
}
60103
}
61104

105+
/**
106+
* Safe version of {@link GenericHID#getPOV(int)}.
107+
*
108+
* @param pov The POV to read
109+
* @return The value of the POV
110+
*/
62111
public double getPOV(int pov) {
63112
if (SafeMode.isEnabled() && safeDisabledPOV.containsKey(pov) && safeDisabledPOV.get(pov).contains(unsafeJoystick.getPOV(pov))) {
64113
return -1;

0 commit comments

Comments
 (0)