mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-30 02:31:44 +00:00
[wpilib] Shuffleboard: Keep duplicates on SelectTab() (#5198)
This commit is contained in:
@@ -20,12 +20,16 @@ struct ShuffleboardInstance::Impl {
|
||||
bool tabsChanged = false;
|
||||
std::shared_ptr<nt::NetworkTable> rootTable;
|
||||
std::shared_ptr<nt::NetworkTable> rootMetaTable;
|
||||
nt::StringPublisher selectedTabPub;
|
||||
};
|
||||
|
||||
ShuffleboardInstance::ShuffleboardInstance(nt::NetworkTableInstance ntInstance)
|
||||
: m_impl(new Impl) {
|
||||
m_impl->rootTable = ntInstance.GetTable(Shuffleboard::kBaseTableName);
|
||||
m_impl->rootMetaTable = m_impl->rootTable->GetSubTable(".metadata");
|
||||
m_impl->selectedTabPub =
|
||||
m_impl->rootMetaTable->GetStringTopic("Selected")
|
||||
.Publish(nt::PubSubOptions{.keepDuplicates = true});
|
||||
HAL_Report(HALUsageReporting::kResourceType_Shuffleboard, 0);
|
||||
}
|
||||
|
||||
@@ -75,9 +79,9 @@ void ShuffleboardInstance::DisableActuatorWidgets() {
|
||||
}
|
||||
|
||||
void ShuffleboardInstance::SelectTab(int index) {
|
||||
m_impl->rootMetaTable->GetEntry("Selected").SetDouble(index);
|
||||
m_impl->selectedTabPub.Set(std::to_string(index));
|
||||
}
|
||||
|
||||
void ShuffleboardInstance::SelectTab(std::string_view title) {
|
||||
m_impl->rootMetaTable->GetEntry("Selected").SetString(title);
|
||||
m_impl->selectedTabPub.Set(title);
|
||||
}
|
||||
|
||||
@@ -7,6 +7,8 @@
|
||||
#include <string_view>
|
||||
|
||||
#include <networktables/NetworkTableInstance.h>
|
||||
#include <networktables/NetworkTableListener.h>
|
||||
#include <networktables/StringTopic.h>
|
||||
|
||||
#include "frc/shuffleboard/ShuffleboardInstance.h"
|
||||
#include "gtest/gtest.h"
|
||||
@@ -106,3 +108,22 @@ TEST(ShuffleboardInstanceTest, NestedActuatorWidgetsAreDisabled) {
|
||||
EXPECT_FALSE(controllable)
|
||||
<< "The nested actuator widget should have been disabled";
|
||||
}
|
||||
|
||||
TEST(ShuffleboardInstanceTest, DuplicateSelectTabs) {
|
||||
NTWrapper ntInst;
|
||||
frc::detail::ShuffleboardInstance shuffleboardInst{ntInst.inst};
|
||||
std::atomic_int counter = 0;
|
||||
auto listener = nt::NetworkTableListener::CreateListener(
|
||||
ntInst.inst.GetStringTopic("/Shuffleboard/.metadata/Selected"),
|
||||
nt::EventFlags::kValueAll | nt::EventFlags::kImmediate,
|
||||
[&counter](auto& event) { counter++; });
|
||||
|
||||
// There shouldn't be anything there
|
||||
EXPECT_EQ(0, counter);
|
||||
|
||||
shuffleboardInst.SelectTab("tab1");
|
||||
shuffleboardInst.SelectTab("tab1");
|
||||
EXPECT_TRUE(ntInst.inst.WaitForListenerQueue(0.005))
|
||||
<< "Listener queue timed out!";
|
||||
EXPECT_EQ(2, counter);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user