diff --git a/wpilibc/src/main/native/cpp/Alert.cpp b/wpilibc/src/main/native/cpp/Alert.cpp index 0394f8a14ac..68587de00be 100644 --- a/wpilibc/src/main/native/cpp/Alert.cpp +++ b/wpilibc/src/main/native/cpp/Alert.cpp @@ -21,6 +21,7 @@ using namespace frc; +// TODO: throw if matching (group, text, type) already constructed Alert::Alert(std::string_view text, AlertType type) : Alert("Alerts", text, type) {} @@ -66,6 +67,10 @@ void Alert::Set(bool active) { m_active = active; } +bool Alert::Get() const { + return m_active; +} + void Alert::SetText(std::string_view text) { if (text == m_text) { return; @@ -82,6 +87,10 @@ void Alert::SetText(std::string_view text) { } } +std::string Alert::GetText() const { + return m_text; +} + Alert::SendableAlerts::SendableAlerts() { m_alerts.fill({}); } diff --git a/wpilibc/src/main/native/include/frc/Alert.h b/wpilibc/src/main/native/include/frc/Alert.h index a38901befc8..9e9d1146691 100644 --- a/wpilibc/src/main/native/include/frc/Alert.h +++ b/wpilibc/src/main/native/include/frc/Alert.h @@ -104,6 +104,12 @@ class Alert { */ void Set(bool active); + /** + * Gets whether the alert is active. + * @return whether the alert is active. + */ + bool Get() const; + /** * Updates current alert text. Use this method to dynamically change the * displayed alert, such as including more details about the detected problem. @@ -112,6 +118,12 @@ class Alert { */ void SetText(std::string_view text); + /** + * Gets the current alert text. + * @return the current text. + */ + std::string GetText() const; + private: class PublishedAlert { public: diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/Alert.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/Alert.java index 4e95dfd16c1..6eee4b86c25 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/Alert.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/Alert.java @@ -123,6 +123,15 @@ public void set(boolean active) { m_active = active; } + /** + * Gets whether the alert is active. + * + * @return whether the alert is active. + */ + public boolean get() { + return m_active; + } + /** * Updates current alert text. Use this method to dynamically change the displayed alert, such as * including more details about the detected problem. @@ -143,6 +152,15 @@ public void setText(String text) { } } + /** + * Gets the current alert text. + * + * @return the current text. + */ + public String getText() { + return m_text; + } + private record PublishedAlert(long timestamp, String text) implements Comparable { private static final Comparator comparator = Comparator.comparingLong((PublishedAlert alert) -> alert.timestamp())