Class LoggedDashboardChooser<V>

java.lang.Object
org.littletonrobotics.junction.networktables.LoggedNetworkInput
org.littletonrobotics.junction.networktables.LoggedDashboardChooser<V>
Type Parameters:
V - The value type associated with each string key.

public class LoggedDashboardChooser<V> extends LoggedNetworkInput
Manages a chooser value published to the "SmartDashboard" table of NT.
  • Constructor Details

    • LoggedDashboardChooser

      public LoggedDashboardChooser(String key)
      Creates a new LoggedDashboardChooser, for handling a chooser input sent via NetworkTables.
      Parameters:
      key - The key for the chooser, published to "/SmartDashboard/{key}" for NT or "/DashboardInputs/SmartDashboard/{key}" when logged.
    • LoggedDashboardChooser

      public LoggedDashboardChooser(String key, SendableChooser<V> chooser)
      Creates a new LoggedDashboardChooser, for handling a chooser input sent via NetworkTables. This constructor copies the options from a SendableChooser. Note that updates to the original SendableChooser will not affect this object.
      Parameters:
      key - The key for the chooser, published to "/SmartDashboard/{key}" for NT or "/DashboardInputs/{key}" when logged.
      chooser - The existing SendableChooser object.
  • Method Details

    • addOption

      public void addOption(String key, V value)
      Adds a new option to the chooser.
      Parameters:
      key - The string key for the option.
      value - The value of the option.
    • addDefaultOption

      public void addDefaultOption(String key, V value)
      Adds a new option to the chooser and sets it to the default.
      Parameters:
      key - The string key for the option.
      value - The value of the option.
    • get

      public V get()
      Returns the selected option. If there is none selected, it will return the default. If there is none selected and no default, then it will return null.
      Returns:
      The value for the selected option.
    • onChange

      public void onChange(Consumer<V> listener)
      Binds the callback to run whenever the selected option changes. There can only be one listener, and this method overrites it with each invokation.
      Parameters:
      listener - The function to call that accepts the new value.
    • getSendableChooser

      public SendableChooser<String> getSendableChooser()
      Returns the internal SendableChooser object, for use when setting up dashboard layouts. Do not read data from the SendableChooser directly.
      Returns:
      The internal SendableChooser object.
    • periodic

      public void periodic()
      Description copied from class: LoggedNetworkInput
      Update the current value and save/replay the input. This function should never be called by user code.
      Specified by:
      periodic in class LoggedNetworkInput