Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[cmd] Refactor RobotModeTriggers to use static variables #7337

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,39 +14,15 @@ public final class RobotModeTriggers {
// Utility class
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.
*/
public static Trigger autonomous() {
return new Trigger(DriverStation::isAutonomousEnabled);
}
/** A trigger that is true when the robot is enabled in autonomous mode. */
public static final 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.
*/
public static Trigger teleop() {
return new Trigger(DriverStation::isTeleopEnabled);
}
/** A trigger that is true when the robot is enabled in teleop mode. */
public static final 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.
*/
public static Trigger disabled() {
return new Trigger(DriverStation::isDisabled);
}
/** A trigger that is true when the robot is disabled. */
public static final 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.
*/
public static Trigger test() {
return new Trigger(DriverStation::isTestEnabled);
}
/** A trigger that is true when the robot is enabled in test mode. */
public static final 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,39 @@
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;

/**
* 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;

/**
* 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;

/**
* 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;
};

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
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.autonomous.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());
}
Loading