mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-07-03 03:01:44 +00:00
Add methods to change the selected tab in the Shuffleboard app (#1448)
This commit is contained in:
committed by
Peter Johnson
parent
a60f312d19
commit
6f0c185a05
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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 <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
|
||||
*/
|
||||
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.
|
||||
|
||||
@@ -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<Impl> m_impl;
|
||||
|
||||
@@ -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 <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
|
||||
*/
|
||||
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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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);
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user