Class SafeMode
java.lang.Object
org.carlmontrobotics.lib199.safeMode.SafeMode
A class that keeps track of safe-mode state and provides functions to access common safe-mode features
To the best of my knowledge, all safe-mode features are thread-safe
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic BooleanSupplierconstant(boolean normalValue, boolean safeValue) Creates aBooleanSupplierthat returns a constant value when safe-mode is disabled and a different constant value when safe-mode is enabled.static DoubleSupplierconstant(double normalValue, double safeValue) Creates aDoubleSupplierthat returns a constant value when safe-mode is disabled and a different constant value when safe-mode is enabled.static IntSupplierconstant(int normalValue, int safeValue) Creates anIntSupplierthat returns a constant value when safe-mode is disabled and a different constant value when safe-mode is enabled.static LongSupplierconstant(long normalValue, long safeValue) Creates aLongSupplierthat returns a constant value when safe-mode is disabled and a different constant value when safe-mode is enabled.static <T> Supplier<T>constant(T normalValue, T safeValue) Creates aSupplierthat returns a constant value when safe-mode is disabled and a different constant value when safe-mode is enabled.static voiddisable()Disables safe-modestatic voiddisableAxis(int joystickPort, int axis) Disables an axis on a joystick while safe-mode is enabled.static voiddisableAxis(GenericHID joystick, int axis) Disables an axis on a joystick while safe-mode is enabled.static voiddisableButton(int joystickPort, int button) Disables a button on a joystick while safe-mode is enabled.static voiddisableButton(GenericHID joystick, int button) Disables a button on a joystick while safe-mode is enabled.static voiddisablePOV(int joystickPort, int angle) Disables a POV state (on POV 0) on a joystick while safe-mode is enabled.static voiddisablePOV(int joystickPort, int pov, int angle) Disables a POV state on a joystick while safe-mode is enabled.static voiddisablePOV(GenericHID joystick, int angle) Disables a POV state (on POV 0) on a joystick while safe-mode is enabled.static voiddisablePOV(GenericHID joystick, int pov, int angle) Disables a POV state on a joystick while safe-mode is enabled.static voidenable()Enables safe-modestatic voidEnsures that the static block of this class is called, setting up safe-mode.static booleanstatic <T extends GenericHID>
TmakeSafe(T joystick) Creates aGenericHIDwhich alters its outputs while safe-mode is enabled bassed on an underlyingGenericHIDimplementation.static voidonDisabled(Runnable runnable) Registers a callback to be called when safe-mode is disabled.static voidRegisters a callback to be called when safe-mode is enabled.static voidscaleAxis(int joystickPort, int axis, double factor) Scales an axis on a joystick while safe-mode is enabled.static voidscaleAxis(GenericHID joystick, int axis, double factor) Scales an axis on a joystick while safe-mode is enabled.static voidCalls the callbacks for safe-mode state changes if necessary.
-
Constructor Details
-
SafeMode
public SafeMode()
-
-
Method Details
-
ensureInitialized
public static void ensureInitialized()Ensures that the static block of this class is called, setting up safe-mode. It is unlikely that you will need to call this function. -
enable
public static void enable()Enables safe-mode -
disable
public static void disable()Disables safe-mode -
isEnabled
public static boolean isEnabled()- Returns:
- Whether safe-mode is enabled
-
onEnabled
Registers a callback to be called when safe-mode is enabled. A couple notes about the state of the callback function: 1. This function is thread-safe 2. The callback function will be called synchronously with the CommandScheduler (unless you callupdateCallbacks()from another thread) 3. The callback function may be called multiple times in a row, even if the safe-mode state has not changed 4. The callback function will not be called if safe-mode is not enabled 5. The callback function will be called if safe-mode is enabled unless safe-mode is re-disabled before a periodic update 6. The callback function will not necessarily be invoked based on the current state of safe-mode- Parameters:
runnable- The function to run
-
onDisabled
Registers a callback to be called when safe-mode is disabled. A couple notes about the state of the callback function: 1. This function is thread-safe 2. The callback function will be called synchronously with the CommandScheduler (unless you callupdateCallbacks()from another thread) 3. The callback function may be called multiple times in a row, even if the safe-mode state has not changed 4. The callback function will not be called if safe-mode is not disabled 5. The callback function will be called if safe-mode is disabled unless safe-mode is re-enabled before a periodic update 6. The callback function will not necessarily be invoked based on the current state of safe-mode- Parameters:
runnable- The function to run
-
updateCallbacks
public static void updateCallbacks()Calls the callbacks for safe-mode state changes if necessary. It should not be necessary to call this function manually as it is automatically invoked as part of the robot's periodic loop viaCommandScheduler. While this function is thread-safe, if you call it from another thread, the callbacks may not be called synchronously with theCommandScheduler. -
constant
Creates aSupplierthat returns a constant value when safe-mode is disabled and a different constant value when safe-mode is enabled.- Type Parameters:
T- The type of the constant values- Parameters:
normalValue- The value to return when safe-mode is disabledsafeValue- The value to return when safe-mode is enabled- Returns:
- A supplier which selects the appropriate value when called
-
constant
Creates aBooleanSupplierthat returns a constant value when safe-mode is disabled and a different constant value when safe-mode is enabled.- Parameters:
normalValue- The value to return when safe-mode is disabledsafeValue- The value to return when safe-mode is enabled- Returns:
- A supplier which selects the appropriate value when called
-
constant
Creates aDoubleSupplierthat returns a constant value when safe-mode is disabled and a different constant value when safe-mode is enabled.- Parameters:
normalValue- The value to return when safe-mode is disabledsafeValue- The value to return when safe-mode is enabled- Returns:
- A supplier which selects the appropriate value when called
-
constant
Creates anIntSupplierthat returns a constant value when safe-mode is disabled and a different constant value when safe-mode is enabled.- Parameters:
normalValue- The value to return when safe-mode is disabledsafeValue- The value to return when safe-mode is enabled- Returns:
- A supplier which selects the appropriate value when called
-
constant
Creates aLongSupplierthat returns a constant value when safe-mode is disabled and a different constant value when safe-mode is enabled.- Parameters:
normalValue- The value to return when safe-mode is disabledsafeValue- The value to return when safe-mode is enabled- Returns:
- A supplier which selects the appropriate value when called
-
makeSafe
Creates aGenericHIDwhich alters its outputs while safe-mode is enabled bassed on an underlyingGenericHIDimplementation.- Type Parameters:
T- The type of the underlyingGenericHID- Parameters:
joystick- The underlyingGenericHIDimplementation- Returns:
- A
GenericHIDof the same type and based on the given joystick which alters its outputs while safe-mode is enabled
-
disableButton
public static void disableButton(int joystickPort, int button) Disables a button on a joystick while safe-mode is enabled.- Parameters:
joystickPort- The port of the joystickbutton- The button to disable
-
disableButton
Disables a button on a joystick while safe-mode is enabled.- Parameters:
joystick- The joystick to disable the button onbutton- The button to disable
-
disableAxis
public static void disableAxis(int joystickPort, int axis) Disables an axis on a joystick while safe-mode is enabled.- Parameters:
joystickPort- The port of the joystickaxis- The axis to disable
-
disableAxis
Disables an axis on a joystick while safe-mode is enabled.- Parameters:
joystick- The joystick to disable the axis onaxis- The axis to disable
-
scaleAxis
public static void scaleAxis(int joystickPort, int axis, double factor) Scales an axis on a joystick while safe-mode is enabled.- Parameters:
joystickPort- The port of the joystickaxis- The axis to scalefactor- The factor to scale the axis by
-
scaleAxis
Scales an axis on a joystick while safe-mode is enabled.- Parameters:
joystick- The joystick to scale the axis onaxis- The axis to scalefactor- The factor to scale the axis by
-
disablePOV
public static void disablePOV(int joystickPort, int angle) Disables a POV state (on POV 0) on a joystick while safe-mode is enabled. This is equivalent to callingdisablePOV(joystickPort, 0, angle).- Parameters:
joystickPort- The port of the joystickangle- The angle of the POV to disable
-
disablePOV
Disables a POV state (on POV 0) on a joystick while safe-mode is enabled. This is equivalent to callingdisablePOV(joystick, 0, angle).- Parameters:
joystick- The joystick to disable the POV onangle- The angle of the POV to disable
-
disablePOV
public static void disablePOV(int joystickPort, int pov, int angle) Disables a POV state on a joystick while safe-mode is enabled.- Parameters:
joystickPort- The port of the joystickpov- The POV on the joystickangle- The angle of the POV to disable
-
disablePOV
Disables a POV state on a joystick while safe-mode is enabled.- Parameters:
joystick- The joystick to disable the POV onpov- The POV on the joystickangle- The angle of the POV to disable
-