From 64d536bf7f847e99be5928fad8c79e8447af59f8 Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Tue, 2 Jan 2024 23:20:35 -0800 Subject: [PATCH] [glass] NTStringChooser: Properly set retained --- glass/src/libnt/native/cpp/NTStringChooser.cpp | 13 +++++++------ .../include/glass/networktables/NTStringChooser.h | 3 ++- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/glass/src/libnt/native/cpp/NTStringChooser.cpp b/glass/src/libnt/native/cpp/NTStringChooser.cpp index b892a2c789e..26074fc4814 100644 --- a/glass/src/libnt/native/cpp/NTStringChooser.cpp +++ b/glass/src/libnt/native/cpp/NTStringChooser.cpp @@ -5,6 +5,7 @@ #include "glass/networktables/NTStringChooser.h" #include +#include using namespace glass; @@ -16,17 +17,17 @@ NTStringChooserModel::NTStringChooserModel(nt::NetworkTableInstance inst, : m_inst{inst}, m_default{ m_inst.GetStringTopic(fmt::format("{}/default", path)).Subscribe("")}, - m_selected{ - m_inst.GetStringTopic(fmt::format("{}/selected", path)).GetEntry("")}, + m_selected{m_inst.GetStringTopic(fmt::format("{}/selected", path)) + .Subscribe("")}, + m_selectedPub{m_inst.GetStringTopic(fmt::format("{}/selected", path)) + .PublishEx("string", {{"retained", true}})}, m_active{ m_inst.GetStringTopic(fmt::format("{}/active", path)).Subscribe("")}, m_options{m_inst.GetStringArrayTopic(fmt::format("{}/options", path)) - .Subscribe({})} { - m_selected.GetTopic().SetRetained(true); -} + .Subscribe({})} {} void NTStringChooserModel::SetSelected(std::string_view val) { - m_selected.Set(val); + m_selectedPub.Set(val); } void NTStringChooserModel::Update() { diff --git a/glass/src/libnt/native/include/glass/networktables/NTStringChooser.h b/glass/src/libnt/native/include/glass/networktables/NTStringChooser.h index d770a749e3f..49c4802ede3 100644 --- a/glass/src/libnt/native/include/glass/networktables/NTStringChooser.h +++ b/glass/src/libnt/native/include/glass/networktables/NTStringChooser.h @@ -39,7 +39,8 @@ class NTStringChooserModel : public StringChooserModel { private: nt::NetworkTableInstance m_inst; nt::StringSubscriber m_default; - nt::StringEntry m_selected; + nt::StringSubscriber m_selected; + nt::StringPublisher m_selectedPub; nt::StringSubscriber m_active; nt::StringArraySubscriber m_options;