Package org.chsrobotics.lib.telemetry
Class DashboardChooser<T>
java.lang.Object
org.chsrobotics.lib.telemetry.DashboardChooser<T>
- Type Parameters:
T- The data type of the option.
- All Implemented Interfaces:
edu.wpi.first.networktables.NTSendable,edu.wpi.first.util.sendable.Sendable,AutoCloseable
public class DashboardChooser<T>
extends Object
implements edu.wpi.first.networktables.NTSendable, AutoCloseable
A NTSendable which replaces the SendableChooser in favor of a listener-based api. Used for
constructing option widgets in the dashboard.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceInterface implemented by enums which allows DashboardChooser to automatically create choosers.static interfaceInterface which defines a lambda for receiving DashboardChooser updates. -
Constructor Summary
ConstructorsConstructorDescriptionDashboardChooser(Map<String, T> options, String defaultOption) Constructs a DashboardChooser from aMap<String, T>, recording changes to the chosen value to the default on-robot log atHighLevelLogger.getLog().DashboardChooser(Map<String, T> options, String defaultOption, boolean logChanges) Constructs a DashboardChooser from aMap<String, T>. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()static <T> DashboardChooser<T>fromEnum(Class<? extends DashboardChooser.Option> enumClass, DashboardChooser.Option defaultOption) Returns a DashboardChooser from an enum implementingDashboardChooser.Option, saving changes to the default log fromHighLevelLogger.getLog()static <T> DashboardChooser<T>fromEnum(Class<? extends DashboardChooser.Option> enumClass, DashboardChooser.Option defaultOption, boolean logChanges) Constructs a DashboardChooser from an enum implementingDashboardChooser.Option.Gets the currently selected option's value.voidinitSendable(edu.wpi.first.networktables.NTSendableBuilder builder) voidregisterListener(DashboardChooser.ValueUpdater<T> updater) Register a listener to be called when the option is updated.voidunregisterListener(DashboardChooser.ValueUpdater<T> updater) Unregister a listener when no longer needed.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface edu.wpi.first.networktables.NTSendable
initSendable
-
Constructor Details
-
DashboardChooser
Constructs a DashboardChooser from aMap<String, T>.- Parameters:
options- The option list, as aMap<title, value>.defaultOption- The title of the default option.logChanges- Whether to log changes in the chosen value to the default on-robot log atHighLevelLogger.getLog().
-
DashboardChooser
Constructs a DashboardChooser from aMap<String, T>, recording changes to the chosen value to the default on-robot log atHighLevelLogger.getLog().- Parameters:
options- The option list, as aMap<title, value>.defaultOption- The title of the default option.
-
-
Method Details
-
fromEnum
public static <T> DashboardChooser<T> fromEnum(Class<? extends DashboardChooser.Option> enumClass, DashboardChooser.Option defaultOption, boolean logChanges) Constructs a DashboardChooser from an enum implementingDashboardChooser.Option.- Type Parameters:
T- The enum's type.- Parameters:
enumClass- The<enum>.classdefaultOption- The default enum optionlogChanges- Whether to log changes in the chosen value to the default robot log atHighLevelLogger.getLog().- Returns:
- A new DashboardChooser object.
-
fromEnum
public static <T> DashboardChooser<T> fromEnum(Class<? extends DashboardChooser.Option> enumClass, DashboardChooser.Option defaultOption) Returns a DashboardChooser from an enum implementingDashboardChooser.Option, saving changes to the default log fromHighLevelLogger.getLog()- Type Parameters:
T- The enum's type.- Parameters:
enumClass- The<enum>.classdefaultOption- The default enum option- Returns:
- A new DashboardChooser object.
-
close
public void close()- Specified by:
closein interfaceAutoCloseable
-
getSelected
Gets the currently selected option's value.- Returns:
- The option's value, of type T.
-
initSendable
public void initSendable(edu.wpi.first.networktables.NTSendableBuilder builder) - Specified by:
initSendablein interfaceedu.wpi.first.networktables.NTSendable
-
registerListener
Register a listener to be called when the option is updated.- Parameters:
updater- The lambda to be called on update.
-
unregisterListener
Unregister a listener when no longer needed.- Parameters:
updater- the lambda to remove.
-