WPILibC++ 2027.0.0-alpha-4
Loading...
Searching...
No Matches
Alert.hpp
Go to the documentation of this file.
1// Copyright (c) FIRST and other WPILib contributors.
2// Open Source Software; you can modify and/or share it under the terms of
3// the WPILib BSD license file in the root directory of this project.
4
5#pragma once
6
7#include <string>
8#include <string_view>
9
10#include "wpi/hal/Alert.h"
11#include "wpi/hal/Types.hpp"
12
13namespace wpi {
14
15/**
16 * Persistent alert to be sent to the driver station. Alerts are tagged with a
17 * type of HIGH/ERROR, MEDIUM/WARNING, or LOW/INFO to denote urgency. See
18 * Alert::Level for suggested usage of each type. Alerts can be displayed on
19 * supported dashboards, and are shown in a priority order based on type and
20 * recency of activation, with newly activated alerts first.
21 *
22 * Alerts should be created once and stored persistently, then updated to
23 * "active" or "inactive" as necessary. Set(bool) can be safely called
24 * periodically.
25 *
26 * <pre>
27 * class Robot {
28 * wpi::Alert alert{"Something went wrong", wpi::Alert::Level::WARNING};
29 * }
30 *
31 * Robot::periodic() {
32 * alert.Set(...);
33 * }
34 * </pre>
35 */
36class Alert {
37 public:
38 /**
39 * Represents an alert's level of urgency.
40 */
41 enum class Level {
42 /**
43 * High priority alert - displayed first with a red "X"
44 * symbol. Use this type for problems which will seriously affect the
45 * robot's functionality and thus require immediate attention.
46 */
48
49 /** Alternate name for a high priority alert. */
51
52 /**
53 * Medium priority alert - displayed second with a yellow "!" symbol.
54 * Use this type for problems which could affect the robot's functionality
55 * but do not necessarily require immediate attention.
56 */
58
59 /** Alternate name for a medium priority alert. */
61
62 /**
63 * Low priority alert - displayed last with a green "i" symbol. Use this
64 * type for problems which are unlikely to affect the robot's functionality,
65 * or any other alerts which do not fall under the other categories.
66 */
68
69 /** Alternate name for a low priority alert. */
71 };
72
73 /**
74 * Creates a new alert in the default group - "Alerts". If this is the first
75 * to be instantiated, the appropriate entries will be added to NetworkTables.
76 *
77 * @param text Text to be displayed when the alert is active.
78 * @param level Alert urgency level.
79 */
80 Alert(std::string_view text, Level level);
81
82 /**
83 * Creates a new alert. If this is the first to be instantiated in its group,
84 * the appropriate entries will be added to NetworkTables.
85 *
86 * @param group Group identifier, used as the entry name in NetworkTables.
87 * @param text Text to be displayed when the alert is active.
88 * @param level Alert urgency level.
89 */
90 Alert(std::string_view group, std::string_view text, Level level);
91
92 /**
93 * Sets whether the alert should currently be displayed. This method can be
94 * safely called periodically.
95 *
96 * @param active Whether to display the alert.
97 */
98 void Set(bool active);
99
100 /**
101 * Gets whether the alert is active.
102 * @return whether the alert is active.
103 */
104 bool Get() const;
105
106 /**
107 * Updates current alert text. Use this method to dynamically change the
108 * displayed alert, such as including more details about the detected problem.
109 *
110 * @param text Text to be displayed when the alert is active.
111 */
112 void SetText(std::string_view text);
113
114 /**
115 * Gets the current alert text.
116 * @return the current text.
117 */
118 std::string GetText() const;
119
120 /**
121 * Get the type of this alert.
122 * @return the type
123 */
124 Level GetType() const { return m_type; }
125
126 private:
127 Level m_type;
129};
130
131} // namespace wpi
Level
Represents an alert's level of urgency.
Definition Alert.hpp:41
@ WARNING
Alternate name for a medium priority alert.
Definition Alert.hpp:60
@ LOW
Low priority alert - displayed last with a green "i" symbol.
Definition Alert.hpp:67
@ INFO
Alternate name for a low priority alert.
Definition Alert.hpp:70
@ HIGH
High priority alert - displayed first with a red "X" symbol.
Definition Alert.hpp:47
@ ERROR
Alternate name for a high priority alert.
Definition Alert.hpp:50
@ MEDIUM
Medium priority alert - displayed second with a yellow "!" symbol.
Definition Alert.hpp:57
bool Get() const
Gets whether the alert is active.
std::string GetText() const
Gets the current alert text.
Alert(std::string_view text, Level level)
Creates a new alert in the default group - "Alerts".
void SetText(std::string_view text)
Updates current alert text.
Level GetType() const
Get the type of this alert.
Definition Alert.hpp:124
void Set(bool active)
Sets whether the alert should currently be displayed.
Alert(std::string_view group, std::string_view text, Level level)
Creates a new alert.
A move-only C++ wrapper around a HAL handle.
Definition Types.hpp:16
@ HAL_ALERT_MEDIUM
Medium priority alert - displayed second with a yellow "!" symbol.
Definition Alert.h:37
@ HAL_ALERT_LOW
Low priority alert - displayed last with a green "i" symbol.
Definition Alert.h:45
@ HAL_ALERT_HIGH
High priority alert - displayed first with a red "X" symbol.
Definition Alert.h:29
Definition CvSource.hpp:15