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.DisplayFormatprivate android.graphics.Paintprivate final org.firstinspires.ftc.robotcore.external.TelemetryFields inherited from class trclib.driverio.TrcDashboard
displayKeyFormat, instance, MAX_NUM_TEXTLINES, numLines -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivateFtcDashboard(org.firstinspires.ftc.robotcore.external.Telemetry telemetry, int numLines) Constructor: Creates an instance of the object. -
Method Summary
Modifier and TypeMethodDescriptionprivate StringcenteredText(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.voidThis method clears all the display lines.voiddisplayCenterPrintf(int lineNum, int fieldWidth, String format, Object... args) This method centers a formatted message in the specified display line on the Driver Station.voiddisplayCenterText(int lineNum, String text, int fieldWidth) This method centers a text message in the specified display line on the Driver Station.voiddisplayHTMLText(int lineNum, String text) This method displays the HTML text message in the specified display line on the Driver Station.voiddisplayPrintf(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.voiddisplayPrintf(int lineNum, String msg) This method displays a formatted message in the specified display line on the Driver Station.voiddisplayPrintf(int lineNum, String format, Object... args) This method displays a formatted message in the specified display line on the Driver Station.voiddisplayRightPrintf(int lineNum, int fieldWidth, String format, Object... args) This method right justified a formatted message in the specified display line on the Driver Station.voiddisplayRightText(int lineNum, String text, int fieldWidth) This method right justifies a text message in the specified display line on the Driver Station.voiddisplayText(int lineNum, String text) This method displays a text message in the specified display line on the Driver Station.voiddisplayText(int lineNum, String text, int fieldWidth, boolean rightJustified) This method displays a text message in the specified display line on the Driver Station.voiddisplayText(int lineNum, String colorAttrib, String text) This method displays a text message in the specified display line on the Driver Station.voiddisplayText(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.booleangetBoolean(String key) This method returns the value of the named boolean data read from the Telemetry class.booleangetBoolean(String key, boolean defaultValue) This method returns the value of the named boolean data read from the Telemetry class.static FtcDashboardThis static method returns the instance of this object if one already exist, returns null if none existed.static FtcDashboardgetInstance(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 FtcDashboardgetInstance(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.doubleThis method returns the value of the named double data read from the Telemetry class.doubleThis 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 StringThis method calls Telemetry class to retrieve the named data item.voidputBoolean(String key, boolean value) This method sets the named boolean data with the given value and also sends it to the Driver Station.voidThis method sets the named double data with the given value and also sends it to the Driver Station.voidThis method sets the named string data with the given value and also sends it to the Driver Station.voidThis method refresh the display lines on the Driver Station.private StringrightJustifiedText(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.voidsetDisplayFormat(org.firstinspires.ftc.robotcore.external.Telemetry.DisplayFormat displayFormat) This sets the telemetry display format.voidsetTextView(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:
clearDisplayin classTrcDashboard
-
refreshDisplay
public void refreshDisplay()This method refresh the display lines on the Driver Station.- Specified by:
refreshDisplayin classTrcDashboard
-
displayPrintf
This method displays a formatted message in the specified display line on the Driver Station.- Specified by:
displayPrintfin 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:
displayPrintfin 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:
getBooleanin 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:
putBooleanin 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:
getNumberin 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:
putNumberin 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:
getStringin 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:
putStringin classTrcDashboard- Parameters:
key- specifies the name associated with the string data.value- specifies the data value.
-