diff --git a/wpilibc/src/main/native/cpp/shuffleboard/Shuffleboard.cpp b/wpilibc/src/main/native/cpp/shuffleboard/Shuffleboard.cpp
index 267ef36f25..2d698471ab 100644
--- a/wpilibc/src/main/native/cpp/shuffleboard/Shuffleboard.cpp
+++ b/wpilibc/src/main/native/cpp/shuffleboard/Shuffleboard.cpp
@@ -19,6 +19,12 @@ ShuffleboardTab& Shuffleboard::GetTab(wpi::StringRef title) {
return GetInstance().GetTab(title);
}
+void Shuffleboard::SelectTab(int index) { GetInstance().SelectTab(index); }
+
+void Shuffleboard::SelectTab(wpi::StringRef title) {
+ GetInstance().SelectTab(title);
+}
+
void Shuffleboard::EnableActuatorWidgets() {
GetInstance().EnableActuatorWidgets();
}
diff --git a/wpilibc/src/main/native/cpp/shuffleboard/ShuffleboardInstance.cpp b/wpilibc/src/main/native/cpp/shuffleboard/ShuffleboardInstance.cpp
index 41dcf301be..39e57782de 100644
--- a/wpilibc/src/main/native/cpp/shuffleboard/ShuffleboardInstance.cpp
+++ b/wpilibc/src/main/native/cpp/shuffleboard/ShuffleboardInstance.cpp
@@ -72,3 +72,11 @@ void ShuffleboardInstance::DisableActuatorWidgets() {
}
}
}
+
+void ShuffleboardInstance::SelectTab(int index) {
+ m_impl->rootMetaTable->GetEntry("Selected").ForceSetDouble(index);
+}
+
+void ShuffleboardInstance::SelectTab(wpi::StringRef title) {
+ m_impl->rootMetaTable->GetEntry("Selected").ForceSetString(title);
+}
diff --git a/wpilibc/src/main/native/include/frc/shuffleboard/Shuffleboard.h b/wpilibc/src/main/native/include/frc/shuffleboard/Shuffleboard.h
index a60ed729e5..e49d1c3542 100644
--- a/wpilibc/src/main/native/include/frc/shuffleboard/Shuffleboard.h
+++ b/wpilibc/src/main/native/include/frc/shuffleboard/Shuffleboard.h
@@ -82,6 +82,22 @@ class Shuffleboard final {
*/
static ShuffleboardTab& GetTab(wpi::StringRef title);
+ /**
+ * Selects the tab in the dashboard with the given index in the range
+ * [0..n-1], where n is the number of tabs in the dashboard at the time
+ * this method is called.
+ *
+ * @param index the index of the tab to select
+ */
+ static void SelectTab(int index);
+
+ /**
+ * Selects the tab in the dashboard with the given title.
+ *
+ * @param title the title of the tab to select
+ */
+ static void SelectTab(wpi::StringRef title);
+
/**
* Enables user control of widgets containing actuators: speed controllers,
* relays, etc. This should only be used when the robot is in test mode.
diff --git a/wpilibc/src/main/native/include/frc/shuffleboard/ShuffleboardInstance.h b/wpilibc/src/main/native/include/frc/shuffleboard/ShuffleboardInstance.h
index 9b0a075ea0..b202160de8 100644
--- a/wpilibc/src/main/native/include/frc/shuffleboard/ShuffleboardInstance.h
+++ b/wpilibc/src/main/native/include/frc/shuffleboard/ShuffleboardInstance.h
@@ -28,6 +28,10 @@ class ShuffleboardInstance final : public ShuffleboardRoot {
void DisableActuatorWidgets() override;
+ void SelectTab(int index) override;
+
+ void SelectTab(wpi::StringRef) override;
+
private:
struct Impl;
std::unique_ptr m_impl;
diff --git a/wpilibc/src/main/native/include/frc/shuffleboard/ShuffleboardRoot.h b/wpilibc/src/main/native/include/frc/shuffleboard/ShuffleboardRoot.h
index a8e1c497eb..0c50545158 100644
--- a/wpilibc/src/main/native/include/frc/shuffleboard/ShuffleboardRoot.h
+++ b/wpilibc/src/main/native/include/frc/shuffleboard/ShuffleboardRoot.h
@@ -45,6 +45,22 @@ class ShuffleboardRoot {
* actuators.
*/
virtual void DisableActuatorWidgets() = 0;
+
+ /**
+ * Selects the tab in the dashboard with the given index in the range
+ * [0..n-1], where n is the number of tabs in the dashboard at the time
+ * this method is called.
+ *
+ * @param index the index of the tab to select
+ */
+ virtual void SelectTab(int index) = 0;
+
+ /**
+ * Selects the tab in the dashboard with the given title.
+ *
+ * @param title the title of the tab to select
+ */
+ virtual void SelectTab(wpi::StringRef title) = 0;
};
} // namespace frc
diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/shuffleboard/Shuffleboard.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/shuffleboard/Shuffleboard.java
index dbfd25e7fb..fbce24a7a0 100644
--- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/shuffleboard/Shuffleboard.java
+++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/shuffleboard/Shuffleboard.java
@@ -82,6 +82,25 @@ public final class Shuffleboard {
return root.getTab(title);
}
+ /**
+ * Selects the tab in the dashboard with the given index in the range [0..n-1], where n
+ * is the number of tabs in the dashboard at the time this method is called.
+ *
+ * @param index the index of the tab to select
+ */
+ public static void selectTab(int index) {
+ root.selectTab(index);
+ }
+
+ /**
+ * Selects the tab in the dashboard with the given title.
+ *
+ * @param title the title of the tab to select
+ */
+ public static void selectTab(String title) {
+ root.selectTab(title);
+ }
+
/**
* Enables user control of widgets containing actuators: speed controllers, relays, etc. This
* should only be used when the robot is in test mode. IterativeRobotBase and SampleRobot are
diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/shuffleboard/ShuffleboardInstance.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/shuffleboard/ShuffleboardInstance.java
index 81d1c68dcf..7018da003d 100644
--- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/shuffleboard/ShuffleboardInstance.java
+++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/shuffleboard/ShuffleboardInstance.java
@@ -13,6 +13,7 @@ import java.util.Objects;
import java.util.function.Consumer;
import edu.wpi.first.networktables.NetworkTable;
+import edu.wpi.first.networktables.NetworkTableEntry;
import edu.wpi.first.networktables.NetworkTableInstance;
final class ShuffleboardInstance implements ShuffleboardRoot {
@@ -21,11 +22,13 @@ final class ShuffleboardInstance implements ShuffleboardRoot {
private boolean m_tabsChanged = false; // NOPMD redundant field initializer
private final NetworkTable m_rootTable;
private final NetworkTable m_rootMetaTable;
+ private final NetworkTableEntry m_selectedTabEntry;
ShuffleboardInstance(NetworkTableInstance ntInstance) {
Objects.requireNonNull(ntInstance, "NetworkTable instance cannot be null");
m_rootTable = ntInstance.getTable(Shuffleboard.kBaseTableName);
m_rootMetaTable = m_rootTable.getSubTable(".metadata");
+ m_selectedTabEntry = m_rootMetaTable.getEntry("Selected");
}
@Override
@@ -64,6 +67,16 @@ final class ShuffleboardInstance implements ShuffleboardRoot {
applyToAllComplexWidgets(ComplexWidget::disableIfActuator);
}
+ @Override
+ public void selectTab(int index) {
+ m_selectedTabEntry.forceSetDouble(index);
+ }
+
+ @Override
+ public void selectTab(String title) {
+ m_selectedTabEntry.forceSetString(title);
+ }
+
/**
* Applies the function {@code func} to all complex widgets in this root, regardless of how they
* are nested.
diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/shuffleboard/ShuffleboardRoot.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/shuffleboard/ShuffleboardRoot.java
index 18da1e8444..a32af69cf9 100644
--- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/shuffleboard/ShuffleboardRoot.java
+++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/shuffleboard/ShuffleboardRoot.java
@@ -38,4 +38,19 @@ interface ShuffleboardRoot {
*/
void disableActuatorWidgets();
+ /**
+ * Selects the tab in the dashboard with the given index in the range [0..n-1], where n
+ * is the number of tabs in the dashboard at the time this method is called.
+ *
+ * @param index the index of the tab to select
+ */
+ void selectTab(int index);
+
+ /**
+ * Selects the tab in the dashboard with the given title.
+ *
+ * @param title the title of the tab to select
+ */
+ void selectTab(String title);
+
}