WPILibC++ 2027.0.0-alpha-5
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, MEDIUM, or LOW 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::MEDIUM};
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 /**
50 * Medium priority alert - displayed second with a yellow "!" symbol.
51 * Use this type for problems which could affect the robot's functionality
52 * but do not necessarily require immediate attention.
53 */
55
56 /**
57 * Low priority alert - displayed last with a green "i" symbol. Use this
58 * type for problems which are unlikely to affect the robot's functionality,
59 * or any other alerts which do not fall under the other categories.
60 */
62 };
63
64 /**
65 * Creates a new alert in the default group - "Alerts". If this is the first
66 * to be instantiated, the appropriate entries will be added to NetworkTables.
67 *
68 * @param text Text to be displayed when the alert is active.
69 * @param level Alert urgency level.
70 */
71 Alert(std::string_view text, Level level);
72
73 /**
74 * Creates a new alert. If this is the first to be instantiated in its group,
75 * the appropriate entries will be added to NetworkTables.
76 *
77 * @param group Group identifier, used as the entry name in NetworkTables.
78 * @param text Text to be displayed when the alert is active.
79 * @param level Alert urgency level.
80 */
81 Alert(std::string_view group, std::string_view text, Level level);
82
83 /**
84 * Sets whether the alert should currently be displayed. This method can be
85 * safely called periodically.
86 *
87 * @param active Whether to display the alert.
88 */
89 void Set(bool active);
90
91 /**
92 * Gets whether the alert is active.
93 * @return whether the alert is active.
94 */
95 bool Get() const;
96
97 /**
98 * Updates current alert text. Use this method to dynamically change the
99 * displayed alert, such as including more details about the detected problem.
100 *
101 * @param text Text to be displayed when the alert is active.
102 */
103 void SetText(std::string_view text);
104
105 /**
106 * Gets the current alert text.
107 * @return the current text.
108 */
109 std::string GetText() const;
110
111 /**
112 * Get the type of this alert.
113 * @return the type
114 */
115 Level GetType() const { return m_type; }
116
117 private:
118 Level m_type;
120};
121
122} // namespace wpi
Level
Represents an alert's level of urgency.
Definition Alert.hpp:41
@ LOW
Low priority alert - displayed last with a green "i" symbol.
Definition Alert.hpp:61
@ HIGH
High priority alert - displayed first with a red "X" symbol.
Definition Alert.hpp:47
@ MEDIUM
Medium priority alert - displayed second with a yellow "!" symbol.
Definition Alert.hpp:54
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:115
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:36
@ HAL_ALERT_LOW
Low priority alert - displayed last with a green "i" symbol.
Definition Alert.h:43
@ HAL_ALERT_HIGH
High priority alert - displayed first with a red "X" symbol.
Definition Alert.h:29
Definition CvSource.hpp:15