From a06f0a64809d4a2b4ba3f479ab12ac5191e602eb Mon Sep 17 00:00:00 2001 From: Hayden Heroux Date: Mon, 4 Mar 2024 15:46:21 -0500 Subject: [PATCH] refactor: Rename methods. --- simgui.json | 3 ++ src/main/java/frc/lib/Telemetry.java | 34 ++++++++++++++------- src/main/java/frc/robot/RobotContainer.java | 8 ++--- 3 files changed, 28 insertions(+), 17 deletions(-) diff --git a/simgui.json b/simgui.json index ea41e35..6e9a8b0 100644 --- a/simgui.json +++ b/simgui.json @@ -11,6 +11,9 @@ "/FMSInfo": "FMSInfo", "/Shuffleboard/Auto/Auto Chooser": "String Chooser", "/Shuffleboard/Auto/SendableChooser[0]": "String Chooser", + "/Shuffleboard/Dashboard/Auto Chooser": "String Chooser", + "/Shuffleboard/Dashboard/Auto/Auto Chooser": "String Chooser", + "/Shuffleboard/Dashboard/Auto/SendableChooser[0]": "String Chooser", "/Shuffleboard/Odometry/Field/Field": "Field2d", "/Shuffleboard/Vision/Field": "Field2d", "/SmartDashboard/Arm Mechanism": "Mechanism2d", diff --git a/src/main/java/frc/lib/Telemetry.java b/src/main/java/frc/lib/Telemetry.java index cf19c3b..d38e6a7 100644 --- a/src/main/java/frc/lib/Telemetry.java +++ b/src/main/java/frc/lib/Telemetry.java @@ -17,14 +17,14 @@ /** Helper class for managing robot telemetry. */ public class Telemetry { - private static final HashMap tabColumnCount = new HashMap<>(); + private static final HashMap tabColumn = new HashMap<>(); /** * Initializes a subsystem's Shuffleboard tab. * * @param subsystem the subsystem to initialize. */ - public static void initializeShuffleboard(Subsystem subsystem) { + public static void initializeTab(Subsystem subsystem) { String name = subsystem.getName(); ShuffleboardTab tab = Shuffleboard.getTab(name); @@ -37,9 +37,9 @@ public static void initializeShuffleboard(Subsystem subsystem) { * * @param subsystems the subsystems to initialize. */ - public static void initializeShuffleboards(Subsystem... subsystems) { + public static void initializeTabs(Subsystem... subsystems) { for (Subsystem subsystem : subsystems) { - Telemetry.initializeShuffleboard(subsystem); + Telemetry.initializeTab(subsystem); } } @@ -48,21 +48,33 @@ public static void initializeShuffleboards(Subsystem... subsystems) { * * @param tab the Shuffleboard tab to add the column to. * @param columnTitle the title of the column. + * @param width the width of the column. * @return the added Shuffleboard column. */ - public static ShuffleboardLayout addColumn(ShuffleboardTab tab, String columnTitle) { + public static ShuffleboardLayout addColumn(ShuffleboardTab tab, String columnTitle, int width) { String tabTitle = tab.getTitle(); - int currentColumnCount = tabColumnCount.getOrDefault(tabTitle, 0); - // Increment the column count for the next call - tabColumnCount.put(tabTitle, currentColumnCount + 1); + int column = tabColumn.containsKey(tabTitle) ? tabColumn.get(tabTitle) + width : 0; + + // Increment the column number for the next call + tabColumn.put(tabTitle, column); - final int kColumnWidth = 2; final int kColumnHeight = 4; return tab.getLayout(columnTitle, BuiltInLayouts.kList) - .withSize(kColumnWidth, kColumnHeight) - .withPosition(currentColumnCount * kColumnWidth, 0); + .withSize(width, kColumnHeight) + .withPosition(column, 0); + } + + /** + * Adds a column to a Shuffleboard tab. + * + * @param tab the Shuffleboard tab to add the column to. + * @param columnTitle the title of the column. + * @return the added Shuffleboard column. + */ + public static ShuffleboardLayout addColumn(ShuffleboardTab tab, String columnTitle) { + return addColumn(tab, columnTitle, 2); } /** diff --git a/src/main/java/frc/robot/RobotContainer.java b/src/main/java/frc/robot/RobotContainer.java index 86bfe57..20b1200 100644 --- a/src/main/java/frc/robot/RobotContainer.java +++ b/src/main/java/frc/robot/RobotContainer.java @@ -62,12 +62,8 @@ public static RobotContainer getInstance() { /** Initializes subsystem telemetry. */ private void initializeTelemetry() { - if (RobotConstants.USE_TELEMETRY) { - Telemetry.initializeShuffleboards(arm, climber, intake, odometry, shooter, swerve); - SmartDashboard.putData("Mechanism", RobotMechanisms.getInstance().getMechanism()); - } - - SmartDashboard.putData(auto.getAutonomousChooser()); + Telemetry.initializeTabs(arm, auto, climber, intake, odometry, shooter, swerve); + SmartDashboard.putData("Mechanism", RobotMechanisms.getInstance().getMechanism()); } /** Configures operator controller bindings. */