CTRE Phoenix 6 C++ 26.70.0-alpha-2
Loading...
Searching...
No Matches
Alerts.hpp
Go to the documentation of this file.
1/*
2 * Copyright (C) Cross The Road Electronics.  All rights reserved.
3 * License information can be found in CTRE_LICENSE.txt
4 * For support and suggestions contact support@ctr-electronics.com or file
5 * an issue tracker at https://github.com/CrossTheRoadElec/Phoenix-Releases
6 */
7#pragma once
8
9#include <optional>
10#include <stdint.h>
11#include <string>
12#include <wpi/units/time.hpp>
13
14namespace ctre {
15namespace phoenix6 {
16
17 /**
18 * \brief Persistent alert with debouncing.
19 *
20 * On a FIRST robot controller, this shows up as a persistent
21 * alert in the Driver Station and compatible NetworkTables
22 * dashboards. Otherwise, this is a no-op.
23 */
24 class PhoenixAlert final {
25 private:
26 uint64_t handle{};
27
28 public:
29 /**
30 * \brief Levels of urgency of the alert.
31 */
32 enum class Level {
33 /** \brief High priority / Error */
34 High = 0,
35 /** \brief Medium priority / Warning */
36 Medium = 1,
37 /** \brief Low priority / Info */
38 Low = 2,
39 };
40
41 /**
42 * \brief Creates an invalid alert.
43 */
44 PhoenixAlert() = default;
45
46 /**
47 * \brief Creates a new alert.
48 *
49 * \param group Group identifier
50 * \param id Alert identifier, unique within the group
51 * \param level Alert urgency level
52 * \param text Alert text to display when the alert is active
53 */
54 PhoenixAlert(char const *group, char const *id, Level level, char const *text = "");
55
56 /**
57 * \brief Creates a new alert.
58 *
59 * \param group Group identifier
60 * \param id Alert identifier, unique within the group
61 * \param level Alert urgency level
62 * \param text Alert text to display when the alert is active
63 */
64 PhoenixAlert(std::string const &group, std::string const &id, Level level, std::string const &text = "") :
65 PhoenixAlert{group.c_str(), id.c_str(), level, text.c_str()}
66 {}
67
68 /**
69 * \returns Whether this alert is valid
70 */
71 bool IsValid() const { return !!handle; }
72
73 /**
74 * \returns Whether this alert is valid
75 */
76 explicit operator bool() const { return IsValid(); }
77
78 /**
79 * \brief Sets the time debounce of this alert, default 1 second.
80 *
81 * \param debounce Debounce time
82 * \returns This alert
83 */
84 PhoenixAlert &WithDebounce(wpi::units::second_t debounce);
85
86 /**
87 * \brief Sets the alert state to active and optionally changes the text.
88 * This should be called periodically, even if the active state does not
89 * change.
90 *
91 * \param text New text to display
92 */
93 void SetActive(char const *text = nullptr);
94
95 /**
96 * \brief Sets the alert state to active and optionally changes the text.
97 * This should be called periodically, even if the active state does not
98 * change.
99 *
100 * \param text New text to display
101 */
102 void SetActive(std::optional<std::string> const &text)
103 {
104 SetActive(text ? text->c_str() : nullptr);
105 }
106
107 /**
108 * \brief Sets the alert state to inactive.
109 */
111 };
112
113 /**
114 * \brief Persistent multi-level alert with debouncing.
115 *
116 * On a FIRST robot controller, this shows up as a persistent
117 * alert in the Driver Station and compatible NetworkTables
118 * dashboards. Otherwise, this is a no-op.
119 */
120 class PhoenixMultiAlert final {
121 private:
122 uint64_t handle{};
123
124 public:
126
127 /** \brief Include High priority / Error */
128 static constexpr uint32_t LevelFlag_High = 1 << (int)Level::High;
129 /** \brief Include Medium priority / Warning */
130 static constexpr uint32_t LevelFlag_Medium = 1 << (int)Level::Medium;
131 /** \brief Include Low priority / Info */
132 static constexpr uint32_t LevelFlag_Low = 1 << (int)Level::Low;
133
134 /**
135 * \brief Creates an invalid multi-level alert.
136 */
137 PhoenixMultiAlert() = default;
138
139 /**
140 * \brief Creates a new multi-level alert.
141 *
142 * \param group Group identifier
143 * \param id Alert identifier, unique within the group
144 * \param levelFlags Alert urgency levels to include
145 * \param text Alert text to display when the alert is active
146 */
147 PhoenixMultiAlert(char const *group, char const *id, uint32_t levelFlags, char const *text = "");
148
149 /**
150 * \brief Creates a new multi-level alert.
151 *
152 * \param group Group identifier
153 * \param id Alert identifier, unique within the group
154 * \param levelFlags Alert urgency levels to include
155 * \param text Alert text to display when the alert is active
156 */
157 PhoenixMultiAlert(std::string const &group, std::string const &id, uint32_t levelFlags, std::string const &text = "") :
158 PhoenixMultiAlert{group.c_str(), id.c_str(), levelFlags, text.c_str()}
159 {}
160
161 /**
162 * \returns Whether this alert is valid
163 */
164 bool IsValid() const { return !!handle; }
165
166 /**
167 * \returns Whether this alert is valid
168 */
169 explicit operator bool() const { return IsValid(); }
170
171 /**
172 * \brief Sets the time debounce of this alert, default 1 second.
173 *
174 * \param debounce Debounce time
175 * \returns This alert
176 */
177 PhoenixMultiAlert &WithDebounce(wpi::units::second_t debounce);
178
179 /**
180 * \brief Sets the alert state to active at the given level and optionally changes
181 * the text. This should be called periodically, even if the active state does not
182 * change.
183 *
184 * \param level New alert urgency level
185 * \param text New text to display
186 */
187 void SetActive(Level level, char const *text = nullptr);
188
189 /**
190 * \brief Sets the alert state to active at the given level and optionally changes
191 * the text. This should be called periodically, even if the active state does not
192 * change.
193 *
194 * \param level New alert urgency level
195 * \param text New text to display
196 */
197 void SetActive(Level level, std::optional<std::string> const &text)
198 {
199 SetActive(level, text ? text->c_str() : nullptr);
200 }
201
202 /**
203 * \brief Sets the alert state to inactive.
204 */
206 };
207
208}
209}
Cross the Road Electronics End User License Agreement This Software License or “Customer” and Cross The Road Electronics a Michigan based company with its principal place of business located at MI Terms Agreement this End User License Agreement that forms the entire agreement between You and the Company regarding the use of the Software CAN BUS a communication standard designed to allow hardware devices to communicate with each other Leone USA Content refers to content such as text
Definition CTRE_LICENSE.txt:15
Level
Levels of urgency of the alert.
Definition Alerts.hpp:32
@ Low
Low priority / Info.
Definition Alerts.hpp:38
@ High
High priority / Error.
Definition Alerts.hpp:34
@ Medium
Medium priority / Warning.
Definition Alerts.hpp:36
PhoenixAlert(char const *group, char const *id, Level level, char const *text="")
Creates a new alert.
PhoenixAlert()=default
Creates an invalid alert.
bool IsValid() const
Definition Alerts.hpp:71
void SetInactive()
Sets the alert state to inactive.
PhoenixAlert & WithDebounce(wpi::units::second_t debounce)
Sets the time debounce of this alert, default 1 second.
void SetActive(std::optional< std::string > const &text)
Sets the alert state to active and optionally changes the text.
Definition Alerts.hpp:102
void SetActive(char const *text=nullptr)
Sets the alert state to active and optionally changes the text.
PhoenixAlert(std::string const &group, std::string const &id, Level level, std::string const &text="")
Creates a new alert.
Definition Alerts.hpp:64
PhoenixAlert::Level Level
Definition Alerts.hpp:125
static constexpr uint32_t LevelFlag_Low
Include Low priority / Info.
Definition Alerts.hpp:132
void SetActive(Level level, std::optional< std::string > const &text)
Sets the alert state to active at the given level and optionally changes the text.
Definition Alerts.hpp:197
static constexpr uint32_t LevelFlag_High
Include High priority / Error.
Definition Alerts.hpp:128
static constexpr uint32_t LevelFlag_Medium
Include Medium priority / Warning.
Definition Alerts.hpp:130
PhoenixMultiAlert & WithDebounce(wpi::units::second_t debounce)
Sets the time debounce of this alert, default 1 second.
PhoenixMultiAlert(std::string const &group, std::string const &id, uint32_t levelFlags, std::string const &text="")
Creates a new multi-level alert.
Definition Alerts.hpp:157
bool IsValid() const
Definition Alerts.hpp:164
PhoenixMultiAlert()=default
Creates an invalid multi-level alert.
void SetActive(Level level, char const *text=nullptr)
Sets the alert state to active at the given level and optionally changes the text.
PhoenixMultiAlert(char const *group, char const *id, uint32_t levelFlags, char const *text="")
Creates a new multi-level alert.
void SetInactive()
Sets the alert state to inactive.
Definition ExternalFeedbackConfigs.hpp:16
Definition motor_constants.h:14