Add methods to change the selected tab in the Shuffleboard app (#1448)

This commit is contained in:
Sam Carlberg
2018-11-28 01:12:50 -05:00
committed by Peter Johnson
parent a60f312d19
commit 6f0c185a05
8 changed files with 97 additions and 0 deletions

View File

@@ -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 <i>n</i>
* 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

View File

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

View File

@@ -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 <i>n</i>
* 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);
}