Skip to content

Commit

Permalink
Add Get and GetText
Browse files Browse the repository at this point in the history
  • Loading branch information
rzblue committed Oct 25, 2024
1 parent c40a06d commit 024fbed
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
9 changes: 9 additions & 0 deletions wpilibc/src/main/native/cpp/Alert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {}

Expand Down Expand Up @@ -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;
Expand All @@ -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({});
}
Expand Down
12 changes: 12 additions & 0 deletions wpilibc/src/main/native/include/frc/Alert.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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:
Expand Down
18 changes: 18 additions & 0 deletions wpilibj/src/main/java/edu/wpi/first/wpilibj/Alert.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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<PublishedAlert> {
private static final Comparator<PublishedAlert> comparator =
Comparator.comparingLong((PublishedAlert alert) -> alert.timestamp())
Expand Down

0 comments on commit 024fbed

Please sign in to comment.