[wpilib] Add support for the PS5 DualSense controller (#5257)

Co-authored-by: Tyler Veness <calcmogul@gmail.com>
This commit is contained in:
David Baucum
2023-10-30 11:25:16 -04:00
committed by GitHub
parent 8d5e6737fc
commit 9536a311cb
12 changed files with 2730 additions and 1 deletions

View File

@@ -0,0 +1,63 @@
// 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/CommandPS5Controller.h"
using namespace frc2;
Trigger CommandPS5Controller::Button(int button, frc::EventLoop* loop) const {
return GenericHID::Button(button, loop).CastTo<Trigger>();
}
Trigger CommandPS5Controller::Square(frc::EventLoop* loop) const {
return PS5Controller::Square(loop).CastTo<Trigger>();
}
Trigger CommandPS5Controller::Cross(frc::EventLoop* loop) const {
return PS5Controller::Cross(loop).CastTo<Trigger>();
}
Trigger CommandPS5Controller::Circle(frc::EventLoop* loop) const {
return PS5Controller::Circle(loop).CastTo<Trigger>();
}
Trigger CommandPS5Controller::Triangle(frc::EventLoop* loop) const {
return PS5Controller::Triangle(loop).CastTo<Trigger>();
}
Trigger CommandPS5Controller::L1(frc::EventLoop* loop) const {
return PS5Controller::L1(loop).CastTo<Trigger>();
}
Trigger CommandPS5Controller::R1(frc::EventLoop* loop) const {
return PS5Controller::R1(loop).CastTo<Trigger>();
}
Trigger CommandPS5Controller::L2(frc::EventLoop* loop) const {
return PS5Controller::L2(loop).CastTo<Trigger>();
}
Trigger CommandPS5Controller::R2(frc::EventLoop* loop) const {
return PS5Controller::R2(loop).CastTo<Trigger>();
}
Trigger CommandPS5Controller::Options(frc::EventLoop* loop) const {
return PS5Controller::Options(loop).CastTo<Trigger>();
}
Trigger CommandPS5Controller::L3(frc::EventLoop* loop) const {
return PS5Controller::L3(loop).CastTo<Trigger>();
}
Trigger CommandPS5Controller::R3(frc::EventLoop* loop) const {
return PS5Controller::R3(loop).CastTo<Trigger>();
}
Trigger CommandPS5Controller::PS(frc::EventLoop* loop) const {
return PS5Controller::PS(loop).CastTo<Trigger>();
}
Trigger CommandPS5Controller::Touchpad(frc::EventLoop* loop) const {
return PS5Controller::Touchpad(loop).CastTo<Trigger>();
}

View File

@@ -0,0 +1,178 @@
// 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.
#pragma once
#include <frc/PS5Controller.h>
#include "Trigger.h"
#include "frc2/command/CommandScheduler.h"
namespace frc2 {
/**
* A version of {@link PS5Controller} with {@link Trigger} factories for
* command-based.
*
* @see PS5Controller
*/
class CommandPS5Controller : public frc::PS5Controller {
public:
using PS5Controller::PS5Controller;
/**
* Constructs an event instance around this button's digital signal.
*
* @param button the button index
* @param loop the event loop instance to attach the event to. Defaults to the
* CommandScheduler's default loop.
* @return an event instance representing the button's digital signal attached
* to the given loop.
*/
Trigger Button(int button,
frc::EventLoop* loop = CommandScheduler::GetInstance()
.GetDefaultButtonLoop()) const;
/**
* Constructs an event instance around the square button's digital signal.
*
* @param loop the event loop instance to attach the event to. Defaults to the
* CommandScheduler's default loop.
* @return an event instance representing the square button's digital signal
* attached to the given loop.
*/
Trigger Square(frc::EventLoop* loop = CommandScheduler::GetInstance()
.GetDefaultButtonLoop()) const;
/**
* Constructs an event instance around the cross button's digital signal.
*
* @param loop the event loop instance to attach the event to. Defaults to the
* CommandScheduler's default loop.
* @return an event instance representing the cross button's digital signal
* attached to the given loop.
*/
Trigger Cross(frc::EventLoop* loop = CommandScheduler::GetInstance()
.GetDefaultButtonLoop()) const;
/**
* Constructs an event instance around the circle button's digital signal.
*
* @param loop the event loop instance to attach the event to. Defaults to the
* CommandScheduler's default loop.
* @return an event instance representing the circle button's digital signal
* attached to the given loop.
*/
Trigger Circle(frc::EventLoop* loop = CommandScheduler::GetInstance()
.GetDefaultButtonLoop()) const;
/**
* Constructs an event instance around the triangle button's digital signal.
*
* @param loop the event loop instance to attach the event to. Defaults to the
* CommandScheduler's default loop.
* @return an event instance representing the triangle button's digital signal
* attached to the given loop.
*/
Trigger Triangle(frc::EventLoop* loop = CommandScheduler::GetInstance()
.GetDefaultButtonLoop()) const;
/**
* Constructs an event instance around the L1 button's digital signal.
*
* @param loop the event loop instance to attach the event to. Defaults to the
* CommandScheduler's default loop.
* @return an event instance representing the L1 button's digital signal
* attached to the given loop.
*/
Trigger L1(frc::EventLoop* loop =
CommandScheduler::GetInstance().GetDefaultButtonLoop()) const;
/**
* Constructs an event instance around the R1 button's digital signal.
*
* @param loop the event loop instance to attach the event to. Defaults to the
* CommandScheduler's default loop.
* @return an event instance representing the R1 button's digital signal
* attached to the given loop.
*/
Trigger R1(frc::EventLoop* loop =
CommandScheduler::GetInstance().GetDefaultButtonLoop()) const;
/**
* Constructs an event instance around the L2 button's digital signal.
*
* @param loop the event loop instance to attach the event to. Defaults to the
* CommandScheduler's default loop.
* @return an event instance representing the L2 button's digital signal
* attached to the given loop.
*/
Trigger L2(frc::EventLoop* loop =
CommandScheduler::GetInstance().GetDefaultButtonLoop()) const;
/**
* Constructs an event instance around the R2 button's digital signal.
*
* @param loop the event loop instance to attach the event to. Defaults to the
* CommandScheduler's default loop.
* @return an event instance representing the R2 button's digital signal
* attached to the given loop.
*/
Trigger R2(frc::EventLoop* loop =
CommandScheduler::GetInstance().GetDefaultButtonLoop()) const;
/**
* Constructs an event instance around the options button's digital signal.
*
* @param loop the event loop instance to attach the event to. Defaults to the
* CommandScheduler's default loop.
* @return an event instance representing the options button's digital signal
* attached to the given loop.
*/
Trigger Options(frc::EventLoop* loop = CommandScheduler::GetInstance()
.GetDefaultButtonLoop()) const;
/**
* Constructs an event instance around the L3 button's digital signal.
*
* @param loop the event loop instance to attach the event to. Defaults to the
* CommandScheduler's default loop.
* @return an event instance representing the L3 button's digital signal
* attached to the given loop.
*/
Trigger L3(frc::EventLoop* loop =
CommandScheduler::GetInstance().GetDefaultButtonLoop()) const;
/**
* Constructs an event instance around the R3 button's digital signal.
*
* @param loop the event loop instance to attach the event to. Defaults to the
* CommandScheduler's default loop.
* @return an event instance representing the R3 button's digital signal
* attached to the given loop.
*/
Trigger R3(frc::EventLoop* loop =
CommandScheduler::GetInstance().GetDefaultButtonLoop()) const;
/**
* Constructs an event instance around the PS button's digital signal.
*
* @param loop the event loop instance to attach the event to. Defaults to the
* CommandScheduler's default loop.
* @return an event instance representing the PS button's digital signal
* attached to the given loop.
*/
Trigger PS(frc::EventLoop* loop =
CommandScheduler::GetInstance().GetDefaultButtonLoop()) const;
/**
* Constructs an event instance around the touchpad's digital signal.
*
* @param loop the event loop instance to attach the event to. Defaults to the
* CommandScheduler's default loop.
* @return an event instance representing the touchpad's digital signal
* attached to the given loop.
*/
Trigger Touchpad(frc::EventLoop* loop = CommandScheduler::GetInstance()
.GetDefaultButtonLoop()) const;
};
} // namespace frc2