Package ftclib.driverio
Class FtcDashboard
java.lang.Object
trclib.driverio.TrcDashboard
ftclib.driverio.FtcDashboard
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
FieldsModifier and TypeFieldDescriptionprivate 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
ConstructorsModifierConstructorDescriptionprivate
FtcDashboard
(org.firstinspires.ftc.robotcore.external.Telemetry telemetry, int numLines) Constructor: Creates an instance of the object. -
Method Summary
Modifier and TypeMethodDescriptionprivate 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
getBoolean
(String key) 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.static FtcDashboard
This static method returns the instance of this object if one already exist, returns null if none existed.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.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.double
This method returns the value of the named double data read from the Telemetry class.double
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.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
This method sets the named double data with the given value and also sends it to the Driver Station.void
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
-
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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 classTrcDashboard
-
refreshDisplay
public void refreshDisplay()This method refresh the display lines on the Driver Station.- Specified by:
refreshDisplay
in classTrcDashboard
-
displayPrintf
This method displays a formatted message in the specified display line on the Driver Station.- Specified by:
displayPrintf
in classTrcDashboard
- Parameters:
lineNum
- specifies the line number on the display.msg
- specifies the message string.
-
displayPrintf
This method displays a formatted message in the specified display line on the Driver Station.- Specified by:
displayPrintf
in classTrcDashboard
- Parameters:
lineNum
- specifies the line number on the display.format
- specifies the format string.args
- specifies variable number of substitution arguments.
-
getBoolean
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 classTrcDashboard
- 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
This method sets the named boolean data with the given value and also sends it to the Driver Station.- Specified by:
putBoolean
in classTrcDashboard
- Parameters:
key
- specifies the name associated with the boolean data.value
- specifies the data value.
-
getNumber
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 classTrcDashboard
- 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
This method sets the named double data with the given value and also sends it to the Driver Station.- Specified by:
putNumber
in classTrcDashboard
- Parameters:
key
- specifies the name associated with the double data.value
- specifies the data value.
-
getString
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 classTrcDashboard
- 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
This method sets the named string data with the given value and also sends it to the Driver Station.- Specified by:
putString
in classTrcDashboard
- Parameters:
key
- specifies the name associated with the string data.value
- specifies the data value.
-