mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
[wpilib] Add metadata to all dashboard ".type" entries (#6799)
This commit is contained in:
@@ -28,6 +28,7 @@
|
||||
#include <wpi/DataLog.h>
|
||||
#include <wpi/EventVector.h>
|
||||
#include <wpi/condition_variable.h>
|
||||
#include <wpi/json.h>
|
||||
#include <wpi/mutex.h>
|
||||
#include <wpi/timestamp.h>
|
||||
|
||||
@@ -45,8 +46,11 @@ class MatchDataSenderEntry {
|
||||
public:
|
||||
MatchDataSenderEntry(const std::shared_ptr<nt::NetworkTable>& table,
|
||||
std::string_view key,
|
||||
typename Topic::ParamType initialVal)
|
||||
: publisher{Topic{table->GetTopic(key)}.Publish()}, prevVal{initialVal} {
|
||||
typename Topic::ParamType initialVal,
|
||||
wpi::json topicProperties = {{}})
|
||||
: publisher{Topic{table->GetTopic(key)}.PublishEx(Topic::kTypeString,
|
||||
topicProperties)},
|
||||
prevVal{initialVal} {
|
||||
publisher.Set(initialVal);
|
||||
}
|
||||
|
||||
@@ -62,10 +66,16 @@ class MatchDataSenderEntry {
|
||||
typename Topic::ValueType prevVal;
|
||||
};
|
||||
|
||||
static constexpr std::string_view kSmartDashboardType = "FMSInfo";
|
||||
|
||||
struct MatchDataSender {
|
||||
std::shared_ptr<nt::NetworkTable> table =
|
||||
nt::NetworkTableInstance::GetDefault().GetTable("FMSInfo");
|
||||
MatchDataSenderEntry<nt::StringTopic> typeMetaData{table, ".type", "FMSInfo"};
|
||||
MatchDataSenderEntry<nt::StringTopic> typeMetaData{
|
||||
table,
|
||||
".type",
|
||||
kSmartDashboardType,
|
||||
{{"SmartDashboard", kSmartDashboardType}}};
|
||||
MatchDataSenderEntry<nt::StringTopic> gameSpecificMessage{
|
||||
table, "GameSpecificMessage", ""};
|
||||
MatchDataSenderEntry<nt::StringTopic> eventName{table, "EventName", ""};
|
||||
|
||||
@@ -13,19 +13,21 @@
|
||||
#include <networktables/NetworkTableInstance.h>
|
||||
#include <networktables/NetworkTableListener.h>
|
||||
#include <networktables/StringTopic.h>
|
||||
#include <wpi/json.h>
|
||||
|
||||
using namespace frc;
|
||||
|
||||
// The Preferences table name
|
||||
static constexpr std::string_view kTableName{"Preferences"};
|
||||
|
||||
static constexpr std::string_view kSmartDashboardType = "RobotPreferences";
|
||||
namespace {
|
||||
struct Instance {
|
||||
Instance();
|
||||
|
||||
std::shared_ptr<nt::NetworkTable> table{
|
||||
nt::NetworkTableInstance::GetDefault().GetTable(kTableName)};
|
||||
nt::StringPublisher typePublisher{table->GetStringTopic(".type").Publish()};
|
||||
nt::StringPublisher typePublisher{table->GetStringTopic(".type").PublishEx(
|
||||
nt::StringTopic::kTypeString, {{"SmartDashboard", kSmartDashboardType}})};
|
||||
nt::MultiSubscriber tableSubscriber{nt::NetworkTableInstance::GetDefault(),
|
||||
{{fmt::format("{}/", table->GetPath())}}};
|
||||
nt::NetworkTableListener listener;
|
||||
@@ -165,7 +167,7 @@ void Preferences::RemoveAll() {
|
||||
}
|
||||
|
||||
Instance::Instance() {
|
||||
typePublisher.Set("RobotPreferences");
|
||||
typePublisher.Set(kSmartDashboardType);
|
||||
listener = nt::NetworkTableListener::CreateListener(
|
||||
tableSubscriber, NT_EVENT_PUBLISH | NT_EVENT_IMMEDIATE,
|
||||
[typeTopic = typePublisher.GetTopic().GetHandle()](auto& event) {
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include <networktables/NetworkTable.h>
|
||||
#include <networktables/NetworkTableInstance.h>
|
||||
#include <networktables/StringTopic.h>
|
||||
#include <wpi/json.h>
|
||||
#include <wpi/mutex.h>
|
||||
#include <wpi/sendable/Sendable.h>
|
||||
#include <wpi/sendable/SendableRegistry.h>
|
||||
@@ -16,6 +17,8 @@
|
||||
|
||||
using namespace frc;
|
||||
|
||||
static constexpr std::string_view kSmartDashboardType = "LW Subsystem";
|
||||
|
||||
namespace {
|
||||
struct Component {
|
||||
bool firstTime = true;
|
||||
@@ -207,8 +210,10 @@ void LiveWindow::UpdateValuesUnsafe() {
|
||||
comp.namePub.Set(cbdata.name);
|
||||
static_cast<SendableBuilderImpl&>(cbdata.builder).SetTable(table);
|
||||
cbdata.sendable->InitSendable(cbdata.builder);
|
||||
comp.typePub = nt::StringTopic{ssTable->GetTopic(".type")}.Publish();
|
||||
comp.typePub.Set("LW Subsystem");
|
||||
comp.typePub = nt::StringTopic{ssTable->GetTopic(".type")}.PublishEx(
|
||||
nt::StringTopic::kTypeString,
|
||||
{{"SmartDashboard", kSmartDashboardType}});
|
||||
comp.typePub.Set(kSmartDashboardType);
|
||||
|
||||
comp.firstTime = false;
|
||||
}
|
||||
|
||||
@@ -4,8 +4,12 @@
|
||||
|
||||
#include "frc/shuffleboard/ShuffleboardLayout.h"
|
||||
|
||||
#include <wpi/json.h>
|
||||
|
||||
using namespace frc;
|
||||
|
||||
static constexpr std::string_view kSmartDashboardType = "ShuffleboardLayout";
|
||||
|
||||
ShuffleboardLayout::ShuffleboardLayout(ShuffleboardContainer& parent,
|
||||
std::string_view title,
|
||||
std::string_view type)
|
||||
@@ -20,7 +24,9 @@ void ShuffleboardLayout::BuildInto(
|
||||
std::shared_ptr<nt::NetworkTable> metaTable) {
|
||||
BuildMetadata(metaTable);
|
||||
auto table = parentTable->GetSubTable(GetTitle());
|
||||
table->GetEntry(".type").SetString("ShuffleboardLayout");
|
||||
table->GetEntry(".type").SetString(kSmartDashboardType);
|
||||
table->GetEntry(".type").GetTopic().SetProperty("SmartDashboard",
|
||||
kSmartDashboardType);
|
||||
for (auto& component : GetComponents()) {
|
||||
component->BuildInto(table, metaTable->GetSubTable(component->GetTitle()));
|
||||
}
|
||||
|
||||
@@ -4,8 +4,12 @@
|
||||
|
||||
#include "frc/shuffleboard/ShuffleboardTab.h"
|
||||
|
||||
#include <wpi/json.h>
|
||||
|
||||
using namespace frc;
|
||||
|
||||
static constexpr std::string_view kSmartDashboardType = "ShuffleboardLayout";
|
||||
|
||||
ShuffleboardTab::ShuffleboardTab(ShuffleboardRoot& root, std::string_view title)
|
||||
: ShuffleboardValue(title), ShuffleboardContainer(title), m_root(root) {}
|
||||
|
||||
@@ -16,7 +20,9 @@ ShuffleboardRoot& ShuffleboardTab::GetRoot() {
|
||||
void ShuffleboardTab::BuildInto(std::shared_ptr<nt::NetworkTable> parentTable,
|
||||
std::shared_ptr<nt::NetworkTable> metaTable) {
|
||||
auto tabTable = parentTable->GetSubTable(GetTitle());
|
||||
tabTable->GetEntry(".type").SetString("ShuffleboardTab");
|
||||
tabTable->GetEntry(".type").SetString(kSmartDashboardType);
|
||||
tabTable->GetEntry(".type").GetTopic().SetProperty("SmartDashboard",
|
||||
kSmartDashboardType);
|
||||
for (auto& component : GetComponents()) {
|
||||
component->BuildInto(tabTable,
|
||||
metaTable->GetSubTable(component->GetTitle()));
|
||||
|
||||
@@ -5,9 +5,12 @@
|
||||
#include "frc/smartdashboard/MechanismLigament2d.h"
|
||||
|
||||
#include <wpi/StringExtras.h>
|
||||
#include <wpi/json.h>
|
||||
|
||||
using namespace frc;
|
||||
|
||||
static constexpr std::string_view kSmartDashboardType = "line";
|
||||
|
||||
MechanismLigament2d::MechanismLigament2d(std::string_view name, double length,
|
||||
units::degree_t angle,
|
||||
double lineWeight,
|
||||
@@ -21,8 +24,9 @@ MechanismLigament2d::MechanismLigament2d(std::string_view name, double length,
|
||||
|
||||
void MechanismLigament2d::UpdateEntries(
|
||||
std::shared_ptr<nt::NetworkTable> table) {
|
||||
m_typePub = table->GetStringTopic(".type").Publish();
|
||||
m_typePub.Set("line");
|
||||
m_typePub = table->GetStringTopic(".type").PublishEx(
|
||||
nt::StringTopic::kTypeString, {{"SmartDashboard", kSmartDashboardType}});
|
||||
m_typePub.Set(kSmartDashboardType);
|
||||
|
||||
m_colorEntry = table->GetStringTopic("color").GetEntry("");
|
||||
m_colorEntry.Set(m_color);
|
||||
|
||||
@@ -13,6 +13,7 @@ import edu.wpi.first.networktables.BooleanPublisher;
|
||||
import edu.wpi.first.networktables.IntegerPublisher;
|
||||
import edu.wpi.first.networktables.NetworkTableInstance;
|
||||
import edu.wpi.first.networktables.StringPublisher;
|
||||
import edu.wpi.first.networktables.StringTopic;
|
||||
import edu.wpi.first.util.EventVector;
|
||||
import edu.wpi.first.util.WPIUtilJNI;
|
||||
import edu.wpi.first.util.datalog.BooleanArrayLogEntry;
|
||||
@@ -93,6 +94,8 @@ public final class DriverStation {
|
||||
|
||||
@SuppressWarnings("MemberName")
|
||||
private static class MatchDataSender {
|
||||
private static final String kSmartDashboardType = "FMSInfo";
|
||||
|
||||
final StringPublisher gameSpecificMessage;
|
||||
final StringPublisher eventName;
|
||||
final IntegerPublisher matchNumber;
|
||||
@@ -112,7 +115,11 @@ public final class DriverStation {
|
||||
|
||||
MatchDataSender() {
|
||||
var table = NetworkTableInstance.getDefault().getTable("FMSInfo");
|
||||
table.getStringTopic(".type").publish().set("FMSInfo");
|
||||
table
|
||||
.getStringTopic(".type")
|
||||
.publishEx(
|
||||
StringTopic.kTypeString, "{\"SmartDashboard\":\"" + kSmartDashboardType + "\"}")
|
||||
.set(kSmartDashboardType);
|
||||
gameSpecificMessage = table.getStringTopic("GameSpecificMessage").publish();
|
||||
gameSpecificMessage.set("");
|
||||
eventName = table.getStringTopic("EventName").publish();
|
||||
|
||||
@@ -15,6 +15,7 @@ import edu.wpi.first.networktables.NetworkTableEvent;
|
||||
import edu.wpi.first.networktables.NetworkTableInstance;
|
||||
import edu.wpi.first.networktables.NetworkTableListener;
|
||||
import edu.wpi.first.networktables.StringPublisher;
|
||||
import edu.wpi.first.networktables.StringTopic;
|
||||
import edu.wpi.first.networktables.Topic;
|
||||
import java.util.Collection;
|
||||
import java.util.EnumSet;
|
||||
@@ -34,7 +35,9 @@ import java.util.EnumSet;
|
||||
*/
|
||||
public final class Preferences {
|
||||
/** The Preferences table name. */
|
||||
private static final String TABLE_NAME = "Preferences";
|
||||
private static final String kTableName = "Preferences";
|
||||
|
||||
private static final String kSmartDashboardType = "RobotPreferences";
|
||||
|
||||
/** The network table. */
|
||||
private static NetworkTable m_table;
|
||||
@@ -57,12 +60,16 @@ public final class Preferences {
|
||||
* @param inst NetworkTable instance
|
||||
*/
|
||||
public static synchronized void setNetworkTableInstance(NetworkTableInstance inst) {
|
||||
m_table = inst.getTable(TABLE_NAME);
|
||||
m_table = inst.getTable(kTableName);
|
||||
if (m_typePublisher != null) {
|
||||
m_typePublisher.close();
|
||||
}
|
||||
m_typePublisher = m_table.getStringTopic(".type").publish();
|
||||
m_typePublisher.set("RobotPreferences");
|
||||
m_typePublisher =
|
||||
m_table
|
||||
.getStringTopic(".type")
|
||||
.publishEx(
|
||||
StringTopic.kTypeString, "{\"SmartDashboard\":\"" + kSmartDashboardType + "\"}");
|
||||
m_typePublisher.set(kSmartDashboardType);
|
||||
|
||||
// Subscribe to all Preferences; this ensures we get the latest values
|
||||
// ahead of a getter call.
|
||||
|
||||
@@ -36,6 +36,8 @@ public final class LiveWindow {
|
||||
StringPublisher m_typePub;
|
||||
}
|
||||
|
||||
private static final String kSmartDashboardType = "LW Subsystem";
|
||||
|
||||
private static final int dataHandle = SendableRegistry.getDataHandle();
|
||||
private static final NetworkTable liveWindowTable =
|
||||
NetworkTableInstance.getDefault().getTable("LiveWindow");
|
||||
@@ -224,8 +226,12 @@ public final class LiveWindow {
|
||||
component.m_namePub.set(cbdata.name);
|
||||
((SendableBuilderImpl) cbdata.builder).setTable(table);
|
||||
cbdata.sendable.initSendable(cbdata.builder);
|
||||
component.m_typePub = new StringTopic(ssTable.getTopic(".type")).publish();
|
||||
component.m_typePub.set("LW Subsystem");
|
||||
component.m_typePub =
|
||||
new StringTopic(ssTable.getTopic(".type"))
|
||||
.publishEx(
|
||||
StringTopic.kTypeString,
|
||||
"{\"SmartDashboard\":\"" + kSmartDashboardType + "\"}");
|
||||
component.m_typePub.set(kSmartDashboardType);
|
||||
|
||||
component.m_firstTime = false;
|
||||
}
|
||||
|
||||
@@ -18,6 +18,8 @@ import java.util.function.Supplier;
|
||||
/** A layout in a Shuffleboard tab. Layouts can contain widgets and other layouts. */
|
||||
public final class ShuffleboardLayout extends ShuffleboardComponent<ShuffleboardLayout>
|
||||
implements ShuffleboardContainer {
|
||||
private static final String kSmartDashboardType = "ShuffleboardLayout";
|
||||
|
||||
private final ContainerHelper m_helper = new ContainerHelper(this);
|
||||
|
||||
ShuffleboardLayout(ShuffleboardContainer parent, String title, String type) {
|
||||
@@ -127,7 +129,11 @@ public final class ShuffleboardLayout extends ShuffleboardComponent<Shuffleboard
|
||||
public void buildInto(NetworkTable parentTable, NetworkTable metaTable) {
|
||||
buildMetadata(metaTable);
|
||||
NetworkTable table = parentTable.getSubTable(getTitle());
|
||||
table.getEntry(".type").setString("ShuffleboardLayout");
|
||||
table.getEntry(".type").setString(kSmartDashboardType);
|
||||
table
|
||||
.getEntry(".type")
|
||||
.getTopic()
|
||||
.setProperty("SmartDashboard", "\"" + kSmartDashboardType + "\"");
|
||||
for (ShuffleboardComponent<?> component : getComponents()) {
|
||||
component.buildInto(table, metaTable.getSubTable(component.getTitle()));
|
||||
}
|
||||
|
||||
@@ -20,6 +20,8 @@ import java.util.function.Supplier;
|
||||
* arbitrarily deep (note that too many levels may make deeper components unusable).
|
||||
*/
|
||||
public final class ShuffleboardTab implements ShuffleboardContainer {
|
||||
private static final String kSmartDashboardType = "ShuffleboardTab";
|
||||
|
||||
private final ContainerHelper m_helper = new ContainerHelper(this);
|
||||
private final ShuffleboardRoot m_root;
|
||||
private final String m_title;
|
||||
@@ -140,7 +142,11 @@ public final class ShuffleboardTab implements ShuffleboardContainer {
|
||||
@Override
|
||||
public void buildInto(NetworkTable parentTable, NetworkTable metaTable) {
|
||||
NetworkTable tabTable = parentTable.getSubTable(m_title);
|
||||
tabTable.getEntry(".type").setString("ShuffleboardTab");
|
||||
tabTable.getEntry(".type").setString(kSmartDashboardType);
|
||||
tabTable
|
||||
.getEntry(".type")
|
||||
.getTopic()
|
||||
.setProperty("SmartDashboard", "\"" + kSmartDashboardType + "\"");
|
||||
for (ShuffleboardComponent<?> component : m_helper.getComponents()) {
|
||||
component.buildInto(tabTable, metaTable.getSubTable(component.getTitle()));
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import edu.wpi.first.networktables.DoubleEntry;
|
||||
import edu.wpi.first.networktables.NetworkTable;
|
||||
import edu.wpi.first.networktables.StringEntry;
|
||||
import edu.wpi.first.networktables.StringPublisher;
|
||||
import edu.wpi.first.networktables.StringTopic;
|
||||
import edu.wpi.first.wpilibj.util.Color8Bit;
|
||||
|
||||
/**
|
||||
@@ -28,6 +29,8 @@ public class MechanismLigament2d extends MechanismObject2d {
|
||||
private double m_weight;
|
||||
private DoubleEntry m_weightEntry;
|
||||
|
||||
private static String kSmartDashboardType = "line";
|
||||
|
||||
/**
|
||||
* Create a new ligament.
|
||||
*
|
||||
@@ -201,8 +204,12 @@ public class MechanismLigament2d extends MechanismObject2d {
|
||||
if (m_typePub != null) {
|
||||
m_typePub.close();
|
||||
}
|
||||
m_typePub = table.getStringTopic(".type").publish();
|
||||
m_typePub.set("line");
|
||||
m_typePub =
|
||||
table
|
||||
.getStringTopic(".type")
|
||||
.publishEx(
|
||||
StringTopic.kTypeString, "{\"SmartDashboard\":\"" + kSmartDashboardType + "\"}");
|
||||
m_typePub.set(kSmartDashboardType);
|
||||
|
||||
if (m_angleEntry != null) {
|
||||
m_angleEntry.close();
|
||||
|
||||
Reference in New Issue
Block a user