Class SettingsFile

java.lang.Object
com.crossbotics.ftchelper.core.SettingsFile

public final class SettingsFile extends Object
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. In the simulator it is in the simulator's data folder instead (see folder()).

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 Details

    • SettingsFile

      public SettingsFile(File file)
      A settings file at a path you choose (used by tests).
      Parameters:
      file - the file to read and write
  • Method Details

    • folder

      public static File folder()
      The folder for the helper's files (settings, finder results, logs): /sdcard/FIRST/ftc-helper on the robot. The simulator sets the Java setting ftchelper.dataDir to keep them on the laptop instead (a laptop has no /sdcard, so saving there would fail).
      Returns:
      the folder (it may not exist yet; savers make it)
    • shared

      public static SettingsFile shared()
      The robot's settings file (settings.properties in folder()).
    • useForTests

      public static void useForTests(SettingsFile file)
      For tests: use another file as the shared one. Pass null to go back to the robot's file.
    • get

      public String get(String key, String fallback)
      A saved text value, or fallback if none is saved.
      Parameters:
      key - the name the value is saved under
      fallback - what to return when nothing is saved
    • getDouble

      public double getDouble(String key, double fallback)
      A saved number, or fallback if none is saved or it is not a number.
      Parameters:
      key - the name the value is saved under
      fallback - what to return when nothing usable is saved
    • has

      public boolean has(String key)
      True if a value is saved under this key.
    • put

      public void put(String key, String value)
      Sets a value in memory. Call save() to write it to the file.
      Parameters:
      key - the name to save it under
      value - the text to save; null removes the key
    • remove

      public void remove(String key)
      Removes a value. Call save() after.
    • save

      public boolean save()
      Writes the file. This WAITS for the storage (a few milliseconds, sometimes more): in a running OpMode use saveInBackground(java.util.function.Consumer<java.lang.Boolean>) instead.
      Returns:
      true if it worked. False (for example no storage) never stops the robot.
    • saveInBackground

      public void saveInBackground(Consumer<Boolean> whenDone)
      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.