From 397a296e255973a89f758e2d061f91b95d6bcef3 Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Sat, 28 Jul 2018 10:42:31 -0700 Subject: [PATCH] Add a .controllable key as a standard part of Sendable (#1225) This indicates whether or not the Sendable listeners are installed. It is set to true when SendableBuilder.startListeners() starts the listeners, and set to false when SendableBuilder.stopListeners() stops the listeners. This allows dashboards to choose to change their widget display based on whether or not the value is actually controllable. --- .../main/native/cpp/smartdashboard/SendableBuilderImpl.cpp | 3 +++ .../native/include/frc/smartdashboard/SendableBuilderImpl.h | 1 + .../wpi/first/wpilibj/smartdashboard/SendableBuilderImpl.java | 4 ++++ 3 files changed, 8 insertions(+) diff --git a/wpilibc/src/main/native/cpp/smartdashboard/SendableBuilderImpl.cpp b/wpilibc/src/main/native/cpp/smartdashboard/SendableBuilderImpl.cpp index 1d05be3073..fb30724fa4 100644 --- a/wpilibc/src/main/native/cpp/smartdashboard/SendableBuilderImpl.cpp +++ b/wpilibc/src/main/native/cpp/smartdashboard/SendableBuilderImpl.cpp @@ -14,6 +14,7 @@ using namespace frc; void SendableBuilderImpl::SetTable(std::shared_ptr table) { m_table = table; + m_controllableEntry = table->GetEntry(".controllable"); } std::shared_ptr SendableBuilderImpl::GetTable() { @@ -30,10 +31,12 @@ void SendableBuilderImpl::UpdateTable() { void SendableBuilderImpl::StartListeners() { for (auto& property : m_properties) property.StartListener(); + m_controllableEntry.SetBoolean(true); } void SendableBuilderImpl::StopListeners() { for (auto& property : m_properties) property.StopListener(); + m_controllableEntry.SetBoolean(false); } void SendableBuilderImpl::StartLiveWindowMode() { diff --git a/wpilibc/src/main/native/include/frc/smartdashboard/SendableBuilderImpl.h b/wpilibc/src/main/native/include/frc/smartdashboard/SendableBuilderImpl.h index ab80d4c6ce..a10098a244 100644 --- a/wpilibc/src/main/native/include/frc/smartdashboard/SendableBuilderImpl.h +++ b/wpilibc/src/main/native/include/frc/smartdashboard/SendableBuilderImpl.h @@ -187,6 +187,7 @@ class SendableBuilderImpl : public SendableBuilder { std::function m_safeState; std::function m_updateTable; std::shared_ptr m_table; + nt::NetworkTableEntry m_controllableEntry; }; } // namespace frc diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/smartdashboard/SendableBuilderImpl.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/smartdashboard/SendableBuilderImpl.java index 7f78eeb716..44445de099 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/smartdashboard/SendableBuilderImpl.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/smartdashboard/SendableBuilderImpl.java @@ -57,6 +57,7 @@ public class SendableBuilderImpl implements SendableBuilder { private Runnable m_safeState; private Runnable m_updateTable; private NetworkTable m_table; + private NetworkTableEntry m_controllableEntry; /** * Set the network table. Must be called prior to any Add* functions being @@ -65,6 +66,7 @@ public class SendableBuilderImpl implements SendableBuilder { */ public void setTable(NetworkTable table) { m_table = table; + m_controllableEntry = table.getEntry(".controllable"); } /** @@ -96,6 +98,7 @@ public class SendableBuilderImpl implements SendableBuilder { for (Property property : m_properties) { property.startListener(); } + m_controllableEntry.setBoolean(true); } /** @@ -105,6 +108,7 @@ public class SendableBuilderImpl implements SendableBuilder { for (Property property : m_properties) { property.stopListener(); } + m_controllableEntry.setBoolean(false); } /**