Class Alert

java.lang.Object
org.wpilib.util.Alert
All Implemented Interfaces:
AutoCloseable

public class Alert extends Object implements AutoCloseable
Persistent alert. Alerts are tagged with a type of HIGH, MEDIUM, or LOW to denote urgency. See Level for suggested usage of each type. Alerts can be displayed on supported dashboards, and are shown in a priority order based on type and recency of activation, with newly activated alerts first.

Alerts should be created once and stored persistently, then updated to "active" or "inactive" as necessary. set(boolean) can be safely called periodically.

class Robot {
  Alert alert = new Alert("somethingWrong", "Something went wrong", Alert.Level.MEDIUM);

  periodic() {
    alert.set(...);
  }
}

Alternatively, alerts which are only used once at startup can be created and activated inline.

public Robot() {
  new Alert("autoPathsFailed", "Failed to load auto paths", Alert.Level.HIGH).set(true);
}
  • Constructor Details

    • Alert

      public Alert(String id, String text, Alert.Level level)
      Creates a new alert in the default group - "Alerts".
      Parameters:
      id - Alert identifier. This should be unique within the group.
      text - Text to be displayed when the alert is active.
      level - Alert urgency level.
    • Alert

      public Alert(String group, String id, String text, Alert.Level level)
      Creates a new alert.
      Parameters:
      group - Group identifier.
      id - Alert identifier. This should be unique within the group.
      text - Text to be displayed when the alert is active.
      level - Alert urgency level.
  • Method Details

    • set

      public void set(boolean active)
      Sets whether the alert should currently be displayed. This method can be safely called periodically.
      Parameters:
      active - Whether to display the alert.
    • get

      public boolean get()
      Gets whether the alert is active.
      Returns:
      whether the alert is active.
    • setText

      public void setText(String text)
      Updates current alert text. Use this method to dynamically change the displayed alert, such as including more details about the detected problem.
      Parameters:
      text - Text to be displayed when the alert is active.
    • getText

      public String getText()
      Gets the current alert text.
      Returns:
      the current text.
    • getLevel

      public Alert.Level getLevel()
      Get the level of this alert.
      Returns:
      the level
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable