Package com.reduxrobotics.canand
Class CanandSettings
java.lang.Object
com.reduxrobotics.canand.CanandSettings
- Direct Known Subclasses:
CanandcolorSettings
,CanandgyroSettings
,CanandmagSettings
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
-
Constructor Summary
ConstructorDescriptionDefault constructor.Clone constructor. -
Method Summary
Modifier and TypeMethodDescriptionboolean
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.getBool
(int idx) Gets a boolean from the internal Map if it exists and return true, false, or nullReturn a direct filtered view of settings values as a newMap
, limited to only valid settings.getFloatAsDouble
(int idx, double divisor) Gets an integer from the internal Map if it exists and return a scaled user value.getIntAsDouble
(int idx, double divisor) Gets an integer from the internal Map if it exists and return a scaled user value.getMap()
Directly access the underlyingMap
of settings values.Generates a list of setting indexes missing from this object to be considered "complete".boolean
isEmpty()
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.toString()
-
Field Details
-
values
The backing Map of raw setting indexes to raw setting values (serialized as Long) -
ephemeral
protected boolean ephemeralWhether the settings will be applied ephemerally.
-
-
Constructor Details
-
CanandSettings
public CanandSettings()Default constructor. -
CanandSettings
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
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 valuerawVal
- The raw inputted double valuemin
- The minimum valid integer valuemax
- The maximum value integer valuescale
- 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
Gets an integer from the internal Map if it exists and return a scaled user value.- Parameters:
idx
- the setting index to pulldivisor
- how much to divide the integer value by- Returns:
- a scaled double if the setting exists else null
-
getFloatAsDouble
Gets an integer from the internal Map if it exists and return a scaled user value.- Parameters:
idx
- the setting index to pulldivisor
- how much to divide the float value by- Returns:
- a scaled double if the setting exists else null
-
getBool
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
Directly access the underlyingMap
of settings values. Intended for internal use.- Returns:
- map
-
getFilteredMap
Return a direct filtered view of settings values as a newMap
, 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
Generates a list of setting indexes missing from this object to be considered "complete".- Returns:
- List of missing setting indexes.
-
toString
-