Class FtcDashboard

java.lang.Object
trclib.driverio.TrcDashboard
ftclib.driverio.FtcDashboard

public class FtcDashboard extends TrcDashboard
This class is a wrapper for the Telemetry class. In addition to providing a way to send named data to the Driver Station to be displayed, it also simulates an LCD display similar to the NXT Mindstorms. The Mindstorms has only 8 lines but this dashboard can support as many lines as the Driver Station can support. By default, we set the number of lines to 16. By providing the numLines parameter when calling createInstance, you can have as many lines as you want. This dashboard display is very useful for displaying debug information. In particular, the TrcMenu class uses the dashboard to display a choice menu and interact with the user for choosing autonomous strategies and options.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private final org.firstinspires.ftc.robotcore.external.Telemetry.Item[]
     
    private org.firstinspires.ftc.robotcore.external.Telemetry.DisplayFormat
     
    private android.graphics.Paint
     
    private final org.firstinspires.ftc.robotcore.external.Telemetry
     

    Fields inherited from class trclib.driverio.TrcDashboard

    displayKeyFormat, instance, MAX_NUM_TEXTLINES, numLines
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    private
    FtcDashboard(org.firstinspires.ftc.robotcore.external.Telemetry telemetry, int numLines)
    Constructor: Creates an instance of the object.
  • Method Summary

    Modifier and Type
    Method
    Description
    private String
    centeredText(int totalWidth, String text)
    This method calculates the number of padding spaces to be inserted in front of the original text so that the text will be centered within the given pixel width.
    void
    This method clears all the display lines.
    void
    displayCenterPrintf(int lineNum, int fieldWidth, String format, Object... args)
    This method centers a formatted message in the specified display line on the Driver Station.
    void
    displayCenterText(int lineNum, String text, int fieldWidth)
    This method centers a text message in the specified display line on the Driver Station.
    void
    displayHTMLText(int lineNum, String text)
    This method displays the HTML text message in the specified display line on the Driver Station.
    void
    displayPrintf(int lineNum, int labelWidth, String labelText, String format, Object... args)
    This method displays a formatted message in the specified display line on the Driver Station.
    void
    displayPrintf(int lineNum, String msg)
    This method displays a formatted message in the specified display line on the Driver Station.
    void
    displayPrintf(int lineNum, String format, Object... args)
    This method displays a formatted message in the specified display line on the Driver Station.
    void
    displayRightPrintf(int lineNum, int fieldWidth, String format, Object... args)
    This method right justified a formatted message in the specified display line on the Driver Station.
    void
    displayRightText(int lineNum, String text, int fieldWidth)
    This method right justifies a text message in the specified display line on the Driver Station.
    void
    displayText(int lineNum, String text)
    This method displays a text message in the specified display line on the Driver Station.
    void
    displayText(int lineNum, String text, int fieldWidth, boolean rightJustified)
    This method displays a text message in the specified display line on the Driver Station.
    void
    displayText(int lineNum, String colorAttrib, String text)
    This method displays a text message in the specified display line on the Driver Station.
    void
    displayText(int lineNum, String text, String colorAttrib, int fieldWidth, boolean rightJustified)
    This method displays a text message in the specified display line on the Driver Station.
    boolean
    This method returns the value of the named boolean data read from the Telemetry class.
    boolean
    getBoolean(String key, boolean defaultValue)
    This method returns the value of the named boolean data read from the Telemetry class.
    This static method returns the instance of this object if one already exist, returns null if none existed.
    getInstance(org.firstinspires.ftc.robotcore.external.Telemetry telemetry)
    This static method returns the instance of this object if one already exist, creates it if none existed.
    getInstance(org.firstinspires.ftc.robotcore.external.Telemetry telemetry, int numLines)
    This static method returns the instance of this object if one already exist, creates it if none existed.
    double
    This method returns the value of the named double data read from the Telemetry class.
    double
    getNumber(String key, double defaultValue)
    This method returns the value of the named double data read from the Telemetry class.
    This method returns the value of the named string data read from the Telemetry class.
    getString(String key, String defaultValue)
    This method returns the value of the named string data read from the Telemetry class.
    private String
    This method calls Telemetry class to retrieve the named data item.
    void
    putBoolean(String key, boolean value)
    This method sets the named boolean data with the given value and also sends it to the Driver Station.
    void
    putNumber(String key, double value)
    This method sets the named double data with the given value and also sends it to the Driver Station.
    void
    putString(String key, String value)
    This method sets the named string data with the given value and also sends it to the Driver Station.
    void
    This method refresh the display lines on the Driver Station.
    private String
    rightJustifiedText(int totalWidth, String text)
    This method calculates the number of padding spaces to be inserted in front of the original text so that the text will be right justified within the given pixel width.
    void
    setDisplayFormat(org.firstinspires.ftc.robotcore.external.Telemetry.DisplayFormat displayFormat)
    This sets the telemetry display format.
    void
    setTextView(android.widget.TextView textView)
    This method sets the TextView object from which to query the typeface measurement for centering/right justifying messages.

    Methods inherited from class trclib.driverio.TrcDashboard

    getNumTextLines

    Methods inherited from class java.lang.Object

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

    • telemetry

      private final org.firstinspires.ftc.robotcore.external.Telemetry telemetry
    • paint

      private android.graphics.Paint paint
    • display

      private final org.firstinspires.ftc.robotcore.external.Telemetry.Item[] display
    • displayFormat

      private org.firstinspires.ftc.robotcore.external.Telemetry.DisplayFormat displayFormat
  • Constructor Details

    • FtcDashboard

      private FtcDashboard(org.firstinspires.ftc.robotcore.external.Telemetry telemetry, int numLines)
      Constructor: Creates an instance of the object. There should only be one global instance of this object. Typically, only the FtcOpMode object should construct an instance of this object via getInstance(telemetry) and nobody else.
      Parameters:
      telemetry - specifies the Telemetry object.
      numLines - specifies the number of display lines.
  • Method Details

    • getInstance

      public static FtcDashboard getInstance(org.firstinspires.ftc.robotcore.external.Telemetry telemetry, int numLines)
      This static method returns the instance of this object if one already exist, creates it if none existed.
      Parameters:
      telemetry - specifies the Telemetry object.
      numLines - specifies the number of display lines.
      Returns:
      existing instance or newly created instance of the object.
    • getInstance

      public static FtcDashboard getInstance(org.firstinspires.ftc.robotcore.external.Telemetry telemetry)
      This static method returns the instance of this object if one already exist, creates it if none existed.
      Parameters:
      telemetry - specifies the Telemetry object.
      Returns:
      existing instance or newly created instance of the object.
    • getInstance

      public static FtcDashboard getInstance()
      This static method returns the instance of this object if one already exist, returns null if none existed.
      Returns:
      existing instance or null if none existing.
    • getBoolean

      public boolean getBoolean(String key)
      This method returns the value of the named boolean data read from the Telemetry class.
      Parameters:
      key - specifies the name associated with the boolean data.
      Returns:
      boolean data value.
    • getNumber

      public double getNumber(String key)
      This method returns the value of the named double data read from the Telemetry class.
      Parameters:
      key - specifies the name associated with the double data.
      Returns:
      double data value.
    • getString

      public String getString(String key)
      This method returns the value of the named string data read from the Telemetry class.
      Parameters:
      key - specifies the name associated with the string data.
      Returns:
      string data value.
    • getValue

      private String getValue(String key)
      This method calls Telemetry class to retrieve the named data item.
      Parameters:
      key - specifies the name associated with the string data.
      Returns:
      string data associated with the given name.
    • rightJustifiedText

      private String rightJustifiedText(int totalWidth, String text)
      This method calculates the number of padding spaces to be inserted in front of the original text so that the text will be right justified within the given pixel width. The resulted string will be returned.
      Parameters:
      totalWidth - specifies the total pixel width.
      text - specifies the text string.
      Returns:
      new string that has prepended padding spaces.
    • centeredText

      private String centeredText(int totalWidth, String text)
      This method calculates the number of padding spaces to be inserted in front of the original text so that the text will be centered within the given pixel width. The resulted string will be returned.
      Parameters:
      totalWidth - specifies the total pixel width.
      text - specifies the text string.
      Returns:
      new string that has prepended padding spaces.
    • setTextView

      public void setTextView(android.widget.TextView textView)
      This method sets the TextView object from which to query the typeface measurement for centering/right justifying messages. You don't need to call this method if you never centered or right justified messages on the dashboard.
      Parameters:
      textView - specifies the TextView object.
    • setDisplayFormat

      public void setDisplayFormat(org.firstinspires.ftc.robotcore.external.Telemetry.DisplayFormat displayFormat)
      This sets the telemetry display format.
      Parameters:
      displayFormat - specifies the telemetry display format (e.g. CLASSIC, MONOSPACE, HTML).
    • displayText

      public void displayText(int lineNum, String text, String colorAttrib, int fieldWidth, boolean rightJustified)
      This method displays a text message in the specified display line on the Driver Station.
      Parameters:
      lineNum - specifies the line number on the display.
      text - specifies the text message.
      colorAttrib - specifies the HTML color attribute (only valid if telemetry display format is set to HTML).
      fieldWidth - specified the field width in pixel units that the message will be centered or right justified in. If specified 0, the message will be left justified.
      rightJustified - specifies true if text message is right justified, false if text is centered. fieldWidth must be greater than 0. If not, this parameter is ignored.
    • displayText

      public void displayText(int lineNum, String text, int fieldWidth, boolean rightJustified)
      This method displays a text message in the specified display line on the Driver Station.
      Parameters:
      lineNum - specifies the line number on the display.
      text - specifies the text message.
      fieldWidth - specified the field width in pixel units that the message will be centered or right justified in. If specified 0, the message will be left justified.
      rightJustified - specifies true if text message is right justified, false if text is centered. fieldWidth must be greater than 0. If not, this parameter is ignored.
    • displayText

      public void displayText(int lineNum, String colorAttrib, String text)
      This method displays a text message in the specified display line on the Driver Station.
      Parameters:
      lineNum - specifies the line number on the display.
      text - specifies the text message.
      colorAttrib - specifies the HTML color attribute (only valid if telemetry display format is set to HTML).
    • displayText

      public void displayText(int lineNum, String text)
      This method displays a text message in the specified display line on the Driver Station.
      Parameters:
      lineNum - specifies the line number on the display.
      text - specifies the text message.
    • displayHTMLText

      public void displayHTMLText(int lineNum, String text)
      This method displays the HTML text message in the specified display line on the Driver Station.
      Parameters:
      lineNum - specifies the line number on the display.
      text - specifies the HTML text message.
    • displayCenterText

      public void displayCenterText(int lineNum, String text, int fieldWidth)
      This method centers a text message in the specified display line on the Driver Station.
      Parameters:
      lineNum - specifies the line number on the display.
      text - specifies the text message.
      fieldWidth - specified the field width in pixel units that the message will be centered in.
    • displayRightText

      public void displayRightText(int lineNum, String text, int fieldWidth)
      This method right justifies a text message in the specified display line on the Driver Station.
      Parameters:
      lineNum - specifies the line number on the display.
      text - specifies the text message.
      fieldWidth - specified the field width in pixel units that the message will be right justified in.
    • displayPrintf

      public void displayPrintf(int lineNum, int labelWidth, String labelText, String format, Object... args)
      This method displays a formatted message in the specified display line on the Driver Station.
      Parameters:
      lineNum - specifies the line number on the display.
      labelWidth - specified the label width in pixel units that the label will be right justified in.
      labelText - specifies the label text that will be right justified.
      format - specifies the format string.
      args - specifies variable number of substitution arguments.
    • displayCenterPrintf

      public void displayCenterPrintf(int lineNum, int fieldWidth, String format, Object... args)
      This method centers a formatted message in the specified display line on the Driver Station.
      Parameters:
      lineNum - specifies the line number on the display.
      fieldWidth - specified the field width in pixel units that the message will be centered in.
      format - specifies the format string.
      args - specifies variable number of substitution arguments.
    • displayRightPrintf

      public void displayRightPrintf(int lineNum, int fieldWidth, String format, Object... args)
      This method right justified a formatted message in the specified display line on the Driver Station.
      Parameters:
      lineNum - specifies the line number on the display.
      fieldWidth - specified the field width in pixel units that the message will be right justified in.
      format - specifies the format string.
      args - specifies variable number of substitution arguments.
    • clearDisplay

      public void clearDisplay()
      This method clears all the display lines.
      Specified by:
      clearDisplay in class TrcDashboard
    • refreshDisplay

      public void refreshDisplay()
      This method refresh the display lines on the Driver Station.
      Specified by:
      refreshDisplay in class TrcDashboard
    • displayPrintf

      public void displayPrintf(int lineNum, String msg)
      This method displays a formatted message in the specified display line on the Driver Station.
      Specified by:
      displayPrintf in class TrcDashboard
      Parameters:
      lineNum - specifies the line number on the display.
      msg - specifies the message string.
    • displayPrintf

      public void displayPrintf(int lineNum, String format, Object... args)
      This method displays a formatted message in the specified display line on the Driver Station.
      Specified by:
      displayPrintf in class TrcDashboard
      Parameters:
      lineNum - specifies the line number on the display.
      format - specifies the format string.
      args - specifies variable number of substitution arguments.
    • getBoolean

      public boolean getBoolean(String key, boolean defaultValue)
      This method returns the value of the named boolean data read from the Telemetry class. If the named data does not exist, it is created and assigned the given default value. Then it is sent to the Driver Station.
      Specified by:
      getBoolean in class TrcDashboard
      Parameters:
      key - specifies the name associated with the boolean data.
      defaultValue - specifies the default value if it does not exist.
      Returns:
      boolean data value.
    • putBoolean

      public void putBoolean(String key, boolean value)
      This method sets the named boolean data with the given value and also sends it to the Driver Station.
      Specified by:
      putBoolean in class TrcDashboard
      Parameters:
      key - specifies the name associated with the boolean data.
      value - specifies the data value.
    • getNumber

      public double getNumber(String key, double defaultValue)
      This method returns the value of the named double data read from the Telemetry class. If the named data does not exist, it is created and assigned the given default value. Then it is sent to the Driver Station.
      Specified by:
      getNumber in class TrcDashboard
      Parameters:
      key - specifies the name associated with the double data.
      defaultValue - specifies the default value if it does not exist.
      Returns:
      double data value.
    • putNumber

      public void putNumber(String key, double value)
      This method sets the named double data with the given value and also sends it to the Driver Station.
      Specified by:
      putNumber in class TrcDashboard
      Parameters:
      key - specifies the name associated with the double data.
      value - specifies the data value.
    • getString

      public String getString(String key, String defaultValue)
      This method returns the value of the named string data read from the Telemetry class. If the named data does not exist, it is created and assigned the given default value. Then it is sent to the Driver Station.
      Specified by:
      getString in class TrcDashboard
      Parameters:
      key - specifies the name associated with the string data.
      defaultValue - specifies the default value if it does not exist.
      Returns:
      string data value.
    • putString

      public void putString(String key, String value)
      This method sets the named string data with the given value and also sends it to the Driver Station.
      Specified by:
      putString in class TrcDashboard
      Parameters:
      key - specifies the name associated with the string data.
      value - specifies the data value.