2020-12-26 14:12:05 -08:00
|
|
|
// 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.
|
2020-01-20 21:35:19 -08:00
|
|
|
|
2025-11-11 18:05:12 -08:00
|
|
|
#include "wpi/commands2/button/POVButton.hpp"
|
|
|
|
|
|
2023-08-28 15:13:34 -07:00
|
|
|
#include <gtest/gtest.h>
|
2020-01-20 21:35:19 -08:00
|
|
|
|
2025-11-07 19:56:21 -05:00
|
|
|
#include "CommandTestBase.hpp"
|
|
|
|
|
#include "wpi/commands2/CommandScheduler.hpp"
|
|
|
|
|
#include "wpi/commands2/RunCommand.hpp"
|
|
|
|
|
#include "wpi/commands2/WaitUntilCommand.hpp"
|
2025-11-07 19:57:55 -05:00
|
|
|
#include "wpi/driverstation/DriverStation.hpp"
|
|
|
|
|
#include "wpi/driverstation/Joystick.hpp"
|
|
|
|
|
#include "wpi/simulation/JoystickSim.hpp"
|
2020-01-20 21:35:19 -08:00
|
|
|
|
2025-11-07 20:00:05 -05:00
|
|
|
using namespace wpi::cmd;
|
2020-01-20 21:35:19 -08:00
|
|
|
class POVButtonTest : public CommandTestBase {};
|
|
|
|
|
|
2021-09-17 22:51:51 -07:00
|
|
|
TEST_F(POVButtonTest, SetPOV) {
|
2025-11-07 20:00:05 -05:00
|
|
|
wpi::sim::JoystickSim joysim(1);
|
|
|
|
|
joysim.SetPOV(wpi::DriverStation::kUp);
|
2020-07-15 23:48:09 -07:00
|
|
|
joysim.NotifyNewData();
|
2020-01-20 21:35:19 -08:00
|
|
|
|
|
|
|
|
auto& scheduler = CommandScheduler::GetInstance();
|
|
|
|
|
bool finished = false;
|
|
|
|
|
|
|
|
|
|
WaitUntilCommand command([&finished] { return finished; });
|
|
|
|
|
|
2025-11-07 20:00:05 -05:00
|
|
|
wpi::Joystick joy(1);
|
|
|
|
|
POVButton(&joy, wpi::DriverStation::kRight).OnTrue(&command);
|
2020-01-20 21:35:19 -08:00
|
|
|
scheduler.Run();
|
|
|
|
|
EXPECT_FALSE(scheduler.IsScheduled(&command));
|
|
|
|
|
|
2025-11-07 20:00:05 -05:00
|
|
|
joysim.SetPOV(wpi::DriverStation::kRight);
|
2020-07-15 23:48:09 -07:00
|
|
|
joysim.NotifyNewData();
|
2020-01-20 21:35:19 -08:00
|
|
|
|
|
|
|
|
scheduler.Run();
|
|
|
|
|
EXPECT_TRUE(scheduler.IsScheduled(&command));
|
|
|
|
|
finished = true;
|
|
|
|
|
scheduler.Run();
|
|
|
|
|
EXPECT_FALSE(scheduler.IsScheduled(&command));
|
|
|
|
|
}
|