Class BindingManager

java.lang.Object
com.cdarobotics.cdalib.bindings.BindingManager

public class BindingManager extends Object
A registry of named Bindings (boolean conditions) and AnalogBindings (analog inputs). Controls are registered by id and queried by id, decoupling the wiring of an input from the code that reacts to it.
  • Constructor Details

    • BindingManager

      public BindingManager()
      Creates an empty binding manager.
  • Method Details

    • addBinding

      public boolean addBinding(String id, BooleanSupplier condition)
      Registers a new Binding under the given id. Does nothing if a binding with that id is already registered.
      Parameters:
      id - the id to register the binding under
      condition - the condition supplier for the binding
      Returns:
      true if the binding was added, false if the id was already taken
    • addBinding

      public boolean addBinding(Binding binding)
      Registers the given Binding under its own id. Does nothing if a binding with that id is already registered.
      Parameters:
      binding - the binding to add
      Returns:
      true if the binding was added, false if the id was already taken
    • replaceBinding

      public void replaceBinding(String id, BooleanSupplier condition)
      Registers a Binding under the given id, overwriting any existing binding with that id.
      Parameters:
      id - the id to register the binding under
      condition - the condition supplier for the binding
    • replaceBinding

      public void replaceBinding(Binding binding)
      Registers the given Binding under its own id, overwriting any existing binding with that id.
      Parameters:
      binding - the binding to add
    • addAnalog

      public boolean addAnalog(String id, DoubleSupplier provider)
      Registers a new AnalogBinding under the given id. Does nothing if an analog binding with that id is already registered.
      Parameters:
      id - the id to register the analog binding under
      provider - the value supplier for the analog binding
      Returns:
      true if the analog binding was added, false if the id was already taken
    • replaceAnalog

      public void replaceAnalog(String id, DoubleSupplier provider)
      Registers an AnalogBinding under the given id, overwriting any existing analog binding with that id.
      Parameters:
      id - the id to register the analog binding under
      provider - the value supplier for the analog binding
    • replaceAnalog

      public void replaceAnalog(AnalogBinding analog)
      Registers the given AnalogBinding under its own id, overwriting any existing analog binding with that id.
      Parameters:
      analog - the analog binding to add
    • checkBinding

      public boolean checkBinding(String id)
      Evaluates the Binding registered under the given id.
      Parameters:
      id - the id of the binding
      Returns:
      the binding's current status, or false if no non-null binding is registered under that id
    • checkAnalog

      public double checkAnalog(String id)
      Reads the value of the AnalogBinding registered under the given id.
      Parameters:
      id - the id of the analog binding
      Returns:
      the analog binding's current value, or 0 if no non-null analog binding is registered under that id