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 BooleanSupplier
constant
(boolean normalValue, boolean safeValue) Creates aBooleanSupplier
that returns a constant value when safe-mode is disabled and a different constant value when safe-mode is enabled.static DoubleSupplier
constant
(double normalValue, double safeValue) Creates aDoubleSupplier
that returns a constant value when safe-mode is disabled and a different constant value when safe-mode is enabled.static IntSupplier
constant
(int normalValue, int safeValue) Creates anIntSupplier
that returns a constant value when safe-mode is disabled and a different constant value when safe-mode is enabled.static LongSupplier
constant
(long normalValue, long safeValue) Creates aLongSupplier
that 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 aSupplier
that returns a constant value when safe-mode is disabled and a different constant value when safe-mode is enabled.static void
disable()
Disables safe-modestatic void
disableAxis
(int joystickPort, int axis) Disables an axis on a joystick while safe-mode is enabled.static void
disableAxis
(GenericHID joystick, int axis) Disables an axis on a joystick while safe-mode is enabled.static void
disableButton
(int joystickPort, int button) Disables a button on a joystick while safe-mode is enabled.static void
disableButton
(GenericHID joystick, int button) Disables a button on a joystick while safe-mode is enabled.static void
disablePOV
(int joystickPort, int angle) Disables a POV state (on POV 0) on a joystick while safe-mode is enabled.static void
disablePOV
(int joystickPort, int pov, int angle) Disables a POV state on a joystick while safe-mode is enabled.static void
disablePOV
(GenericHID joystick, int angle) Disables a POV state (on POV 0) on a joystick while safe-mode is enabled.static void
disablePOV
(GenericHID joystick, int pov, int angle) Disables a POV state on a joystick while safe-mode is enabled.static void
enable()
Enables safe-modestatic void
Ensures that the static block of this class is called, setting up safe-mode.static boolean
static <T extends GenericHID>
TmakeSafe
(T joystick) Creates aGenericHID
which alters its outputs while safe-mode is enabled bassed on an underlyingGenericHID
implementation.static void
onDisabled
(Runnable runnable) Registers a callback to be called when safe-mode is disabled.static void
Registers a callback to be called when safe-mode is enabled.static void
scaleAxis
(int joystickPort, int axis, double factor) Scales an axis on a joystick while safe-mode is enabled.static void
scaleAxis
(GenericHID joystick, int axis, double factor) Scales an axis on a joystick while safe-mode is enabled.static void
Calls 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 aSupplier
that 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 aBooleanSupplier
that 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 aDoubleSupplier
that 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 anIntSupplier
that 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 aLongSupplier
that 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 aGenericHID
which alters its outputs while safe-mode is enabled bassed on an underlyingGenericHID
implementation.- Type Parameters:
T
- The type of the underlyingGenericHID
- Parameters:
joystick
- The underlyingGenericHID
implementation- Returns:
- A
GenericHID
of 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
-