[wpilib] Add metadata to all dashboard ".type" entries (#6799)

This commit is contained in:
Ryan Blue
2024-07-02 16:31:50 -04:00
committed by GitHub
parent 7366a03fc9
commit 6a5448322b
12 changed files with 95 additions and 23 deletions

View File

@@ -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();

View File

@@ -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.

View File

@@ -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;
}

View File

@@ -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()));
}

View File

@@ -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()));
}

View File

@@ -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();