Skip to content

Commit

Permalink
[glass] NTStringChooser: Properly set retained
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterJohnson committed Jan 3, 2024
1 parent 783acb9 commit 64d536b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
13 changes: 7 additions & 6 deletions glass/src/libnt/native/cpp/NTStringChooser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "glass/networktables/NTStringChooser.h"

#include <fmt/format.h>
#include <wpi/json.h>

using namespace glass;

Expand All @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 64d536b

Please sign in to comment.