WPILibC++ 2027.0.0-alpha-4
Loading...
Searching...
No Matches
wpi::Alert Class Reference

Persistent alert to be sent to the driver station. More...

#include <wpi/driverstation/Alert.hpp>

Public Types

enum class  Level {
  HIGH = HAL_ALERT_HIGH , ERROR = HIGH , MEDIUM = HAL_ALERT_MEDIUM , WARNING = MEDIUM ,
  LOW = HAL_ALERT_LOW , INFO = LOW
}
 Represents an alert's level of urgency. More...

Public Member Functions

 Alert (std::string_view text, Level level)
 Creates a new alert in the default group - "Alerts".
 Alert (std::string_view group, std::string_view text, Level level)
 Creates a new alert.
void Set (bool active)
 Sets whether the alert should currently be displayed.
bool Get () const
 Gets whether the alert is active.
void SetText (std::string_view text)
 Updates current alert text.
std::string GetText () const
 Gets the current alert text.
Level GetType () const
 Get the type of this alert.

Detailed Description

Persistent alert to be sent to the driver station.

Alerts are tagged with a type of HIGH/ERROR, MEDIUM/WARNING, or LOW/INFO to denote urgency. See Alert::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(bool) can be safely called periodically.

class Robot {
  wpi::Alert alert{"Something went wrong", wpi::Alert::Level::WARNING};
}

Robot::periodic() {
  alert.Set(...);
}

Member Enumeration Documentation

◆ Level

enum class wpi::Alert::Level
strong

Represents an alert's level of urgency.

Enumerator
HIGH 

High priority alert - displayed first with a red "X" symbol.

Use this type for problems which will seriously affect the robot's functionality and thus require immediate attention.

ERROR 

Alternate name for a high priority alert.

MEDIUM 

Medium priority alert - displayed second with a yellow "!" symbol.

Use this type for problems which could affect the robot's functionality but do not necessarily require immediate attention.

WARNING 

Alternate name for a medium priority alert.

LOW 

Low priority alert - displayed last with a green "i" symbol.

Use this type for problems which are unlikely to affect the robot's functionality, or any other alerts which do not fall under the other categories.

INFO 

Alternate name for a low priority alert.

Constructor & Destructor Documentation

◆ Alert() [1/2]

wpi::Alert::Alert ( std::string_view text,
Level level )

Creates a new alert in the default group - "Alerts".

If this is the first to be instantiated, the appropriate entries will be added to NetworkTables.

Parameters
textText to be displayed when the alert is active.
levelAlert urgency level.

◆ Alert() [2/2]

wpi::Alert::Alert ( std::string_view group,
std::string_view text,
Level level )

Creates a new alert.

If this is the first to be instantiated in its group, the appropriate entries will be added to NetworkTables.

Parameters
groupGroup identifier, used as the entry name in NetworkTables.
textText to be displayed when the alert is active.
levelAlert urgency level.

Member Function Documentation

◆ Get()

bool wpi::Alert::Get ( ) const

Gets whether the alert is active.

Returns
whether the alert is active.

◆ GetText()

std::string wpi::Alert::GetText ( ) const

Gets the current alert text.

Returns
the current text.

◆ GetType()

Level wpi::Alert::GetType ( ) const
inline

Get the type of this alert.

Returns
the type

◆ Set()

void wpi::Alert::Set ( bool active)

Sets whether the alert should currently be displayed.

This method can be safely called periodically.

Parameters
activeWhether to display the alert.

◆ SetText()

void wpi::Alert::SetText ( std::string_view text)

Updates current alert text.

Use this method to dynamically change the displayed alert, such as including more details about the detected problem.

Parameters
textText to be displayed when the alert is active.

The documentation for this class was generated from the following file: