Package com.crossbotics.ftchelper.core
Class SettingsFile
java.lang.Object
com.crossbotics.ftchelper.core.SettingsFile
A small settings file on the Control Hub, so choices and tuned numbers survive a restart.
Used by
Profile and Tunable. You rarely need it directly.
The file is /sdcard/FIRST/ftc-helper/settings.properties on the Control Hub.
You can see it with the REV Hardware Client or Android Studio's Device Explorer.
Inside, each line is key=value, for example profile=PRACTICE. Every value is
stored as text; getDouble(java.lang.String, double) turns it back into a number.
Safety: nothing here ever stops the robot. A missing, damaged or unwritable file only means the values written in the code are used. Docs: docs/modules/core.md
-
Constructor Summary
ConstructorsConstructorDescriptionSettingsFile(File file) A settings file at a path you choose (used by tests). -
Method Summary
Modifier and TypeMethodDescriptionA saved text value, orfallbackif none is saved.doubleA saved number, orfallbackif none is saved or it is not a number.booleanTrue if a value is saved under this key.voidSets a value in memory.voidRemoves a value.booleansave()Writes the file.voidsaveInBackground(Consumer)without a result.voidsaveInBackground(Consumer<Boolean> whenDone) Writes the file on a background thread and returns at once, so the robot loop never waits for the storage.static SettingsFileshared()The robot's settings file.static voiduseForTests(SettingsFile file) For tests: use another file as the shared one.
-
Constructor Details
-
SettingsFile
A settings file at a path you choose (used by tests).- Parameters:
file- the file to read and write
-
-
Method Details
-
useForTests
For tests: use another file as the shared one. Pass null to go back to the robot's file. -
get
A saved text value, orfallbackif none is saved.- Parameters:
key- the name the value is saved underfallback- what to return when nothing is saved
-
getDouble
A saved number, orfallbackif none is saved or it is not a number.- Parameters:
key- the name the value is saved underfallback- what to return when nothing usable is saved
-
has
True if a value is saved under this key. -
put
Sets a value in memory. Callsave()to write it to the file.- Parameters:
key- the name to save it undervalue- the text to save; null removes the key
-
remove
Removes a value. Callsave()after. -
save
public boolean save()Writes the file. This WAITS for the storage (a few milliseconds, sometimes more): in a running OpMode usesaveInBackground(java.util.function.Consumer<java.lang.Boolean>)instead.- Returns:
- true if it worked. False (for example no storage) never stops the robot.
-
saveInBackground
Writes the file on a background thread and returns at once, so the robot loop never waits for the storage. Saves asked for while one is waiting are merged: only the newest values are written.- Parameters:
whenDone- gets true if it worked, false if not (runs on the background thread); may be null
-
saveInBackground
public void saveInBackground()saveInBackground(Consumer)without a result.