47 std::optional<std::string>
text{};
63 template <std::convertible_to<std::optional<std::
string>> S = std::optional<std::
string>>
66 return {
true, std::forward<S>(
text)};
79 std::optional<std::string>
text{};
96 template <std::convertible_to<std::optional<std::
string>> S = std::optional<std::
string>>
99 return {
true,
level, std::forward<S>(
text)};
111 std::vector<std::function<void()>> alerts;
112 std::vector<std::function<void()>> beforeAlerts;
132 for (
auto const &func : beforeAlerts) {
135 for (
auto const &alert : alerts) {
148 alertable.RegisterAlerts(*
this);
170 template <std::invocable<AlertableCollection &> F>
184 template <std::invocable<AlertableCollection &> F>
201 template <std::invocable F>
202 requires std::convertible_to<std::invoke_result_t<F>, std::optional<AlertInfo>>
206 if (debounce >= 0_s) {
209 alerts.emplace_back([alert=std::move(alert), infoGetter=std::forward<F>(infoGetter)]()
mutable {
210 std::optional<AlertInfo>
const result = infoGetter();
212 if (result->isActive) {
233 template <std::invocable F>
234 requires std::convertible_to<std::invoke_result_t<F>, std::optional<AlertInfo>>
237 return std::move(
WithAlert(std::move(
id), level, std::forward<F>(infoGetter),
text, debounce));
251 template <std::invocable F>
252 requires std::convertible_to<std::invoke_result_t<F>, std::optional<MultiAlertInfo>>
256 if (debounce >= 0_s) {
259 alerts.emplace_back([alert=std::move(alert), infoGetter=std::forward<F>(infoGetter)]()
mutable {
260 std::optional<MultiAlertInfo>
const result = infoGetter();
262 if (result->isActive) {
263 alert.
SetActive(result->level, result->text);
283 template <std::invocable F>
284 requires std::convertible_to<std::invoke_result_t<F>, std::optional<MultiAlertInfo>>
287 return std::move(
WithMultiAlert(std::move(
id), levelFlags, std::forward<F>(infoGetter),
text, debounce));
299 template <std::invocable F>
302 beforeAlerts.emplace_back(std::forward<F>(func));
315 template <std::invocable F>
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
Collection of objects that can report alerts.
Definition Alertable.hpp:109
AlertableCollection(std::string group)
Constructs a new collection of alertable objects.
Definition Alertable.hpp:120
AlertableCollection && WithAlertable(F const &alertable) &&
Adds an alertable to this collection.
Definition Alertable.hpp:185
AlertableCollection & WithBeforeAlerts(F &&func) &
Adds a function to run before updating any alerts.
Definition Alertable.hpp:300
AlertableCollection && WithMultiAlert(std::string id, uint32_t levelFlags, F &&infoGetter, std::string const &text="", wpi::units::second_t debounce=-1_s) &&
Adds a PhoenixMultiAlert to this collection.
Definition Alertable.hpp:285
AlertableCollection && WithAlert(std::string id, PhoenixAlert::Level level, F &&infoGetter, std::string const &text="", wpi::units::second_t debounce=-1_s) &&
Adds a PhoenixAlert to this collection.
Definition Alertable.hpp:235
AlertableCollection && WithAlertable(PhoenixAlertable &alertable) &&
Adds a PhoenixAlertable to this collection.
Definition Alertable.hpp:158
AlertableCollection & WithAlert(std::string id, PhoenixAlert::Level level, F &&infoGetter, std::string const &text="", wpi::units::second_t debounce=-1_s) &
Adds a PhoenixAlert to this collection.
Definition Alertable.hpp:203
AlertableCollection && WithBeforeAlerts(F &&func) &&
Adds a function to run before updating any alerts.
Definition Alertable.hpp:316
AlertableCollection & operator=(AlertableCollection &&)=default
AlertableCollection(AlertableCollection &&)=default
AlertableCollection & WithAlertable(F const &alertable) &
Adds an alertable to this collection.
Definition Alertable.hpp:171
AlertableCollection & WithMultiAlert(std::string id, uint32_t levelFlags, F &&infoGetter, std::string const &text="", wpi::units::second_t debounce=-1_s) &
Adds a PhoenixMultiAlert to this collection.
Definition Alertable.hpp:253
void Report() const
Reports all alerts in this collection.
Definition Alertable.hpp:130
AlertableCollection & WithAlertable(PhoenixAlertable &alertable) &
Adds a PhoenixAlertable to this collection.
Definition Alertable.hpp:146
Persistent alert with debouncing.
Definition Alerts.hpp:24
Level
Levels of urgency of the alert.
Definition Alerts.hpp:32
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(char const *text=nullptr)
Sets the alert state to active and optionally changes the text.
Interface for all types that can report a Phoenix alert.
Definition Alertable.hpp:21
virtual void RegisterAlerts(AlertableCollection &collection)=0
Registers all alerts for this type to the provided collection.
PhoenixAlert::Level AlertLevel
Levels of urgency of a registered alert.
Definition Alertable.hpp:26
Persistent multi-level alert with debouncing.
Definition Alerts.hpp:120
PhoenixAlert::Level Level
Definition Alerts.hpp:125
PhoenixMultiAlert & WithDebounce(wpi::units::second_t debounce)
Sets the time debounce of this alert, default 1 second.
void SetActive(Level level, char const *text=nullptr)
Sets the alert state to active at the given level and optionally changes the text.
void SetInactive()
Sets the alert state to inactive.
Definition ExternalFeedbackConfigs.hpp:16
Definition motor_constants.h:14
Information about an alert.
Definition Alertable.hpp:43
bool isActive
Whether the alert is active.
Definition Alertable.hpp:45
std::optional< std::string > text
The new text to report in the alert, or nullopt to leave the text unchanged.
Definition Alertable.hpp:47
static AlertInfo Inactive()
Creates new information for an inactive alert.
Definition Alertable.hpp:54
static AlertInfo Active(S &&text=std::nullopt)
Creates new information for an active alert.
Definition Alertable.hpp:64
Information about a multi-level alert.
Definition Alertable.hpp:73
PhoenixMultiAlert::Level level
The new alert urgency level.
Definition Alertable.hpp:77
static MultiAlertInfo Active(PhoenixMultiAlert::Level level, S &&text=std::nullopt)
Creates new information for an active multi-level alert.
Definition Alertable.hpp:97
static MultiAlertInfo Inactive()
Creates new information for an inactive multi-level alert.
Definition Alertable.hpp:86
std::optional< std::string > text
The new text to report in the alert, or nullopt to leave the text unchanged.
Definition Alertable.hpp:79
bool isActive
Whether the multi-level alert is active.
Definition Alertable.hpp:75