Class TunableConfig

java.lang.Object
org.wpilib.tunable.TunableConfig

public final class TunableConfig extends Object
Additional optional configuration for tunables. This class is immutable.
  • Constructor Details

    • TunableConfig

      public TunableConfig()
      Creates a TunableConfig with default configuration: no properties, robust=false, no type string, isMutable=true, no callback, and polling=DEFAULT.
    • TunableConfig

      public TunableConfig(Map<String,String> propertiesMap, boolean robust, String typeString, boolean isMutable, Runnable onTune, boolean alwaysGet)
      Creates a TunableConfig.
      Parameters:
      propertiesMap - properties
      robust - robust flag
      typeString - type string
      isMutable - mutable flag
      onTune - onTune callback; must not throw
      alwaysGet - always get flag
    • TunableConfig

      public TunableConfig(Map<String,String> propertiesMap, boolean robust, String typeString, boolean isMutable, Runnable onTune, TunableConfig.Polling polling)
      Creates a TunableConfig.
      Parameters:
      propertiesMap - properties
      robust - robust flag
      typeString - type string
      isMutable - mutable flag
      onTune - onTune callback; must not throw
      polling - polling behavior
  • Method Details

    • of

      public static TunableConfig of(TunableOption... options)
      Creates a TunableConfig from an array of TunableOption.
      Parameters:
      options - options
      Returns:
      tunable config
    • withProperty

      public TunableConfig withProperty(String key, String value)
      Sets a property value.
      Parameters:
      key - property key
      value - property value; must be a valid JSON value string (e.g. quoted string, number, true, false, null, object, or array)
      Returns:
      new TunableConfig with the property set
    • withRobust

      public TunableConfig withRobust(boolean robust)
      Sets the robust flag.
      Parameters:
      robust - whether the tunable should separately echo back its value after setting
      Returns:
      new TunableConfig with the robust flag set
    • withTypeString

      public TunableConfig withTypeString(String typeString)
      Sets the type string.
      Parameters:
      typeString - the type string to use for the tunable
      Returns:
      new TunableConfig with the type string set
    • withMutable

      public TunableConfig withMutable(boolean isMutable)
      Sets the mutable flag.
      Parameters:
      isMutable - whether the tunable is mutable; setting this to false makes the tunable immutable, meaning that the Tunable's set() function will not be called
      Returns:
      new TunableConfig with the mutable flag set
    • withOnTune

      public TunableConfig withOnTune(Runnable onTune)
      Sets the onTune callback.
      Parameters:
      onTune - callback to call when the tunable is modified via tune(); this is called immediately after the tunable's tune() function is called. The callback will be called by TunableRegistry.update(). This callback must not throw.
      Returns:
      new TunableConfig with the onTune callback set
    • withAlwaysGet

      public TunableConfig withAlwaysGet(boolean alwaysGet)
      Sets the polling behavior to always get or get on change.
      Parameters:
      alwaysGet - whether the tunable should always get its value
      Returns:
      new TunableConfig with the polling behavior set
    • withPolling

      public TunableConfig withPolling(TunableConfig.Polling polling)
      Sets the polling behavior.
      Parameters:
      polling - polling behavior
      Returns:
      new TunableConfig with the polling behavior set
    • getProperties

      public String getProperties()
      Gets properties as a JSON string.
      Returns:
      JSON string
    • isRobust

      public boolean isRobust()
      Returns whether the tunable should separately echo back its new value after being set.
      Returns:
      whether the tunable is robust
    • getTypeString

      public String getTypeString()
      Returns the custom type string for the tunable.
      Returns:
      the type string, or null if none was set
    • isMutable

      public boolean isMutable()
      Returns whether the tunable is mutable. Setting this to false makes the tunable immutable, meaning that the Tunable's set() function will not be called.
      Returns:
      whether the tunable is mutable
    • getOnTune

      public Runnable getOnTune()
      Returns callback to call when the tunable is modified via tune(). This is called immediately after the tunable's tune() function is called. The callback will be called by TunableRegistry.update() and must not throw.
      Returns:
      the onTune callback
    • isAlwaysGet

      public boolean isAlwaysGet()
      Returns whether the tunable should always get its value.
      Returns:
      whether the tunable should always get its value
    • getPolling

      public TunableConfig.Polling getPolling()
      Returns when the backend should poll the tunable's local value.
      Returns:
      polling behavior