Skip to content

Commit

Permalink
[cmd] Refactor RobotModeTriggers to use static variables
Browse files Browse the repository at this point in the history
Signed-off-by: Jade Turner <spacey-sooty@proton.me>
  • Loading branch information
spacey-sooty committed Nov 4, 2024
1 parent debb521 commit 55ac361
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 83 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,42 +9,33 @@
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 {
public:
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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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());
}

0 comments on commit 55ac361

Please sign in to comment.