diff --git a/wpilibc/src/main/native/cpp/smartdashboard/SendableChooserBase.cpp b/wpilibc/src/main/native/cpp/smartdashboard/SendableChooserBase.cpp index 9fa5b69428..f19d9e4612 100644 --- a/wpilibc/src/main/native/cpp/smartdashboard/SendableChooserBase.cpp +++ b/wpilibc/src/main/native/cpp/smartdashboard/SendableChooserBase.cpp @@ -19,8 +19,6 @@ SendableChooserBase::SendableChooserBase(SendableChooserBase&& oth) m_defaultChoice(std::move(oth.m_defaultChoice)), m_selected(std::move(oth.m_selected)), m_haveSelected(std::move(oth.m_haveSelected)), - m_instancePubs(std::move(oth.m_instancePubs)), - m_activePubs(std::move(oth.m_activePubs)), m_instance(std::move(oth.m_instance)) {} SendableChooserBase& SendableChooserBase::operator=(SendableChooserBase&& oth) { @@ -29,8 +27,6 @@ SendableChooserBase& SendableChooserBase::operator=(SendableChooserBase&& oth) { m_defaultChoice = std::move(oth.m_defaultChoice); m_selected = std::move(oth.m_selected); m_haveSelected = std::move(oth.m_haveSelected); - m_instancePubs = std::move(oth.m_instancePubs); - m_activePubs = std::move(oth.m_activePubs); m_instance = std::move(oth.m_instance); return *this; } diff --git a/wpilibc/src/main/native/include/frc/smartdashboard/SendableChooser.h b/wpilibc/src/main/native/include/frc/smartdashboard/SendableChooser.h index 42e9806a1a..f06c2524db 100644 --- a/wpilibc/src/main/native/include/frc/smartdashboard/SendableChooser.h +++ b/wpilibc/src/main/native/include/frc/smartdashboard/SendableChooser.h @@ -91,7 +91,7 @@ class SendableChooser : public SendableChooserBase { */ void OnChange(std::function); - void InitSendable(nt::NTSendableBuilder& builder) override; + void InitSendable(wpi::SendableBuilder& builder) override; }; } // namespace frc diff --git a/wpilibc/src/main/native/include/frc/smartdashboard/SendableChooser.inc b/wpilibc/src/main/native/include/frc/smartdashboard/SendableChooser.inc index 18f983be6a..e40befdb74 100644 --- a/wpilibc/src/main/native/include/frc/smartdashboard/SendableChooser.inc +++ b/wpilibc/src/main/native/include/frc/smartdashboard/SendableChooser.inc @@ -12,7 +12,7 @@ #include #include -#include +#include #include "frc/smartdashboard/SendableChooser.h" @@ -58,16 +58,9 @@ void SendableChooser::OnChange(std::function listener) { template requires std::copy_constructible && std::default_initializable -void SendableChooser::InitSendable(nt::NTSendableBuilder& builder) { +void SendableChooser::InitSendable(wpi::SendableBuilder& builder) { builder.SetSmartDashboardType("String Chooser"); - { - std::scoped_lock lock(m_mutex); - m_instancePubs.emplace_back( - nt::IntegerTopic{builder.GetTopic(kInstance)}.Publish()); - m_instancePubs.back().Set(m_instance); - m_activePubs.emplace_back( - nt::StringTopic{builder.GetTopic(kActive)}.Publish()); - } + builder.PublishConstInteger(kInstance, m_instance); builder.AddStringArrayProperty( kOptions, [=, this] { @@ -109,9 +102,6 @@ void SendableChooser::InitSendable(nt::NTSendableBuilder& builder) { std::scoped_lock lock(m_mutex); m_haveSelected = true; m_selected = val; - for (auto& pub : m_activePubs) { - pub.Set(val); - } if (m_previousVal != val && m_listener) { choice = m_choices[val]; listener = m_listener; diff --git a/wpilibc/src/main/native/include/frc/smartdashboard/SendableChooserBase.h b/wpilibc/src/main/native/include/frc/smartdashboard/SendableChooserBase.h index 46cbf0444b..f0b4fedcbb 100644 --- a/wpilibc/src/main/native/include/frc/smartdashboard/SendableChooserBase.h +++ b/wpilibc/src/main/native/include/frc/smartdashboard/SendableChooserBase.h @@ -7,11 +7,8 @@ #include #include -#include -#include -#include -#include #include +#include #include namespace frc { @@ -22,7 +19,7 @@ namespace frc { * It contains static, non-templated variables to avoid their duplication in the * template class. */ -class SendableChooserBase : public nt::NTSendable, +class SendableChooserBase : public wpi::Sendable, public wpi::SendableHelper { public: SendableChooserBase(); @@ -41,8 +38,6 @@ class SendableChooserBase : public nt::NTSendable, std::string m_defaultChoice; std::string m_selected; bool m_haveSelected = false; - wpi::SmallVector m_instancePubs; - wpi::SmallVector m_activePubs; wpi::mutex m_mutex; int m_instance; std::string m_previousVal; diff --git a/wpilibc/src/test/native/cpp/smartdashboard/SendableChooserTest.cpp b/wpilibc/src/test/native/cpp/smartdashboard/SendableChooserTest.cpp index 5728a072ab..b25934deef 100644 --- a/wpilibc/src/test/native/cpp/smartdashboard/SendableChooserTest.cpp +++ b/wpilibc/src/test/native/cpp/smartdashboard/SendableChooserTest.cpp @@ -9,6 +9,7 @@ #include #include +#include class SendableChooserTest : public ::testing::TestWithParam {}; diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/smartdashboard/SendableChooser.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/smartdashboard/SendableChooser.java index bfca78100e..7f3b93c1f4 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/smartdashboard/SendableChooser.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/smartdashboard/SendableChooser.java @@ -6,16 +6,10 @@ package edu.wpi.first.wpilibj.smartdashboard; import static edu.wpi.first.util.ErrorMessages.requireNonNullParam; -import edu.wpi.first.networktables.IntegerPublisher; -import edu.wpi.first.networktables.IntegerTopic; -import edu.wpi.first.networktables.NTSendable; -import edu.wpi.first.networktables.NTSendableBuilder; -import edu.wpi.first.networktables.StringPublisher; -import edu.wpi.first.networktables.StringTopic; +import edu.wpi.first.util.sendable.Sendable; +import edu.wpi.first.util.sendable.SendableBuilder; import edu.wpi.first.util.sendable.SendableRegistry; -import java.util.ArrayList; import java.util.LinkedHashMap; -import java.util.List; import java.util.Map; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.locks.ReentrantLock; @@ -33,7 +27,7 @@ import java.util.function.Consumer; * * @param The type of the values to be stored */ -public class SendableChooser implements NTSendable, AutoCloseable { +public class SendableChooser implements Sendable, AutoCloseable { /** The key for the default value. */ private static final String DEFAULT = "default"; @@ -67,14 +61,6 @@ public class SendableChooser implements NTSendable, AutoCloseable { @Override public void close() { SendableRegistry.remove(this); - m_mutex.lock(); - try { - for (StringPublisher pub : m_activePubs) { - pub.close(); - } - } finally { - m_mutex.unlock(); - } } /** @@ -136,15 +122,12 @@ public class SendableChooser implements NTSendable, AutoCloseable { } private String m_selected; - private final List m_activePubs = new ArrayList<>(); private final ReentrantLock m_mutex = new ReentrantLock(); @Override - public void initSendable(NTSendableBuilder builder) { + public void initSendable(SendableBuilder builder) { builder.setSmartDashboardType("String Chooser"); - IntegerPublisher instancePub = new IntegerTopic(builder.getTopic(INSTANCE)).publish(); - instancePub.set(m_instance); - builder.addCloseable(instancePub); + builder.publishConstInteger(INSTANCE, m_instance); builder.addStringProperty(DEFAULT, () -> m_defaultChoice, null); builder.addStringArrayProperty(OPTIONS, () -> m_map.keySet().toArray(new String[0]), null); builder.addStringProperty( @@ -162,12 +145,6 @@ public class SendableChooser implements NTSendable, AutoCloseable { } }, null); - m_mutex.lock(); - try { - m_activePubs.add(new StringTopic(builder.getTopic(ACTIVE)).publish()); - } finally { - m_mutex.unlock(); - } builder.addStringProperty( SELECTED, null, @@ -185,9 +162,6 @@ public class SendableChooser implements NTSendable, AutoCloseable { listener = null; } m_previousVal = val; - for (StringPublisher pub : m_activePubs) { - pub.set(val); - } } finally { m_mutex.unlock(); }