Class SafeMode

java.lang.Object
org.carlmontrobotics.lib199.safeMode.SafeMode

public class SafeMode extends Object
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
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    constant(boolean normalValue, boolean safeValue)
    Creates a BooleanSupplier that returns a constant value when safe-mode is disabled and a different constant value when safe-mode is enabled.
    constant(double normalValue, double safeValue)
    Creates a DoubleSupplier that returns a constant value when safe-mode is disabled and a different constant value when safe-mode is enabled.
    constant(int normalValue, int safeValue)
    Creates an IntSupplier that returns a constant value when safe-mode is disabled and a different constant value when safe-mode is enabled.
    constant(long normalValue, long safeValue)
    Creates a LongSupplier 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 a Supplier that returns a constant value when safe-mode is disabled and a different constant value when safe-mode is enabled.
    static void
    Disables safe-mode
    static 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
    Enables safe-mode
    static void
    Ensures that the static block of this class is called, setting up safe-mode.
    static boolean
     
    static <T extends GenericHID>
    T
    makeSafe(T joystick)
    Creates a GenericHID which alters its outputs while safe-mode is enabled bassed on an underlying GenericHID implementation.
    static void
    onDisabled(Runnable runnable)
    Registers a callback to be called when safe-mode is disabled.
    static void
    onEnabled(Runnable runnable)
    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.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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

      public static void onEnabled(Runnable runnable)
      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 call updateCallbacks() 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

      public static void onDisabled(Runnable runnable)
      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 call updateCallbacks() 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 via CommandScheduler. While this function is thread-safe, if you call it from another thread, the callbacks may not be called synchronously with the CommandScheduler.
    • constant

      public static <T> Supplier<T> constant(T normalValue, T safeValue)
      Creates a Supplier 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 disabled
      safeValue - The value to return when safe-mode is enabled
      Returns:
      A supplier which selects the appropriate value when called
    • constant

      public static BooleanSupplier constant(boolean normalValue, boolean safeValue)
      Creates a BooleanSupplier 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 disabled
      safeValue - The value to return when safe-mode is enabled
      Returns:
      A supplier which selects the appropriate value when called
    • constant

      public static DoubleSupplier constant(double normalValue, double safeValue)
      Creates a DoubleSupplier 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 disabled
      safeValue - The value to return when safe-mode is enabled
      Returns:
      A supplier which selects the appropriate value when called
    • constant

      public static IntSupplier constant(int normalValue, int safeValue)
      Creates an IntSupplier 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 disabled
      safeValue - The value to return when safe-mode is enabled
      Returns:
      A supplier which selects the appropriate value when called
    • constant

      public static LongSupplier constant(long normalValue, long safeValue)
      Creates a LongSupplier 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 disabled
      safeValue - The value to return when safe-mode is enabled
      Returns:
      A supplier which selects the appropriate value when called
    • makeSafe

      public static <T extends GenericHID> T makeSafe(T joystick)
      Creates a GenericHID which alters its outputs while safe-mode is enabled bassed on an underlying GenericHID implementation.
      Type Parameters:
      T - The type of the underlying GenericHID
      Parameters:
      joystick - The underlying GenericHID 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 joystick
      button - The button to disable
    • disableButton

      public static void disableButton(GenericHID joystick, int button)
      Disables a button on a joystick while safe-mode is enabled.
      Parameters:
      joystick - The joystick to disable the button on
      button - 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 joystick
      axis - The axis to disable
    • disableAxis

      public static void disableAxis(GenericHID joystick, int axis)
      Disables an axis on a joystick while safe-mode is enabled.
      Parameters:
      joystick - The joystick to disable the axis on
      axis - 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 joystick
      axis - The axis to scale
      factor - The factor to scale the axis by
    • scaleAxis

      public static void scaleAxis(GenericHID joystick, int axis, double factor)
      Scales an axis on a joystick while safe-mode is enabled.
      Parameters:
      joystick - The joystick to scale the axis on
      axis - The axis to scale
      factor - 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 calling disablePOV(joystickPort, 0, angle).
      Parameters:
      joystickPort - The port of the joystick
      angle - The angle of the POV to disable
    • disablePOV

      public static void disablePOV(GenericHID joystick, int angle)
      Disables a POV state (on POV 0) on a joystick while safe-mode is enabled. This is equivalent to calling disablePOV(joystick, 0, angle).
      Parameters:
      joystick - The joystick to disable the POV on
      angle - 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 joystick
      pov - The POV on the joystick
      angle - The angle of the POV to disable
    • disablePOV

      public static void disablePOV(GenericHID joystick, int pov, int angle)
      Disables a POV state on a joystick while safe-mode is enabled.
      Parameters:
      joystick - The joystick to disable the POV on
      pov - The POV on the joystick
      angle - The angle of the POV to disable