From 55ac36125f1911c02a9f65108de29ddadb0cdf25 Mon Sep 17 00:00:00 2001 From: Jade Turner Date: Mon, 4 Nov 2024 11:45:20 +0800 Subject: [PATCH 1/8] [cmd] Refactor RobotModeTriggers to use static variables Signed-off-by: Jade Turner --- .../command/button/RobotModeTriggers.java | 32 +++++-------------- .../frc2/command/button/RobotModeTriggers.cpp | 25 --------------- .../frc2/command/button/RobotModeTriggers.h | 27 ++++++---------- .../command/button/RobotModeTriggersTest.java | 12 +++---- .../command/button/RobotModeTriggersTest.cpp | 12 +++---- 5 files changed, 25 insertions(+), 83 deletions(-) delete mode 100644 wpilibNewCommands/src/main/native/cpp/frc2/command/button/RobotModeTriggers.cpp diff --git a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/RobotModeTriggers.java b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/RobotModeTriggers.java index 9bef66abfa3..406ce6a7395 100644 --- a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/RobotModeTriggers.java +++ b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/RobotModeTriggers.java @@ -15,38 +15,22 @@ public final class RobotModeTriggers { private RobotModeTriggers() {} /** - * Returns a trigger that is true when the robot is enabled in autonomous mode. - * - * @return A trigger that is true when the robot is enabled in autonomous mode. + * A trigger that is true when the robot is enabled in autonomous mode. */ - public static Trigger autonomous() { - return new Trigger(DriverStation::isAutonomousEnabled); - } + public static Trigger autonomous = new Trigger(DriverStation::isAutonomousEnabled); /** - * Returns a trigger that is true when the robot is enabled in teleop mode. - * - * @return A trigger that is true when the robot is enabled in teleop mode. + * A trigger that is true when the robot is enabled in teleop mode. */ - public static Trigger teleop() { - return new Trigger(DriverStation::isTeleopEnabled); - } + public static Trigger teleop = new Trigger(DriverStation::isTeleopEnabled); /** - * Returns a trigger that is true when the robot is disabled. - * - * @return A trigger that is true when the robot is disabled. + * A trigger that is true when the robot is disabled. */ - public static Trigger disabled() { - return new Trigger(DriverStation::isDisabled); - } + public static Trigger disabled = new Trigger(DriverStation::isDisabled); /** - * Returns a trigger that is true when the robot is enabled in test mode. - * - * @return A trigger that is true when the robot is enabled in test mode. + * A trigger that is true when the robot is enabled in test mode. */ - public static Trigger test() { - return new Trigger(DriverStation::isTestEnabled); - } + public static Trigger test = new Trigger(DriverStation::isTestEnabled); } diff --git a/wpilibNewCommands/src/main/native/cpp/frc2/command/button/RobotModeTriggers.cpp b/wpilibNewCommands/src/main/native/cpp/frc2/command/button/RobotModeTriggers.cpp deleted file mode 100644 index ab593d8ff29..00000000000 --- a/wpilibNewCommands/src/main/native/cpp/frc2/command/button/RobotModeTriggers.cpp +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright (c) FIRST and other WPILib contributors. -// Open Source Software; you can modify and/or share it under the terms of -// the WPILib BSD license file in the root directory of this project. - -#include "frc2/command/button/RobotModeTriggers.h" - -#include - -using namespace frc2; - -Trigger RobotModeTriggers::Autonomous() { - return Trigger{&frc::DriverStation::IsAutonomousEnabled}; -} - -Trigger RobotModeTriggers::Teleop() { - return Trigger{&frc::DriverStation::IsTeleopEnabled}; -} - -Trigger RobotModeTriggers::Disabled() { - return Trigger{&frc::DriverStation::IsDisabled}; -} - -Trigger RobotModeTriggers::Test() { - return Trigger{&frc::DriverStation::IsTestEnabled}; -} diff --git a/wpilibNewCommands/src/main/native/include/frc2/command/button/RobotModeTriggers.h b/wpilibNewCommands/src/main/native/include/frc2/command/button/RobotModeTriggers.h index 2fbcc643851..a072005a401 100644 --- a/wpilibNewCommands/src/main/native/include/frc2/command/button/RobotModeTriggers.h +++ b/wpilibNewCommands/src/main/native/include/frc2/command/button/RobotModeTriggers.h @@ -9,7 +9,7 @@ namespace frc2 { /** - * A class containing static Trigger factories for running callbacks when robot + * A class containing static Triggers for running callbacks when robot * mode changes. */ class RobotModeTriggers { @@ -17,34 +17,25 @@ class RobotModeTriggers { RobotModeTriggers() = delete; /** - * Returns a trigger that is true when the robot is enabled in autonomous - * mode. - * - * @return A trigger that is true when the robot is enabled in autonomous + * A trigger that is true when the robot is enabled in autonomous * mode. */ - static Trigger Autonomous(); + static Trigger Autonomous{&frc::DriverStation::IsAutonomousEnabled}; /** - * Returns a trigger that is true when the robot is enabled in teleop mode. - * - * @return A trigger that is true when the robot is enabled in teleop mode. + * A trigger that is true when the robot is enabled in teleop mode. */ - static Trigger Teleop(); + static Trigger Teleop{&frc::DriverStation::IsTeleopEnabled}; /** - * Returns a trigger that is true when the robot is disabled. - * - * @return A trigger that is true when the robot is disabled. + * A trigger that is true when the robot is disabled. */ - static Trigger Disabled(); + static Trigger Disabled{&frc::DriverStation::IsDisabled}; /** - * Returns a trigger that is true when the robot is enabled in test mode. - * - * @return A trigger that is true when the robot is enabled in test mode. + * A trigger that is true when the robot is enabled in test mode. */ - static Trigger Test(); + static Trigger Test{&frc::DriverStation::IsTestEnabled}; }; } // namespace frc2 diff --git a/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/button/RobotModeTriggersTest.java b/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/button/RobotModeTriggersTest.java index f7df7f0bcb6..adcb61c9877 100644 --- a/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/button/RobotModeTriggersTest.java +++ b/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/button/RobotModeTriggersTest.java @@ -18,8 +18,7 @@ void autonomousTest() { DriverStationSim.setTest(false); DriverStationSim.setEnabled(true); DriverStationSim.notifyNewData(); - Trigger auto = RobotModeTriggers.autonomous(); - assertTrue(auto.getAsBoolean()); + assertTrue(RobotModeTriggers.auto.getAsBoolean()); } @Test @@ -29,8 +28,7 @@ void teleopTest() { DriverStationSim.setTest(false); DriverStationSim.setEnabled(true); DriverStationSim.notifyNewData(); - Trigger teleop = RobotModeTriggers.teleop(); - assertTrue(teleop.getAsBoolean()); + assertTrue(RobotModeTriggers.teleop.getAsBoolean()); } @Test @@ -40,8 +38,7 @@ void testModeTest() { DriverStationSim.setTest(true); DriverStationSim.setEnabled(true); DriverStationSim.notifyNewData(); - Trigger test = RobotModeTriggers.test(); - assertTrue(test.getAsBoolean()); + assertTrue(RobotModeTriggers.test.getAsBoolean()); } @Test @@ -51,7 +48,6 @@ void disabledTest() { DriverStationSim.setTest(false); DriverStationSim.setEnabled(false); DriverStationSim.notifyNewData(); - Trigger disabled = RobotModeTriggers.disabled(); - assertTrue(disabled.getAsBoolean()); + assertTrue(RobotModeTriggers.disabled.getAsBoolean()); } } diff --git a/wpilibNewCommands/src/test/native/cpp/frc2/command/button/RobotModeTriggersTest.cpp b/wpilibNewCommands/src/test/native/cpp/frc2/command/button/RobotModeTriggersTest.cpp index adc9ec7732c..cffcdf31863 100644 --- a/wpilibNewCommands/src/test/native/cpp/frc2/command/button/RobotModeTriggersTest.cpp +++ b/wpilibNewCommands/src/test/native/cpp/frc2/command/button/RobotModeTriggersTest.cpp @@ -19,8 +19,7 @@ TEST(RobotModeTriggersTest, Autonomous) { DriverStationSim::SetTest(false); DriverStationSim::SetEnabled(true); DriverStationSim::NotifyNewData(); - Trigger autonomous = RobotModeTriggers::Autonomous(); - EXPECT_TRUE(autonomous.Get()); + EXPECT_TRUE(RobotModeTriggers::Autonomous.Get()); } TEST(RobotModeTriggersTest, Teleop) { @@ -29,8 +28,7 @@ TEST(RobotModeTriggersTest, Teleop) { DriverStationSim::SetTest(false); DriverStationSim::SetEnabled(true); DriverStationSim::NotifyNewData(); - Trigger teleop = RobotModeTriggers::Teleop(); - EXPECT_TRUE(teleop.Get()); + EXPECT_TRUE(RobotModeTriggers::Teleop.Get()); } TEST(RobotModeTriggersTest, Disabled) { @@ -39,8 +37,7 @@ TEST(RobotModeTriggersTest, Disabled) { DriverStationSim::SetTest(false); DriverStationSim::SetEnabled(false); DriverStationSim::NotifyNewData(); - Trigger disabled = RobotModeTriggers::Disabled(); - EXPECT_TRUE(disabled.Get()); + EXPECT_TRUE(RobotModeTriggers::Disabled.Get()); } TEST(RobotModeTriggersTest, TestMode) { @@ -49,6 +46,5 @@ TEST(RobotModeTriggersTest, TestMode) { DriverStationSim::SetTest(true); DriverStationSim::SetEnabled(true); DriverStationSim::NotifyNewData(); - Trigger test = RobotModeTriggers::Test(); - EXPECT_TRUE(test.Get()); + EXPECT_TRUE(RobotModeTriggers::Test.Get()); } From 28b12802d297232495f6700842a16517eeb599bf Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon, 4 Nov 2024 03:50:05 +0000 Subject: [PATCH 2/8] Formatting fixes --- .../command/button/RobotModeTriggers.java | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/RobotModeTriggers.java b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/RobotModeTriggers.java index 406ce6a7395..70345b51d71 100644 --- a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/RobotModeTriggers.java +++ b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/RobotModeTriggers.java @@ -14,23 +14,15 @@ public final class RobotModeTriggers { // Utility class private RobotModeTriggers() {} - /** - * A trigger that is true when the robot is enabled in autonomous mode. - */ + /** A trigger that is true when the robot is enabled in autonomous mode. */ public static Trigger autonomous = new Trigger(DriverStation::isAutonomousEnabled); - /** - * A trigger that is true when the robot is enabled in teleop mode. - */ + /** A trigger that is true when the robot is enabled in teleop mode. */ public static Trigger teleop = new Trigger(DriverStation::isTeleopEnabled); - /** - * A trigger that is true when the robot is disabled. - */ + /** A trigger that is true when the robot is disabled. */ public static Trigger disabled = new Trigger(DriverStation::isDisabled); - /** - * A trigger that is true when the robot is enabled in test mode. - */ + /** A trigger that is true when the robot is enabled in test mode. */ public static Trigger test = new Trigger(DriverStation::isTestEnabled); } From 9632a61cfb9cdbddce59172f1631299be37c0125 Mon Sep 17 00:00:00 2001 From: Jade Turner Date: Mon, 4 Nov 2024 12:09:17 +0800 Subject: [PATCH 3/8] fix build Signed-off-by: Jade Turner --- .../frc2/command/button/RobotModeTriggers.h | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/wpilibNewCommands/src/main/native/include/frc2/command/button/RobotModeTriggers.h b/wpilibNewCommands/src/main/native/include/frc2/command/button/RobotModeTriggers.h index a072005a401..da9c84ccaaf 100644 --- a/wpilibNewCommands/src/main/native/include/frc2/command/button/RobotModeTriggers.h +++ b/wpilibNewCommands/src/main/native/include/frc2/command/button/RobotModeTriggers.h @@ -4,6 +4,7 @@ #pragma once +#include #include "frc2/command/button/Trigger.h" namespace frc2 { @@ -20,22 +21,27 @@ class RobotModeTriggers { * A trigger that is true when the robot is enabled in autonomous * mode. */ - static Trigger Autonomous{&frc::DriverStation::IsAutonomousEnabled}; + static Trigger Autonomous; /** * A trigger that is true when the robot is enabled in teleop mode. */ - static Trigger Teleop{&frc::DriverStation::IsTeleopEnabled}; + static Trigger Teleop; /** * A trigger that is true when the robot is disabled. */ - static Trigger Disabled{&frc::DriverStation::IsDisabled}; + static Trigger Disabled; /** * A trigger that is true when the robot is enabled in test mode. */ - static Trigger Test{&frc::DriverStation::IsTestEnabled}; + static Trigger Test; }; +RobotModeTriggers::Autonomous = Trigger{&frc::DriverStation::IsAutonomousEnabled}; +RobotModeTriggers::Teleop = Trigger{&frc::DriverStation::IsTeleopEnabled}; +RobotModeTriggers::Disabled = Trigger{&frc::DriverStation::IsDisabled}; +RobotModeTriggers::Test = Trigger{&frc::DriverStation::IsTestEnabled}; + } // namespace frc2 From f7ce278a9885c72e7a8306e79653eb76508e24bc Mon Sep 17 00:00:00 2001 From: Jade Turner Date: Mon, 4 Nov 2024 12:24:07 +0800 Subject: [PATCH 4/8] fix Signed-off-by: Jade Turner --- .../include/frc2/command/button/RobotModeTriggers.h | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/wpilibNewCommands/src/main/native/include/frc2/command/button/RobotModeTriggers.h b/wpilibNewCommands/src/main/native/include/frc2/command/button/RobotModeTriggers.h index da9c84ccaaf..5ffc1b678c0 100644 --- a/wpilibNewCommands/src/main/native/include/frc2/command/button/RobotModeTriggers.h +++ b/wpilibNewCommands/src/main/native/include/frc2/command/button/RobotModeTriggers.h @@ -4,7 +4,6 @@ #pragma once -#include #include "frc2/command/button/Trigger.h" namespace frc2 { @@ -23,8 +22,7 @@ class RobotModeTriggers { */ static Trigger Autonomous; - /** - * A trigger that is true when the robot is enabled in teleop mode. + /** A trigger that is true when the robot is enabled in teleop mode. */ static Trigger Teleop; @@ -39,9 +37,9 @@ class RobotModeTriggers { static Trigger Test; }; -RobotModeTriggers::Autonomous = Trigger{&frc::DriverStation::IsAutonomousEnabled}; -RobotModeTriggers::Teleop = Trigger{&frc::DriverStation::IsTeleopEnabled}; -RobotModeTriggers::Disabled = Trigger{&frc::DriverStation::IsDisabled}; -RobotModeTriggers::Test = Trigger{&frc::DriverStation::IsTestEnabled}; +Trigger RobotModeTriggers::Autonomous = Trigger{&frc::DriverStation::IsAutonomousEnabled}; +Trigger RobotModeTriggers::Teleop = Trigger{&frc::DriverStation::IsTeleopEnabled}; +Trigger RobotModeTriggers::Disabled = Trigger{&frc::DriverStation::IsDisabled}; +Trigger RobotModeTriggers::Test = Trigger{&frc::DriverStation::IsTestEnabled}; } // namespace frc2 From 788e8b7463d1381cc10af9845feb3cdf1d0d666d Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon, 4 Nov 2024 04:31:04 +0000 Subject: [PATCH 5/8] Formatting fixes --- .../native/include/frc2/command/button/RobotModeTriggers.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/wpilibNewCommands/src/main/native/include/frc2/command/button/RobotModeTriggers.h b/wpilibNewCommands/src/main/native/include/frc2/command/button/RobotModeTriggers.h index 5ffc1b678c0..78e2c59df19 100644 --- a/wpilibNewCommands/src/main/native/include/frc2/command/button/RobotModeTriggers.h +++ b/wpilibNewCommands/src/main/native/include/frc2/command/button/RobotModeTriggers.h @@ -37,8 +37,10 @@ class RobotModeTriggers { static Trigger Test; }; -Trigger RobotModeTriggers::Autonomous = Trigger{&frc::DriverStation::IsAutonomousEnabled}; -Trigger RobotModeTriggers::Teleop = Trigger{&frc::DriverStation::IsTeleopEnabled}; +Trigger RobotModeTriggers::Autonomous = + Trigger{&frc::DriverStation::IsAutonomousEnabled}; +Trigger RobotModeTriggers::Teleop = + Trigger{&frc::DriverStation::IsTeleopEnabled}; Trigger RobotModeTriggers::Disabled = Trigger{&frc::DriverStation::IsDisabled}; Trigger RobotModeTriggers::Test = Trigger{&frc::DriverStation::IsTestEnabled}; From 707b5c1cbc2933a0e64bea34ad6f8d566e7ee0a3 Mon Sep 17 00:00:00 2001 From: Jade Turner Date: Mon, 4 Nov 2024 12:37:10 +0800 Subject: [PATCH 6/8] fiox Signed-off-by: Jade Turner --- .../first/wpilibj2/command/button/RobotModeTriggersTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/button/RobotModeTriggersTest.java b/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/button/RobotModeTriggersTest.java index adcb61c9877..2f9cb889753 100644 --- a/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/button/RobotModeTriggersTest.java +++ b/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/button/RobotModeTriggersTest.java @@ -18,7 +18,7 @@ void autonomousTest() { DriverStationSim.setTest(false); DriverStationSim.setEnabled(true); DriverStationSim.notifyNewData(); - assertTrue(RobotModeTriggers.auto.getAsBoolean()); + assertTrue(RobotModeTriggers.autonomous.getAsBoolean()); } @Test From ea6de68b7885b9e7090c85bdff8efdd388a5922e Mon Sep 17 00:00:00 2001 From: Jade Turner Date: Mon, 4 Nov 2024 12:54:05 +0800 Subject: [PATCH 7/8] final Signed-off-by: Jade Turner --- .../first/wpilibj2/command/button/RobotModeTriggers.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/RobotModeTriggers.java b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/RobotModeTriggers.java index 70345b51d71..650d0b323f3 100644 --- a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/RobotModeTriggers.java +++ b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/RobotModeTriggers.java @@ -15,14 +15,14 @@ public final class RobotModeTriggers { private RobotModeTriggers() {} /** A trigger that is true when the robot is enabled in autonomous mode. */ - public static Trigger autonomous = new Trigger(DriverStation::isAutonomousEnabled); + public final static Trigger autonomous = new Trigger(DriverStation::isAutonomousEnabled); /** A trigger that is true when the robot is enabled in teleop mode. */ - public static Trigger teleop = new Trigger(DriverStation::isTeleopEnabled); + public final static Trigger teleop = new Trigger(DriverStation::isTeleopEnabled); /** A trigger that is true when the robot is disabled. */ - public static Trigger disabled = new Trigger(DriverStation::isDisabled); + public final static Trigger disabled = new Trigger(DriverStation::isDisabled); /** A trigger that is true when the robot is enabled in test mode. */ - public static Trigger test = new Trigger(DriverStation::isTestEnabled); + public final static Trigger test = new Trigger(DriverStation::isTestEnabled); } From 5aa265893c655e1cc5f80388e2e003dddb70024b Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon, 4 Nov 2024 05:04:06 +0000 Subject: [PATCH 8/8] Formatting fixes --- .../first/wpilibj2/command/button/RobotModeTriggers.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/RobotModeTriggers.java b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/RobotModeTriggers.java index 650d0b323f3..42984dade56 100644 --- a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/RobotModeTriggers.java +++ b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/RobotModeTriggers.java @@ -15,14 +15,14 @@ public final class RobotModeTriggers { private RobotModeTriggers() {} /** A trigger that is true when the robot is enabled in autonomous mode. */ - public final static Trigger autonomous = new Trigger(DriverStation::isAutonomousEnabled); + public static final Trigger autonomous = new Trigger(DriverStation::isAutonomousEnabled); /** A trigger that is true when the robot is enabled in teleop mode. */ - public final static Trigger teleop = new Trigger(DriverStation::isTeleopEnabled); + public static final Trigger teleop = new Trigger(DriverStation::isTeleopEnabled); /** A trigger that is true when the robot is disabled. */ - public final static Trigger disabled = new Trigger(DriverStation::isDisabled); + public static final Trigger disabled = new Trigger(DriverStation::isDisabled); /** A trigger that is true when the robot is enabled in test mode. */ - public final static Trigger test = new Trigger(DriverStation::isTestEnabled); + public static final Trigger test = new Trigger(DriverStation::isTestEnabled); }