Skip to content

Commit 3569b17

Browse files
authored
Merge pull request #59 from DeepBlueRobotics/safe-mode
Fix a Bug Where Safe-Mode May not be Initialized if only Safe-Commands are Used
2 parents 4420b4c + acf643f commit 3569b17

5 files changed

Lines changed: 22 additions & 0 deletions

File tree

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ public class SafeCommand extends FunctionalCommand {
1414

1515
private final Command command;
1616

17+
static {
18+
SafeMode.ensureInitialized();
19+
}
20+
1721
/**
1822
* Creates a new SafeCommand
1923
* @param command The command to run

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ public class SafeExecuteBlockingCommand extends FunctionalCommand {
1515

1616
private final Command command;
1717

18+
static {
19+
SafeMode.ensureInitialized();
20+
}
21+
1822
public SafeExecuteBlockingCommand(Command command) {
1923
super(
2024
() -> command.initialize(),

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ public class SafeMode {
4646
Lib199Subsystem.registerPeriodic(SafeMode::updateCallbacks);
4747
}
4848

49+
/**
50+
* Ensures that the static block of this class is called, setting up safe-mode.
51+
* It is unlikely that you will need to call this function.
52+
*/
53+
public static void ensureInitialized() {}
54+
4955
/**
5056
* Enables safe-mode
5157
*/

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ public class UnsafeCommand extends FunctionalCommand {
1414

1515
private final Command command;
1616

17+
static {
18+
SafeMode.ensureInitialized();
19+
}
20+
1721
public UnsafeCommand(Command command) {
1822
super(
1923
() -> { if(!SafeMode.isEnabled()) command.initialize(); },

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ public class UnsafeExecuteBlockingCommand extends FunctionalCommand {
1515

1616
private final Command command;
1717

18+
static {
19+
SafeMode.ensureInitialized();
20+
}
21+
1822
public UnsafeExecuteBlockingCommand(Command command) {
1923
super(
2024
command::initialize,

0 commit comments

Comments
 (0)