11package frc .robot .util ;
22
3-
43import edu .wpi .first .networktables .GenericEntry ;
54import edu .wpi .first .wpilibj .shuffleboard .BuiltInWidgets ;
65import edu .wpi .first .wpilibj .shuffleboard .Shuffleboard ;
76import edu .wpi .first .wpilibj .shuffleboard .ShuffleboardTab ;
87import edu .wpi .first .wpilibj2 .command .button .Trigger ;
98
10-
119/**
12- * AutoResetDashboardTrigger
13- * -------------------------
14- * A dashboard-backed one-shot trigger designed to behave like
15- * a gamepad "onTrue" button.
16- *
17- * Behavior:
18- * - Exposes a Shuffleboard Toggle Button
19- * - Detects a FALSE -> TRUE transition (rising edge)
20- * - Fires TRUE for exactly one scheduler loop
21- * - Automatically resets the dashboard value back to FALSE
22- *
23- * Intended use cases:
24- * - Single-action commands (reset, zeroing, shoot-once, test actions)
25- * - Debug and pit utilities where holding a button is unsafe
26- *
27- * Not intended for:
28- * - whileTrue / continuous commands
29- * - toggle or latch-style behaviors
30- */
10+ * AutoResetDashboardTrigger ------------------------- A dashboard-backed one-shot trigger designed to behave like a
11+ * gamepad "onTrue" button.
12+ *
13+ * <p>Behavior: - Exposes a Shuffleboard Toggle Button - Detects a FALSE -> TRUE transition (rising edge) - Fires TRUE
14+ * for exactly one scheduler loop - Automatically resets the dashboard value back to FALSE
15+ *
16+ * <p>Intended use cases: - Single-action commands (reset, zeroing, shoot-once, test actions) - Debug and pit utilities
17+ * where holding a button is unsafe
18+ *
19+ * <p>Not intended for: - whileTrue / continuous commands - toggle or latch-style behaviors
20+ */
3121public final class DashboardTrigger {
3222
33-
34- /** NetworkTables-backed boolean entry shown on Shuffleboard */
35- private final GenericEntry buttonEntry ;
36-
37-
38- /** Cached previous value for edge detection */
39- private boolean previousValue = false ;
40-
41-
42- /**
43- * Creates an auto-resetting dashboard trigger.
44- *
45- * @param tabName Shuffleboard tab name
46- * @param buttonName Label displayed on the dashboard
47- */
48- public DashboardTrigger (String tabName , String buttonName ) {
49- ShuffleboardTab tab = Shuffleboard .getTab (tabName );
50-
51-
52- this .buttonEntry = tab .add (buttonName , false )
53- .withWidget (BuiltInWidgets .kToggleButton )
54- .getEntry ();
55- }
56-
57-
58- /**
59- * Returns a WPILib Trigger that fires exactly once
60- * when the dashboard button is pressed.
61- *
62- * @return one-shot Trigger (rising-edge based)
63- */
64- public Trigger trigger () {
65- return new Trigger (() -> {
66- boolean currentValue = buttonEntry .getBoolean (false );
67-
68-
69- // Rising edge detection
70- if (currentValue && !previousValue ) {
71- buttonEntry .setBoolean (false ); // auto-reset immediately
72- previousValue = true ;
73- return true ;
23+ /** NetworkTables-backed boolean entry shown on Shuffleboard */
24+ private final GenericEntry buttonEntry ;
25+
26+ /** Cached previous value for edge detection */
27+ private boolean previousValue = false ;
28+
29+ /**
30+ * Creates an auto-resetting dashboard trigger.
31+ *
32+ * @param tabName Shuffleboard tab name
33+ * @param buttonName Label displayed on the dashboard
34+ */
35+ public DashboardTrigger (String tabName , String buttonName ) {
36+ ShuffleboardTab tab = Shuffleboard .getTab (tabName );
37+
38+ this .buttonEntry = tab .add (buttonName , false )
39+ .withWidget (BuiltInWidgets .kToggleButton )
40+ .getEntry ();
41+ }
42+
43+ /**
44+ * Returns a WPILib Trigger that fires exactly once when the dashboard button is pressed.
45+ *
46+ * @return one-shot Trigger (rising-edge based)
47+ */
48+ public Trigger trigger () {
49+ return new Trigger (() -> {
50+ boolean currentValue = buttonEntry .getBoolean (false );
51+
52+ // Rising edge detection
53+ if (currentValue && !previousValue ) {
54+ buttonEntry .setBoolean (false ); // auto-reset immediately
55+ previousValue = true ;
56+ return true ;
57+ }
58+
59+ previousValue = currentValue ;
60+ return false ;
61+ });
62+ }
63+
64+ /** Programmatically fires the trigger once. Useful for tests or internal control logic. */
65+ public void fireOnce () {
66+ buttonEntry .setBoolean (true );
67+ }
7468}
7569
76-
77- previousValue = currentValue ;
78- return false ;
79- });
80- }
81-
82-
83- /**
84- * Programmatically fires the trigger once.
85- * Useful for tests or internal control logic.
86- */
87- public void fireOnce () {
88- buttonEntry .setBoolean (true );
89- }
90- }
91-
92-
9370/*
9471========================
9572Example usage (RobotContainer)
@@ -106,4 +83,4 @@ Example usage (RobotContainer)
10683
10784// Designed for onTrue only
10885// whileTrue / toggle usage is intentionally unsupported
109- */
86+ */
0 commit comments