Class SendableChooser<V>
java.lang.Object
edu.wpi.first.wpilibj.smartdashboard.SendableChooser<V>
- Type Parameters:
V- The type of the values to be stored
- All Implemented Interfaces:
Sendable,AutoCloseable
The
SendableChooser class is a useful tool for presenting a selection of options to the
SmartDashboard.
For instance, you may wish to be able to select between multiple autonomous modes. You can do
this by putting every possible Command you want to run as an autonomous into a SendableChooser and then put it into the SmartDashboard to have a list of options appear
on the laptop. Once autonomous starts, simply ask the SendableChooser what the selected
value is.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds the given object to the list of options.voidclose()Returns the selected option.voidinitSendable(SendableBuilder builder) Initializes thisSendableobject.voidBind a listener that's called when the selected value changes.voidsetDefaultOption(String name, V object) Adds the given object to the list of options and marks it as the default.
-
Constructor Details
-
SendableChooser
public SendableChooser()Instantiates aSendableChooser.
-
-
Method Details
-
close
- Specified by:
closein interfaceAutoCloseable
-
addOption
Adds the given object to the list of options. On theSmartDashboardon the desktop, the object will appear as the given name.- Parameters:
name- the name of the optionobject- the option
-
setDefaultOption
Adds the given object to the list of options and marks it as the default. Functionally, this is very close toaddOption(String, Object)except that it will use this as the default option if none other is explicitly selected.- Parameters:
name- the name of the optionobject- the option
-
getSelected
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 returnnull.- Returns:
- the option selected
-
onChange
Bind a listener that's called when the selected value changes. Only one listener can be bound. Calling this function will replace the previous listener.- Parameters:
listener- The function to call that accepts the new value
-
initSendable
Description copied from interface:SendableInitializes thisSendableobject.- Specified by:
initSendablein interfaceSendable- Parameters:
builder- sendable builder
-