Class CanandSettings

java.lang.Object
com.reduxrobotics.canand.CanandSettings
Direct Known Subclasses:
CanandcolorSettings, CanandgyroSettings, CanandmagSettings

public abstract class CanandSettings extends Object
Base (simple) settings class for Redux devices. Inheriting classes with more complex firmware interfaces may or may not use this structure. It's typically used in conjunction with CanandSettingsManager. In general, however, it's a pretty useful structure.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected boolean
    Whether the settings will be applied ephemerally.
    protected Map<Integer,Long>
    The backing Map of raw setting indexes to raw setting values (serialized as Long)
  • Constructor Summary

    Constructors
    Constructor
    Description
    Default constructor.
    Clone constructor.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Returns whether or not all settings fields have been written into the object.
    protected static long
    checkBounds(String flavor, double rawVal, int min, int max, double scale)
    Check bounds for an input double that is mapped to some integer type underneath.
    protected abstract int[]
    Gets the list of settings addresses this settings class records.
    protected Optional<Boolean>
    getBool(int idx)
    Gets a boolean from the internal Map if it exists and return true, false, or null
    Return a direct filtered view of settings values as a new Map, limited to only valid settings.
    protected Optional<Double>
    getFloatAsDouble(int idx, double divisor)
    Gets an integer from the internal Map if it exists and return a scaled user value.
    protected Optional<Double>
    getIntAsDouble(int idx, double divisor)
    Gets an integer from the internal Map if it exists and return a scaled user value.
    Directly access the underlying Map of settings values.
    Generates a list of setting indexes missing from this object to be considered "complete".
    boolean
    Returns if this CanandSettings has any set settings or not.
    void
    setEphemeral(boolean value)
    Sets whether or not the settings will be set as ephemeral -- that is, does not persist on device power cycle.
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • values

      protected Map<Integer,Long> values
      The backing Map of raw setting indexes to raw setting values (serialized as Long)
    • ephemeral

      protected boolean ephemeral
      Whether the settings will be applied ephemerally.
  • Constructor Details

    • CanandSettings

      public CanandSettings()
      Default constructor.
    • CanandSettings

      public CanandSettings(CanandSettings stg)
      Clone constructor.
      Parameters:
      stg - the other object to clone.
  • Method Details

    • fetchSettingsAddresses

      protected abstract int[] fetchSettingsAddresses()
      Gets the list of settings addresses this settings class records. This is typically a static list of constants from a Details class.
      Returns:
      settings addresses.
    • checkBounds

      protected static long checkBounds(String flavor, double rawVal, int min, int max, double scale)
      Check bounds for an input double that is mapped to some integer type underneath. A common example is to map some value between [0..1) to [0..16383].
      Parameters:
      flavor - Flavor text describing the value
      rawVal - The raw inputted double value
      min - The minimum valid integer value
      max - The maximum value integer value
      scale - How much the raw value must be multiplied by to fit the scale
      Returns:
      A scaled integer (long) value mapped from the input raw value.
    • getIntAsDouble

      protected Optional<Double> getIntAsDouble(int idx, double divisor)
      Gets an integer from the internal Map if it exists and return a scaled user value.
      Parameters:
      idx - the setting index to pull
      divisor - how much to divide the integer value by
      Returns:
      a scaled double if the setting exists else null
    • getFloatAsDouble

      protected Optional<Double> getFloatAsDouble(int idx, double divisor)
      Gets an integer from the internal Map if it exists and return a scaled user value.
      Parameters:
      idx - the setting index to pull
      divisor - how much to divide the float value by
      Returns:
      a scaled double if the setting exists else null
    • getBool

      protected Optional<Boolean> getBool(int idx)
      Gets a boolean from the internal Map if it exists and return true, false, or null
      Parameters:
      idx - the setting index to pull
      Returns:
      a boolean if the setting exists else null
    • allSettingsReceived

      public boolean allSettingsReceived()
      Returns whether or not all settings fields have been written into the object.

      May return false if the a getSettings call did not succeed in fetching every setting.

      Returns:
      whether the settings object has been filled
    • getMap

      public Map<Integer,Long> getMap()
      Directly access the underlying Map of settings values. Intended for internal use.
      Returns:
      map
    • getFilteredMap

      public Map<Integer,Long> getFilteredMap()
      Return a direct filtered view of settings values as a new Map, limited to only valid settings.
      Returns:
      map
    • isEmpty

      public boolean isEmpty()
      Returns if this CanandSettings has any set settings or not. Useful when a CanandSettings is returned as a result of setSettings to check if all settings succeeded.
      Returns:
      true if empty
    • setEphemeral

      public void setEphemeral(boolean value)
      Sets whether or not the settings will be set as ephemeral -- that is, does not persist on device power cycle.

      This is generally not needed unless you are legitimately changing the actual values of settings frequently!!! Redux devices will skip writing to flash if the sent setting already equals what is stored in flash.

      This means, in practice, if you are only applying a fixed set of settings on robot startup, there is little benefit to sending them ephemerally as it does not affect flash wear if the settings already match, and sending them ephemerally reduces robustness against things like poor wiring and power cycling of the device.

      Parameters:
      value - true if ephemeral
    • getMissingIndexes

      public List<Integer> getMissingIndexes()
      Generates a list of setting indexes missing from this object to be considered "complete".
      Returns:
      List of missing setting indexes.
    • toString

      public String toString()
      Overrides:
      toString in class Object