Class CanandSettings

java.lang.Object
com.reduxrobotics.canand.CanandSettings
Direct Known Subclasses:
Canandcoder.Settings, Canandcolor.Settings

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<Byte,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 byte[]
    Gets the list of settings addresses this settings class records.
    protected Boolean
    getBool(byte 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 Double
    getIntAsDouble(byte 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<Byte,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 byte[] 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 Double getIntAsDouble(byte 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
    • getBool

      protected Boolean getBool(byte 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<Byte,Long> getMap()
      Directly access the underlying Map of settings values. Intended for internal use.
      Returns:
      map
    • getFilteredMap

      public Map<Byte,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. Pre-v2024 firmwares will not support this!
      Parameters:
      value - true if ephemeral
    • getMissingIndexes

      public List<Byte> 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