mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-26 01:51:41 +00:00
[wpilib] SendableChooser: implement Sendable instead of NTSendable (#5718)
This commit is contained in:
@@ -91,7 +91,7 @@ class SendableChooser : public SendableChooserBase {
|
||||
*/
|
||||
void OnChange(std::function<void(T)>);
|
||||
|
||||
void InitSendable(nt::NTSendableBuilder& builder) override;
|
||||
void InitSendable(wpi::SendableBuilder& builder) override;
|
||||
};
|
||||
|
||||
} // namespace frc
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include <networktables/NTSendableBuilder.h>
|
||||
#include <wpi/sendable/SendableBuilder.h>
|
||||
|
||||
#include "frc/smartdashboard/SendableChooser.h"
|
||||
|
||||
@@ -58,16 +58,9 @@ void SendableChooser<T>::OnChange(std::function<void(T)> listener) {
|
||||
|
||||
template <class T>
|
||||
requires std::copy_constructible<T> && std::default_initializable<T>
|
||||
void SendableChooser<T>::InitSendable(nt::NTSendableBuilder& builder) {
|
||||
void SendableChooser<T>::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<T>::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;
|
||||
|
||||
@@ -7,11 +7,8 @@
|
||||
#include <atomic>
|
||||
#include <string>
|
||||
|
||||
#include <networktables/IntegerTopic.h>
|
||||
#include <networktables/NTSendable.h>
|
||||
#include <networktables/StringTopic.h>
|
||||
#include <wpi/SmallVector.h>
|
||||
#include <wpi/mutex.h>
|
||||
#include <wpi/sendable/Sendable.h>
|
||||
#include <wpi/sendable/SendableHelper.h>
|
||||
|
||||
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<SendableChooserBase> {
|
||||
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<nt::IntegerPublisher, 2> m_instancePubs;
|
||||
wpi::SmallVector<nt::StringPublisher, 2> m_activePubs;
|
||||
wpi::mutex m_mutex;
|
||||
int m_instance;
|
||||
std::string m_previousVal;
|
||||
|
||||
Reference in New Issue
Block a user