diff --git a/wpilibNewCommands/src/main/native/include/frc2/command/button/POVButton.h b/wpilibNewCommands/src/main/native/include/frc2/command/button/POVButton.h index bc81beaac2..e4f8f0eec0 100644 --- a/wpilibNewCommands/src/main/native/include/frc2/command/button/POVButton.h +++ b/wpilibNewCommands/src/main/native/include/frc2/command/button/POVButton.h @@ -28,7 +28,7 @@ class POVButton : public Button { */ POVButton(frc::GenericHID* joystick, int angle, int povNumber = 0) : Button([joystick, angle, povNumber] { - joystick->GetPOV(povNumber) == angle; + return joystick->GetPOV(povNumber) == angle; }) {} }; } // namespace frc2 diff --git a/wpilibNewCommands/src/test/native/cpp/frc2/command/POVButtonTest.cpp b/wpilibNewCommands/src/test/native/cpp/frc2/command/POVButtonTest.cpp new file mode 100644 index 0000000000..d501943c49 --- /dev/null +++ b/wpilibNewCommands/src/test/native/cpp/frc2/command/POVButtonTest.cpp @@ -0,0 +1,47 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 2020 FIRST. All Rights Reserved. */ +/* Open Source Software - may be modified and shared by FRC teams. The code */ +/* must be accompanied by the FIRST BSD license file in the root directory of */ +/* the project. */ +/*----------------------------------------------------------------------------*/ + +#include +#include + +#include "CommandTestBase.h" +#include "frc2/command/CommandScheduler.h" +#include "frc2/command/RunCommand.h" +#include "frc2/command/WaitUntilCommand.h" +#include "frc2/command/button/POVButton.h" +#include "gtest/gtest.h" + +using namespace frc2; +class POVButtonTest : public CommandTestBase {}; + +TEST_F(POVButtonTest, SetPOVTest) { + HAL_JoystickPOVs povs; + povs.count = 1; + povs.povs[0] = 0; + HALSIM_SetJoystickPOVs(1, &povs); + HALSIM_NotifyDriverStationNewData(); + + auto& scheduler = CommandScheduler::GetInstance(); + bool finished = false; + + WaitUntilCommand command([&finished] { return finished; }); + + frc::Joystick joy(1); + POVButton(&joy, 90).WhenPressed(&command); + scheduler.Run(); + EXPECT_FALSE(scheduler.IsScheduled(&command)); + + povs.povs[0] = 90; + HALSIM_SetJoystickPOVs(1, &povs); + HALSIM_NotifyDriverStationNewData(); + + scheduler.Run(); + EXPECT_TRUE(scheduler.IsScheduled(&command)); + finished = true; + scheduler.Run(); + EXPECT_FALSE(scheduler.IsScheduled(&command)); +}