mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-23 01:21:42 +00:00
SCRIPT Move cc files
This commit is contained in:
committed by
Peter Johnson
parent
10b4a0c971
commit
7ca1be9bae
@@ -0,0 +1,434 @@
|
||||
// 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/Gamepad.h>
|
||||
|
||||
#include "frc2/command/CommandScheduler.h"
|
||||
#include "frc2/command/button/CommandGenericHID.h"
|
||||
#include "frc2/command/button/Trigger.h"
|
||||
|
||||
namespace frc2 {
|
||||
/**
|
||||
* A version of {@link frc::Gamepad} with {@link Trigger} factories for
|
||||
* command-based.
|
||||
*
|
||||
* @see frc::Gamepad
|
||||
*/
|
||||
class CommandGamepad : public CommandGenericHID {
|
||||
public:
|
||||
/**
|
||||
* Construct an instance of a controller.
|
||||
*
|
||||
* @param port The port index on the Driver Station that the controller is
|
||||
* plugged into.
|
||||
*/
|
||||
explicit CommandGamepad(int port);
|
||||
|
||||
/**
|
||||
* Get the underlying GenericHID object.
|
||||
*
|
||||
* @return the wrapped GenericHID object
|
||||
*/
|
||||
frc::Gamepad& GetHID();
|
||||
|
||||
/**
|
||||
* Constructs a Trigger instance around the South Face button's
|
||||
* digital signal.
|
||||
*
|
||||
* @param loop the event loop instance to attach the event to. Defaults to the
|
||||
* CommandScheduler's default loop.
|
||||
* @return a Trigger instance representing the South Face button's
|
||||
* digital signal attached to the given loop.
|
||||
*/
|
||||
Trigger SouthFace(frc::EventLoop* loop = CommandScheduler::GetInstance()
|
||||
.GetDefaultButtonLoop()) const;
|
||||
|
||||
/**
|
||||
* Constructs a Trigger instance around the East Face button's
|
||||
* digital signal.
|
||||
*
|
||||
* @param loop the event loop instance to attach the event to. Defaults to the
|
||||
* CommandScheduler's default loop.
|
||||
* @return a Trigger instance representing the East Face button's
|
||||
* digital signal attached to the given loop.
|
||||
*/
|
||||
Trigger EastFace(frc::EventLoop* loop = CommandScheduler::GetInstance()
|
||||
.GetDefaultButtonLoop()) const;
|
||||
|
||||
/**
|
||||
* Constructs a Trigger instance around the West Face button's
|
||||
* digital signal.
|
||||
*
|
||||
* @param loop the event loop instance to attach the event to. Defaults to the
|
||||
* CommandScheduler's default loop.
|
||||
* @return a Trigger instance representing the West Face button's
|
||||
* digital signal attached to the given loop.
|
||||
*/
|
||||
Trigger WestFace(frc::EventLoop* loop = CommandScheduler::GetInstance()
|
||||
.GetDefaultButtonLoop()) const;
|
||||
|
||||
/**
|
||||
* Constructs a Trigger instance around the North Face button's
|
||||
* digital signal.
|
||||
*
|
||||
* @param loop the event loop instance to attach the event to. Defaults to the
|
||||
* CommandScheduler's default loop.
|
||||
* @return a Trigger instance representing the North Face button's
|
||||
* digital signal attached to the given loop.
|
||||
*/
|
||||
Trigger NorthFace(frc::EventLoop* loop = CommandScheduler::GetInstance()
|
||||
.GetDefaultButtonLoop()) const;
|
||||
|
||||
/**
|
||||
* Constructs a Trigger instance around the Back button's
|
||||
* digital signal.
|
||||
*
|
||||
* @param loop the event loop instance to attach the event to. Defaults to the
|
||||
* CommandScheduler's default loop.
|
||||
* @return a Trigger instance representing the Back button's
|
||||
* digital signal attached to the given loop.
|
||||
*/
|
||||
Trigger Back(frc::EventLoop* loop = CommandScheduler::GetInstance()
|
||||
.GetDefaultButtonLoop()) const;
|
||||
|
||||
/**
|
||||
* Constructs a Trigger instance around the Guide button's
|
||||
* digital signal.
|
||||
*
|
||||
* @param loop the event loop instance to attach the event to. Defaults to the
|
||||
* CommandScheduler's default loop.
|
||||
* @return a Trigger instance representing the Guide button's
|
||||
* digital signal attached to the given loop.
|
||||
*/
|
||||
Trigger Guide(frc::EventLoop* loop = CommandScheduler::GetInstance()
|
||||
.GetDefaultButtonLoop()) const;
|
||||
|
||||
/**
|
||||
* Constructs a Trigger instance around the Start button's
|
||||
* digital signal.
|
||||
*
|
||||
* @param loop the event loop instance to attach the event to. Defaults to the
|
||||
* CommandScheduler's default loop.
|
||||
* @return a Trigger instance representing the Start button's
|
||||
* digital signal attached to the given loop.
|
||||
*/
|
||||
Trigger Start(frc::EventLoop* loop = CommandScheduler::GetInstance()
|
||||
.GetDefaultButtonLoop()) const;
|
||||
|
||||
/**
|
||||
* Constructs a Trigger instance around the left stick button's
|
||||
* digital signal.
|
||||
*
|
||||
* @param loop the event loop instance to attach the event to. Defaults to the
|
||||
* CommandScheduler's default loop.
|
||||
* @return a Trigger instance representing the left stick button's
|
||||
* digital signal attached to the given loop.
|
||||
*/
|
||||
Trigger LeftStick(frc::EventLoop* loop = CommandScheduler::GetInstance()
|
||||
.GetDefaultButtonLoop()) const;
|
||||
|
||||
/**
|
||||
* Constructs a Trigger instance around the right stick button's
|
||||
* digital signal.
|
||||
*
|
||||
* @param loop the event loop instance to attach the event to. Defaults to the
|
||||
* CommandScheduler's default loop.
|
||||
* @return a Trigger instance representing the right stick button's
|
||||
* digital signal attached to the given loop.
|
||||
*/
|
||||
Trigger RightStick(frc::EventLoop* loop = CommandScheduler::GetInstance()
|
||||
.GetDefaultButtonLoop()) const;
|
||||
|
||||
/**
|
||||
* Constructs a Trigger instance around the right shoulder button's
|
||||
* digital signal.
|
||||
*
|
||||
* @param loop the event loop instance to attach the event to. Defaults to the
|
||||
* CommandScheduler's default loop.
|
||||
* @return a Trigger instance representing the right shoulder button's
|
||||
* digital signal attached to the given loop.
|
||||
*/
|
||||
Trigger LeftShoulder(
|
||||
frc::EventLoop* loop =
|
||||
CommandScheduler::GetInstance().GetDefaultButtonLoop()) const;
|
||||
|
||||
/**
|
||||
* Constructs a Trigger instance around the right shoulder button's
|
||||
* digital signal.
|
||||
*
|
||||
* @param loop the event loop instance to attach the event to. Defaults to the
|
||||
* CommandScheduler's default loop.
|
||||
* @return a Trigger instance representing the right shoulder button's
|
||||
* digital signal attached to the given loop.
|
||||
*/
|
||||
Trigger RightShoulder(
|
||||
frc::EventLoop* loop =
|
||||
CommandScheduler::GetInstance().GetDefaultButtonLoop()) const;
|
||||
|
||||
/**
|
||||
* Constructs a Trigger instance around the D-pad up button's
|
||||
* digital signal.
|
||||
*
|
||||
* @param loop the event loop instance to attach the event to. Defaults to the
|
||||
* CommandScheduler's default loop.
|
||||
* @return a Trigger instance representing the D-pad up button's
|
||||
* digital signal attached to the given loop.
|
||||
*/
|
||||
Trigger DpadUp(frc::EventLoop* loop = CommandScheduler::GetInstance()
|
||||
.GetDefaultButtonLoop()) const;
|
||||
|
||||
/**
|
||||
* Constructs a Trigger instance around the D-pad down button's
|
||||
* digital signal.
|
||||
*
|
||||
* @param loop the event loop instance to attach the event to. Defaults to the
|
||||
* CommandScheduler's default loop.
|
||||
* @return a Trigger instance representing the D-pad down button's
|
||||
* digital signal attached to the given loop.
|
||||
*/
|
||||
Trigger DpadDown(frc::EventLoop* loop = CommandScheduler::GetInstance()
|
||||
.GetDefaultButtonLoop()) const;
|
||||
|
||||
/**
|
||||
* Constructs a Trigger instance around the D-pad left button's
|
||||
* digital signal.
|
||||
*
|
||||
* @param loop the event loop instance to attach the event to. Defaults to the
|
||||
* CommandScheduler's default loop.
|
||||
* @return a Trigger instance representing the D-pad left button's
|
||||
* digital signal attached to the given loop.
|
||||
*/
|
||||
Trigger DpadLeft(frc::EventLoop* loop = CommandScheduler::GetInstance()
|
||||
.GetDefaultButtonLoop()) const;
|
||||
|
||||
/**
|
||||
* Constructs a Trigger instance around the D-pad right button's
|
||||
* digital signal.
|
||||
*
|
||||
* @param loop the event loop instance to attach the event to. Defaults to the
|
||||
* CommandScheduler's default loop.
|
||||
* @return a Trigger instance representing the D-pad right button's
|
||||
* digital signal attached to the given loop.
|
||||
*/
|
||||
Trigger DpadRight(frc::EventLoop* loop = CommandScheduler::GetInstance()
|
||||
.GetDefaultButtonLoop()) const;
|
||||
|
||||
/**
|
||||
* Constructs a Trigger instance around the Miscellaneous 1 button's
|
||||
* digital signal.
|
||||
*
|
||||
* @param loop the event loop instance to attach the event to. Defaults to the
|
||||
* CommandScheduler's default loop.
|
||||
* @return a Trigger instance representing the Miscellaneous 1 button's
|
||||
* digital signal attached to the given loop.
|
||||
*/
|
||||
Trigger Misc1(frc::EventLoop* loop = CommandScheduler::GetInstance()
|
||||
.GetDefaultButtonLoop()) const;
|
||||
|
||||
/**
|
||||
* Constructs a Trigger instance around the Right Paddle 1 button's
|
||||
* digital signal.
|
||||
*
|
||||
* @param loop the event loop instance to attach the event to. Defaults to the
|
||||
* CommandScheduler's default loop.
|
||||
* @return a Trigger instance representing the Right Paddle 1 button's
|
||||
* digital signal attached to the given loop.
|
||||
*/
|
||||
Trigger RightPaddle1(
|
||||
frc::EventLoop* loop =
|
||||
CommandScheduler::GetInstance().GetDefaultButtonLoop()) const;
|
||||
|
||||
/**
|
||||
* Constructs a Trigger instance around the Left Paddle 1 button's
|
||||
* digital signal.
|
||||
*
|
||||
* @param loop the event loop instance to attach the event to. Defaults to the
|
||||
* CommandScheduler's default loop.
|
||||
* @return a Trigger instance representing the Left Paddle 1 button's
|
||||
* digital signal attached to the given loop.
|
||||
*/
|
||||
Trigger LeftPaddle1(frc::EventLoop* loop = CommandScheduler::GetInstance()
|
||||
.GetDefaultButtonLoop()) const;
|
||||
|
||||
/**
|
||||
* Constructs a Trigger instance around the Right Paddle 2 button's
|
||||
* digital signal.
|
||||
*
|
||||
* @param loop the event loop instance to attach the event to. Defaults to the
|
||||
* CommandScheduler's default loop.
|
||||
* @return a Trigger instance representing the Right Paddle 2 button's
|
||||
* digital signal attached to the given loop.
|
||||
*/
|
||||
Trigger RightPaddle2(
|
||||
frc::EventLoop* loop =
|
||||
CommandScheduler::GetInstance().GetDefaultButtonLoop()) const;
|
||||
|
||||
/**
|
||||
* Constructs a Trigger instance around the Left Paddle 2 button's
|
||||
* digital signal.
|
||||
*
|
||||
* @param loop the event loop instance to attach the event to. Defaults to the
|
||||
* CommandScheduler's default loop.
|
||||
* @return a Trigger instance representing the Left Paddle 2 button's
|
||||
* digital signal attached to the given loop.
|
||||
*/
|
||||
Trigger LeftPaddle2(frc::EventLoop* loop = CommandScheduler::GetInstance()
|
||||
.GetDefaultButtonLoop()) const;
|
||||
|
||||
/**
|
||||
* Constructs a Trigger instance around the Touchpad button's
|
||||
* digital signal.
|
||||
*
|
||||
* @param loop the event loop instance to attach the event to. Defaults to the
|
||||
* CommandScheduler's default loop.
|
||||
* @return a Trigger instance representing the Touchpad button's
|
||||
* digital signal attached to the given loop.
|
||||
*/
|
||||
Trigger Touchpad(frc::EventLoop* loop = CommandScheduler::GetInstance()
|
||||
.GetDefaultButtonLoop()) const;
|
||||
|
||||
/**
|
||||
* Constructs a Trigger instance around the Miscellaneous 2 button's
|
||||
* digital signal.
|
||||
*
|
||||
* @param loop the event loop instance to attach the event to. Defaults to the
|
||||
* CommandScheduler's default loop.
|
||||
* @return a Trigger instance representing the Miscellaneous 2 button's
|
||||
* digital signal attached to the given loop.
|
||||
*/
|
||||
Trigger Misc2(frc::EventLoop* loop = CommandScheduler::GetInstance()
|
||||
.GetDefaultButtonLoop()) const;
|
||||
|
||||
/**
|
||||
* Constructs a Trigger instance around the Miscellaneous 3 button's
|
||||
* digital signal.
|
||||
*
|
||||
* @param loop the event loop instance to attach the event to. Defaults to the
|
||||
* CommandScheduler's default loop.
|
||||
* @return a Trigger instance representing the Miscellaneous 3 button's
|
||||
* digital signal attached to the given loop.
|
||||
*/
|
||||
Trigger Misc3(frc::EventLoop* loop = CommandScheduler::GetInstance()
|
||||
.GetDefaultButtonLoop()) const;
|
||||
|
||||
/**
|
||||
* Constructs a Trigger instance around the Miscellaneous 4 button's
|
||||
* digital signal.
|
||||
*
|
||||
* @param loop the event loop instance to attach the event to. Defaults to the
|
||||
* CommandScheduler's default loop.
|
||||
* @return a Trigger instance representing the Miscellaneous 4 button's
|
||||
* digital signal attached to the given loop.
|
||||
*/
|
||||
Trigger Misc4(frc::EventLoop* loop = CommandScheduler::GetInstance()
|
||||
.GetDefaultButtonLoop()) const;
|
||||
|
||||
/**
|
||||
* Constructs a Trigger instance around the Miscellaneous 5 button's
|
||||
* digital signal.
|
||||
*
|
||||
* @param loop the event loop instance to attach the event to. Defaults to the
|
||||
* CommandScheduler's default loop.
|
||||
* @return a Trigger instance representing the Miscellaneous 5 button's
|
||||
* digital signal attached to the given loop.
|
||||
*/
|
||||
Trigger Misc5(frc::EventLoop* loop = CommandScheduler::GetInstance()
|
||||
.GetDefaultButtonLoop()) const;
|
||||
|
||||
/**
|
||||
* Constructs a Trigger instance around the Miscellaneous 6 button's
|
||||
* digital signal.
|
||||
*
|
||||
* @param loop the event loop instance to attach the event to. Defaults to the
|
||||
* CommandScheduler's default loop.
|
||||
* @return a Trigger instance representing the Miscellaneous 6 button's
|
||||
* digital signal attached to the given loop.
|
||||
*/
|
||||
Trigger Misc6(frc::EventLoop* loop = CommandScheduler::GetInstance()
|
||||
.GetDefaultButtonLoop()) const;
|
||||
|
||||
/**
|
||||
* Constructs a Trigger instance around the axis value of the left trigger.
|
||||
* The returned Trigger will be true when the axis value is greater than
|
||||
* {@code threshold}.
|
||||
*
|
||||
* @param threshold the minimum axis value for the returned Trigger to be
|
||||
* true. This value should be in the range [0, 1] where 0 is the unpressed
|
||||
* state of the axis. Defaults to 0.5.
|
||||
* @param loop the event loop instance to attach the Trigger to. Defaults to
|
||||
* the CommandScheduler's default loop.
|
||||
* @return a Trigger instance that is true when the left trigger's axis
|
||||
* exceeds the provided threshold, attached to the given loop
|
||||
*/
|
||||
Trigger LeftTrigger(double threshold = 0.5,
|
||||
frc::EventLoop* loop = CommandScheduler::GetInstance()
|
||||
.GetDefaultButtonLoop()) const;
|
||||
|
||||
/**
|
||||
* Constructs a Trigger instance around the axis value of the right trigger.
|
||||
* The returned Trigger will be true when the axis value is greater than
|
||||
* {@code threshold}.
|
||||
*
|
||||
* @param threshold the minimum axis value for the returned Trigger to be
|
||||
* true. This value should be in the range [0, 1] where 0 is the unpressed
|
||||
* state of the axis. Defaults to 0.5.
|
||||
* @param loop the event loop instance to attach the Trigger to. Defaults to
|
||||
* the CommandScheduler's default loop.
|
||||
* @return a Trigger instance that is true when the right trigger's axis
|
||||
* exceeds the provided threshold, attached to the given loop
|
||||
*/
|
||||
Trigger RightTrigger(
|
||||
double threshold = 0.5,
|
||||
frc::EventLoop* loop =
|
||||
CommandScheduler::GetInstance().GetDefaultButtonLoop()) const;
|
||||
|
||||
/**
|
||||
* Get the X axis value of left side of the controller. Right is positive.
|
||||
*
|
||||
* @return The axis value.
|
||||
*/
|
||||
double GetLeftX() const;
|
||||
|
||||
/**
|
||||
* Get the Y axis value of left side of the controller. Back is positive.
|
||||
*
|
||||
* @return The axis value.
|
||||
*/
|
||||
double GetLeftY() const;
|
||||
|
||||
/**
|
||||
* Get the X axis value of right side of the controller. Right is positive.
|
||||
*
|
||||
* @return The axis value.
|
||||
*/
|
||||
double GetRightX() const;
|
||||
|
||||
/**
|
||||
* Get the Y axis value of right side of the controller. Back is positive.
|
||||
*
|
||||
* @return The axis value.
|
||||
*/
|
||||
double GetRightY() const;
|
||||
|
||||
/**
|
||||
* Get the left trigger axis value of the controller. Note that this axis is
|
||||
* bound to the range of [0, 1] as opposed to the usual [-1, 1].
|
||||
*
|
||||
* @return The axis value.
|
||||
*/
|
||||
double GetLeftTriggerAxis() const;
|
||||
|
||||
/**
|
||||
* Get the right trigger axis value of the controller. Note that this axis is
|
||||
* bound to the range of [0, 1] as opposed to the usual [-1, 1].
|
||||
*
|
||||
* @return The axis value.
|
||||
*/
|
||||
double GetRightTriggerAxis() const;
|
||||
|
||||
private:
|
||||
frc::Gamepad m_hid;
|
||||
};
|
||||
} // namespace frc2
|
||||
@@ -0,0 +1,264 @@
|
||||
// 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/DriverStation.h>
|
||||
#include <frc/GenericHID.h>
|
||||
|
||||
#include "Trigger.h"
|
||||
#include "frc2/command/CommandScheduler.h"
|
||||
|
||||
namespace frc2 {
|
||||
|
||||
/**
|
||||
* A version of {@link frc::GenericHID} with {@link Trigger} factories for
|
||||
* command-based.
|
||||
*
|
||||
* @see GenericHID
|
||||
*/
|
||||
class CommandGenericHID {
|
||||
public:
|
||||
/**
|
||||
* Construct an instance of a device.
|
||||
*
|
||||
* @param port The port index on the Driver Station that the device is plugged
|
||||
* into.
|
||||
*/
|
||||
explicit CommandGenericHID(int port);
|
||||
|
||||
/**
|
||||
* Get the underlying GenericHID object.
|
||||
*
|
||||
* @return the wrapped GenericHID object
|
||||
*/
|
||||
frc::GenericHID& GetHID();
|
||||
|
||||
/**
|
||||
* 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 a Trigger instance based around this angle of a POV on the HID.
|
||||
*
|
||||
* @param loop the event loop instance to attach the event to. Defaults to
|
||||
* {@link CommandScheduler::GetDefaultButtonLoop() the default command
|
||||
* scheduler button loop}.
|
||||
* @param angle POV angle.
|
||||
* @return a Trigger instance based around this angle of a POV on the HID.
|
||||
*/
|
||||
Trigger POV(frc::DriverStation::POVDirection angle,
|
||||
frc::EventLoop* loop =
|
||||
CommandScheduler::GetInstance().GetDefaultButtonLoop()) const;
|
||||
|
||||
/**
|
||||
* Constructs a Trigger instance based around this angle of a POV on the HID.
|
||||
*
|
||||
* @param loop the event loop instance to attach the event to. Defaults to
|
||||
* {@link CommandScheduler::GetDefaultButtonLoop() the default command
|
||||
* scheduler button loop}.
|
||||
* @param pov index of the POV to read (starting at 0). Defaults to 0.
|
||||
* @param angle POV angle.
|
||||
* @return a Trigger instance based around this angle of a POV on the HID.
|
||||
*/
|
||||
Trigger POV(int pov, frc::DriverStation::POVDirection angle,
|
||||
frc::EventLoop* loop =
|
||||
CommandScheduler::GetInstance().GetDefaultButtonLoop()) const;
|
||||
|
||||
/**
|
||||
* Constructs a Trigger instance based around the up direction of the
|
||||
* default (index 0) POV on the HID.
|
||||
*
|
||||
* @param loop the event loop instance to attach the event to. Defaults to
|
||||
* {@link CommandScheduler::GetDefaultButtonLoop() the default command
|
||||
* scheduler button loop}.
|
||||
* @return a Trigger instance based around the up direction of a POV on the
|
||||
* HID.
|
||||
*/
|
||||
Trigger POVUp(frc::EventLoop* loop = CommandScheduler::GetInstance()
|
||||
.GetDefaultButtonLoop()) const;
|
||||
|
||||
/**
|
||||
* Constructs a Trigger instance based around the up right direction
|
||||
* of the default (index 0) POV on the HID.
|
||||
*
|
||||
* @param loop the event loop instance to attach the event to. Defaults to
|
||||
* {@link CommandScheduler::GetDefaultButtonLoop() the default command
|
||||
* scheduler button loop}.
|
||||
* @return a Trigger instance based around the up right direction of a POV on
|
||||
* the HID.
|
||||
*/
|
||||
Trigger POVUpRight(frc::EventLoop* loop = CommandScheduler::GetInstance()
|
||||
.GetDefaultButtonLoop()) const;
|
||||
|
||||
/**
|
||||
* Constructs a Trigger instance based around the right direction of
|
||||
* the default (index 0) POV on the HID.
|
||||
*
|
||||
* @param loop the event loop instance to attach the event to. Defaults to
|
||||
* {@link CommandScheduler::GetDefaultButtonLoop() the default command
|
||||
* scheduler button loop}.
|
||||
* @return a Trigger instance based around the right direction of a POV on the
|
||||
* HID.
|
||||
*/
|
||||
Trigger POVRight(frc::EventLoop* loop = CommandScheduler::GetInstance()
|
||||
.GetDefaultButtonLoop()) const;
|
||||
|
||||
/**
|
||||
* Constructs a Trigger instance based around the down right direction
|
||||
* of the default (index 0) POV on the HID.
|
||||
*
|
||||
* @return a Trigger instance based around the down right direction of a POV
|
||||
* on the HID.
|
||||
*/
|
||||
Trigger POVDownRight(
|
||||
frc::EventLoop* loop =
|
||||
CommandScheduler::GetInstance().GetDefaultButtonLoop()) const;
|
||||
|
||||
/**
|
||||
* Constructs a Trigger instance based around the down direction of
|
||||
* the default (index 0) POV on the HID.
|
||||
*
|
||||
* @param loop the event loop instance to attach the event to. Defaults to
|
||||
* {@link CommandScheduler::GetDefaultButtonLoop() the default command
|
||||
* scheduler button loop}.
|
||||
* @return a Trigger instance based around the down direction of a POV on
|
||||
* the HID.
|
||||
*/
|
||||
Trigger POVDown(frc::EventLoop* loop = CommandScheduler::GetInstance()
|
||||
.GetDefaultButtonLoop()) const;
|
||||
|
||||
/**
|
||||
* Constructs a Trigger instance based around the down left direction
|
||||
* of the default (index 0) POV on the HID.
|
||||
*
|
||||
* @param loop the event loop instance to attach the event to. Defaults to
|
||||
* {@link CommandScheduler::GetDefaultButtonLoop() the default command
|
||||
* scheduler button loop}.
|
||||
* @return a Trigger instance based around the down left direction of a POV on
|
||||
* the HID.
|
||||
*/
|
||||
Trigger POVDownLeft(frc::EventLoop* loop = CommandScheduler::GetInstance()
|
||||
.GetDefaultButtonLoop()) const;
|
||||
|
||||
/**
|
||||
* Constructs a Trigger instance based around the left direction of
|
||||
* the default (index 0) POV on the HID.
|
||||
*
|
||||
* @param loop the event loop instance to attach the event to. Defaults to
|
||||
* {@link CommandScheduler::GetDefaultButtonLoop() the default command
|
||||
* scheduler button loop}.
|
||||
* @return a Trigger instance based around the left direction of a POV on
|
||||
* the HID.
|
||||
*/
|
||||
Trigger POVLeft(frc::EventLoop* loop = CommandScheduler::GetInstance()
|
||||
.GetDefaultButtonLoop()) const;
|
||||
|
||||
/**
|
||||
* Constructs a Trigger instance based around the up left direction
|
||||
* of the default (index 0) POV on the HID.
|
||||
*
|
||||
* @param loop the event loop instance to attach the event to. Defaults to
|
||||
* {@link CommandScheduler::GetDefaultButtonLoop() the default command
|
||||
* scheduler button loop}.
|
||||
* @return a Trigger instance based around the up left direction of a POV on
|
||||
* the HID.
|
||||
*/
|
||||
Trigger POVUpLeft(frc::EventLoop* loop = CommandScheduler::GetInstance()
|
||||
.GetDefaultButtonLoop()) const;
|
||||
|
||||
/**
|
||||
* Constructs a Trigger instance based around the center (not pressed)
|
||||
* position of the default (index 0) POV on the HID.
|
||||
*
|
||||
* @param loop the event loop instance to attach the event to. Defaults to
|
||||
* {@link CommandScheduler::GetDefaultButtonLoop() the default command
|
||||
* scheduler button loop}.
|
||||
* @return a Trigger instance based around the center position of a POV on the
|
||||
* HID.
|
||||
*/
|
||||
Trigger POVCenter(frc::EventLoop* loop = CommandScheduler::GetInstance()
|
||||
.GetDefaultButtonLoop()) const;
|
||||
|
||||
/**
|
||||
* Constructs a Trigger instance that is true when the axis value is less than
|
||||
* {@code threshold}, attached to {@link
|
||||
* CommandScheduler::GetDefaultButtonLoop() the default command scheduler
|
||||
* button loop}.
|
||||
* @param axis The axis to read, starting at 0.
|
||||
* @param threshold The value below which this trigger should return true.
|
||||
* @param loop the event loop instance to attach the event to. Defaults to
|
||||
* {@link CommandScheduler::GetDefaultButtonLoop() the default command
|
||||
* scheduler button loop}.
|
||||
* @return a Trigger instance that is true when the axis value is less than
|
||||
* the provided threshold.
|
||||
*/
|
||||
Trigger AxisLessThan(
|
||||
int axis, double threshold,
|
||||
frc::EventLoop* loop =
|
||||
CommandScheduler::GetInstance().GetDefaultButtonLoop()) const;
|
||||
|
||||
/**
|
||||
* Constructs a Trigger instance that is true when the axis value is greater
|
||||
* than {@code threshold}, attached to {@link
|
||||
* CommandScheduler::GetDefaultButtonLoop() the default command scheduler
|
||||
* button loop}.
|
||||
* @param axis The axis to read, starting at 0.
|
||||
* @param threshold The value below which this trigger should return true.
|
||||
* @param loop the event loop instance to attach the event to. Defaults to
|
||||
* {@link CommandScheduler::GetDefaultButtonLoop() the default command
|
||||
* scheduler button loop}.
|
||||
* @return a Trigger instance that is true when the axis value is greater than
|
||||
* the provided threshold.
|
||||
*/
|
||||
Trigger AxisGreaterThan(
|
||||
int axis, double threshold,
|
||||
frc::EventLoop* loop =
|
||||
CommandScheduler::GetInstance().GetDefaultButtonLoop()) const;
|
||||
|
||||
/**
|
||||
* Constructs a Trigger instance that is true when the axis magnitude value is
|
||||
* greater than {@code threshold}, attached to the given loop.
|
||||
*
|
||||
* @param axis The axis to read, starting at 0
|
||||
* @param threshold The value above which this trigger should return true.
|
||||
* @param loop the event loop instance to attach the trigger to.
|
||||
* @return a Trigger instance that is true when the axis magnitude value is
|
||||
* greater than the provided threshold.
|
||||
*/
|
||||
Trigger AxisMagnitudeGreaterThan(
|
||||
int axis, double threshold,
|
||||
frc::EventLoop* loop =
|
||||
CommandScheduler::GetInstance().GetDefaultButtonLoop()) const;
|
||||
|
||||
/**
|
||||
* Set the rumble output for the HID.
|
||||
*
|
||||
* The DS currently supports 2 rumble values, left rumble and right rumble.
|
||||
*
|
||||
* @param type Which rumble value to set
|
||||
* @param value The normalized value (0 to 1) to set the rumble to
|
||||
*/
|
||||
void SetRumble(frc::GenericHID::RumbleType type, double value);
|
||||
|
||||
/**
|
||||
* Get if the HID is connected.
|
||||
*
|
||||
* @return true if the HID is connected
|
||||
*/
|
||||
bool IsConnected() const;
|
||||
|
||||
private:
|
||||
frc::GenericHID m_hid;
|
||||
};
|
||||
} // namespace frc2
|
||||
@@ -0,0 +1,78 @@
|
||||
// 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/Joystick.h>
|
||||
|
||||
#include "Trigger.h"
|
||||
#include "frc2/command/CommandScheduler.h"
|
||||
#include "frc2/command/button/CommandGenericHID.h"
|
||||
|
||||
namespace frc2 {
|
||||
/**
|
||||
* A version of {@link frc::Joystick} with {@link Trigger} factories for
|
||||
* command-based.
|
||||
*
|
||||
* @see frc::Joystick
|
||||
*/
|
||||
class CommandJoystick : public CommandGenericHID {
|
||||
public:
|
||||
/**
|
||||
* Construct an instance of a controller.
|
||||
*
|
||||
* @param port The port index on the Driver Station that the controller is
|
||||
* plugged into.
|
||||
*/
|
||||
explicit CommandJoystick(int port);
|
||||
|
||||
/**
|
||||
* Get the underlying GenericHID object.
|
||||
*
|
||||
* @return the wrapped GenericHID object
|
||||
*/
|
||||
frc::Joystick& GetHID();
|
||||
|
||||
/**
|
||||
* Constructs an event instance around the trigger 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 trigger button's digital signal
|
||||
* attached to the given loop.
|
||||
*/
|
||||
class Trigger Trigger(
|
||||
frc::EventLoop* loop =
|
||||
CommandScheduler::GetInstance().GetDefaultButtonLoop()) const;
|
||||
|
||||
/**
|
||||
* Constructs an event instance around the top 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 top button's digital signal
|
||||
* attached to the given loop.
|
||||
*/
|
||||
class Trigger Top(frc::EventLoop* loop = CommandScheduler::GetInstance()
|
||||
.GetDefaultButtonLoop()) const;
|
||||
/**
|
||||
* Get the magnitude of the vector formed by the joystick's
|
||||
* current position relative to its origin.
|
||||
*
|
||||
* @return The magnitude of the direction vector
|
||||
*/
|
||||
double GetMagnitude() const;
|
||||
|
||||
/**
|
||||
* Get the direction of the vector formed by the joystick and its origin. 0 is
|
||||
* forward and clockwise is positive. (Straight right is π/2 radians or 90
|
||||
* degrees.)
|
||||
*
|
||||
* @return The direction of the vector.
|
||||
*/
|
||||
units::radian_t GetDirection() const;
|
||||
|
||||
private:
|
||||
frc::Joystick m_hid;
|
||||
};
|
||||
} // namespace frc2
|
||||
@@ -0,0 +1,32 @@
|
||||
// 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/GenericHID.h>
|
||||
|
||||
#include "Trigger.h"
|
||||
|
||||
namespace frc2 {
|
||||
/**
|
||||
* A class used to bind command scheduling to joystick button presses. Can be
|
||||
* composed with other buttons with the operators in Trigger.
|
||||
*
|
||||
* This class is provided by the NewCommands VendorDep
|
||||
*
|
||||
* @see Trigger
|
||||
*/
|
||||
class JoystickButton : public Trigger {
|
||||
public:
|
||||
/**
|
||||
* Creates a JoystickButton that commands can be bound to.
|
||||
*
|
||||
* @param joystick The joystick on which the button is located.
|
||||
* @param buttonNumber The number of the button on the joystick.
|
||||
*/
|
||||
explicit JoystickButton(frc::GenericHID* joystick, int buttonNumber)
|
||||
: Trigger([joystick, buttonNumber] {
|
||||
return joystick->GetRawButton(buttonNumber);
|
||||
}) {}
|
||||
};
|
||||
} // namespace frc2
|
||||
@@ -0,0 +1,65 @@
|
||||
// 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 <memory>
|
||||
#include <string_view>
|
||||
|
||||
#include <networktables/BooleanTopic.h>
|
||||
#include <networktables/NetworkTable.h>
|
||||
#include <networktables/NetworkTableInstance.h>
|
||||
|
||||
#include "Trigger.h"
|
||||
|
||||
namespace frc2 {
|
||||
/**
|
||||
* A Button that uses a NetworkTable boolean field.
|
||||
*
|
||||
* This class is provided by the NewCommands VendorDep
|
||||
*/
|
||||
class NetworkButton : public Trigger {
|
||||
public:
|
||||
/**
|
||||
* Creates a NetworkButton that commands can be bound to.
|
||||
*
|
||||
* @param topic The boolean topic that contains the value.
|
||||
*/
|
||||
explicit NetworkButton(nt::BooleanTopic topic);
|
||||
|
||||
/**
|
||||
* Creates a NetworkButton that commands can be bound to.
|
||||
*
|
||||
* @param sub The boolean subscriber that provides the value.
|
||||
*/
|
||||
explicit NetworkButton(nt::BooleanSubscriber sub);
|
||||
|
||||
/**
|
||||
* Creates a NetworkButton that commands can be bound to.
|
||||
*
|
||||
* @param table The table where the networktable value is located.
|
||||
* @param field The field that is the value.
|
||||
*/
|
||||
NetworkButton(std::shared_ptr<nt::NetworkTable> table,
|
||||
std::string_view field);
|
||||
|
||||
/**
|
||||
* Creates a NetworkButton that commands can be bound to.
|
||||
*
|
||||
* @param table The table where the networktable value is located.
|
||||
* @param field The field that is the value.
|
||||
*/
|
||||
NetworkButton(std::string_view table, std::string_view field);
|
||||
|
||||
/**
|
||||
* Creates a NetworkButton that commands can be bound to.
|
||||
*
|
||||
* @param inst The NetworkTable instance to use
|
||||
* @param table The table where the networktable value is located.
|
||||
* @param field The field that is the value.
|
||||
*/
|
||||
NetworkButton(nt::NetworkTableInstance inst, std::string_view table,
|
||||
std::string_view field);
|
||||
};
|
||||
} // namespace frc2
|
||||
@@ -0,0 +1,36 @@
|
||||
// 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/DriverStation.h>
|
||||
#include <frc/GenericHID.h>
|
||||
|
||||
#include "Trigger.h"
|
||||
|
||||
namespace frc2 {
|
||||
/**
|
||||
* A class used to bind command scheduling to joystick POV presses. Can be
|
||||
* composed with other buttons with the operators in Trigger.
|
||||
*
|
||||
* This class is provided by the NewCommands VendorDep
|
||||
*
|
||||
* @see Trigger
|
||||
*/
|
||||
class POVButton : public Trigger {
|
||||
public:
|
||||
/**
|
||||
* Creates a POVButton that commands can be bound to.
|
||||
*
|
||||
* @param joystick The joystick on which the button is located.
|
||||
* @param angle The angle of the POV corresponding to a button press.
|
||||
* @param povNumber The number of the POV on the joystick.
|
||||
*/
|
||||
POVButton(frc::GenericHID* joystick, frc::DriverStation::POVDirection angle,
|
||||
int povNumber = 0)
|
||||
: Trigger([joystick, angle, povNumber] {
|
||||
return joystick->GetPOV(povNumber) == angle;
|
||||
}) {}
|
||||
};
|
||||
} // namespace frc2
|
||||
@@ -0,0 +1,50 @@
|
||||
// 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 "frc2/command/button/Trigger.h"
|
||||
|
||||
namespace frc2 {
|
||||
|
||||
/**
|
||||
* A class containing static Trigger factories 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
|
||||
* mode.
|
||||
*/
|
||||
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.
|
||||
*/
|
||||
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.
|
||||
*/
|
||||
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.
|
||||
*/
|
||||
static Trigger Test();
|
||||
};
|
||||
|
||||
} // namespace frc2
|
||||
@@ -0,0 +1,305 @@
|
||||
// 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 <functional>
|
||||
#include <utility>
|
||||
|
||||
#include <frc/event/BooleanEvent.h>
|
||||
#include <frc/event/EventLoop.h>
|
||||
#include <frc/filter/Debouncer.h>
|
||||
#include <units/time.h>
|
||||
#include <wpi/FunctionExtras.h>
|
||||
|
||||
#include "frc2/command/Command.h"
|
||||
#include "frc2/command/CommandScheduler.h"
|
||||
|
||||
namespace frc2 {
|
||||
class Command;
|
||||
/**
|
||||
* This class provides an easy way to link commands to conditions.
|
||||
*
|
||||
* <p>It is very easy to link a button to a command. For instance, you could
|
||||
* link the trigger button of a joystick to a "score" command.
|
||||
*
|
||||
* <p>Triggers can easily be composed for advanced functionality using the
|
||||
* {@link #operator!}, {@link #operator||}, {@link #operator&&} operators.
|
||||
*
|
||||
* <p>This class is provided by the NewCommands VendorDep
|
||||
*/
|
||||
class Trigger {
|
||||
public:
|
||||
/**
|
||||
* Creates a new trigger based on the given condition.
|
||||
*
|
||||
* <p>Polled by the default scheduler button loop.
|
||||
*
|
||||
* @param condition the condition represented by this trigger
|
||||
*/
|
||||
explicit Trigger(std::function<bool()> condition)
|
||||
: Trigger{CommandScheduler::GetInstance().GetDefaultButtonLoop(),
|
||||
std::move(condition)} {}
|
||||
|
||||
/**
|
||||
* Creates a new trigger based on the given condition.
|
||||
*
|
||||
* @param loop The loop instance that polls this trigger.
|
||||
* @param condition the condition represented by this trigger
|
||||
*/
|
||||
Trigger(frc::EventLoop* loop, std::function<bool()> condition)
|
||||
: m_loop{loop}, m_condition{std::move(condition)} {}
|
||||
|
||||
/**
|
||||
* Create a new trigger that is always `false`.
|
||||
*/
|
||||
Trigger() : Trigger([] { return false; }) {}
|
||||
|
||||
Trigger(const Trigger& other);
|
||||
|
||||
/**
|
||||
* Starts the command when the condition changes.
|
||||
*
|
||||
* @param command the command to start
|
||||
* @return this trigger, so calls can be chained
|
||||
*/
|
||||
Trigger OnChange(Command* command);
|
||||
|
||||
/**
|
||||
* Starts the command when the condition changes. Moves command ownership to
|
||||
* the button scheduler.
|
||||
*
|
||||
* @param command the command to start
|
||||
* @return this trigger, so calls can be chained
|
||||
*/
|
||||
Trigger OnChange(CommandPtr&& command);
|
||||
|
||||
/**
|
||||
* Starts the given command whenever the condition changes from `false` to
|
||||
* `true`.
|
||||
*
|
||||
* <p>Takes a raw pointer, and so is non-owning; users are responsible for the
|
||||
* lifespan of the command.
|
||||
*
|
||||
* @param command the command to start
|
||||
* @return this trigger, so calls can be chained
|
||||
*/
|
||||
Trigger OnTrue(Command* command);
|
||||
|
||||
/**
|
||||
* Starts the given command whenever the condition changes from `false` to
|
||||
* `true`. Moves command ownership to the button scheduler.
|
||||
*
|
||||
* @param command The command to bind.
|
||||
* @return The trigger, for chained calls.
|
||||
*/
|
||||
Trigger OnTrue(CommandPtr&& command);
|
||||
|
||||
/**
|
||||
* Starts the given command whenever the condition changes from `true` to
|
||||
* `false`.
|
||||
*
|
||||
* <p>Takes a raw pointer, and so is non-owning; users are responsible for the
|
||||
* lifespan of the command.
|
||||
*
|
||||
* @param command the command to start
|
||||
* @return this trigger, so calls can be chained
|
||||
*/
|
||||
Trigger OnFalse(Command* command);
|
||||
|
||||
/**
|
||||
* Starts the given command whenever the condition changes from `true` to
|
||||
* `false`.
|
||||
*
|
||||
* @param command The command to bind.
|
||||
* @return The trigger, for chained calls.
|
||||
*/
|
||||
Trigger OnFalse(CommandPtr&& command);
|
||||
|
||||
/**
|
||||
* Starts the given command when the condition changes to `true` and cancels
|
||||
* it when the condition changes to `false`.
|
||||
*
|
||||
* <p>Doesn't re-start the command if it ends while the condition is still
|
||||
* `true`. If the command should restart, see RepeatCommand.
|
||||
*
|
||||
* <p>Takes a raw pointer, and so is non-owning; users are responsible for the
|
||||
* lifespan of the command.
|
||||
*
|
||||
* @param command the command to start
|
||||
* @return this trigger, so calls can be chained
|
||||
*/
|
||||
Trigger WhileTrue(Command* command);
|
||||
|
||||
/**
|
||||
* Starts the given command when the condition changes to `true` and cancels
|
||||
* it when the condition changes to `false`. Moves command ownership to the
|
||||
* button scheduler.
|
||||
*
|
||||
* <p>Doesn't re-start the command if it ends while the condition is still
|
||||
* `true`. If the command should restart, see RepeatCommand.
|
||||
*
|
||||
* @param command The command to bind.
|
||||
* @return The trigger, for chained calls.
|
||||
*/
|
||||
Trigger WhileTrue(CommandPtr&& command);
|
||||
|
||||
/**
|
||||
* Starts the given command when the condition changes to `false` and cancels
|
||||
* it when the condition changes to `true`.
|
||||
*
|
||||
* <p>Doesn't re-start the command if it ends while the condition is still
|
||||
* `true`. If the command should restart, see RepeatCommand.
|
||||
*
|
||||
* <p>Takes a raw pointer, and so is non-owning; users are responsible for the
|
||||
* lifespan of the command.
|
||||
*
|
||||
* @param command the command to start
|
||||
* @return this trigger, so calls can be chained
|
||||
*/
|
||||
Trigger WhileFalse(Command* command);
|
||||
|
||||
/**
|
||||
* Starts the given command when the condition changes to `false` and cancels
|
||||
* it when the condition changes to `true`. Moves command ownership to the
|
||||
* button scheduler.
|
||||
*
|
||||
* <p>Doesn't re-start the command if it ends while the condition is still
|
||||
* `false`. If the command should restart, see RepeatCommand.
|
||||
*
|
||||
* @param command The command to bind.
|
||||
* @return The trigger, for chained calls.
|
||||
*/
|
||||
Trigger WhileFalse(CommandPtr&& command);
|
||||
|
||||
/**
|
||||
* Toggles a command when the condition changes from `false` to `true`.
|
||||
*
|
||||
* <p>Takes a raw pointer, and so is non-owning; users are responsible for the
|
||||
* lifespan of the command.
|
||||
*
|
||||
* @param command the command to toggle
|
||||
* @return this trigger, so calls can be chained
|
||||
*/
|
||||
Trigger ToggleOnTrue(Command* command);
|
||||
|
||||
/**
|
||||
* Toggles a command when the condition changes from `false` to `true`.
|
||||
*
|
||||
* <p>Takes a raw pointer, and so is non-owning; users are responsible for the
|
||||
* lifespan of the command.
|
||||
*
|
||||
* @param command the command to toggle
|
||||
* @return this trigger, so calls can be chained
|
||||
*/
|
||||
Trigger ToggleOnTrue(CommandPtr&& command);
|
||||
|
||||
/**
|
||||
* Toggles a command when the condition changes from `true` to the low
|
||||
* state.
|
||||
*
|
||||
* <p>Takes a raw pointer, and so is non-owning; users are responsible for the
|
||||
* lifespan of the command.
|
||||
*
|
||||
* @param command the command to toggle
|
||||
* @return this trigger, so calls can be chained
|
||||
*/
|
||||
Trigger ToggleOnFalse(Command* command);
|
||||
|
||||
/**
|
||||
* Toggles a command when the condition changes from `true` to `false`.
|
||||
*
|
||||
* <p>Takes a raw pointer, and so is non-owning; users are responsible for the
|
||||
* lifespan of the command.
|
||||
*
|
||||
* @param command the command to toggle
|
||||
* @return this trigger, so calls can be chained
|
||||
*/
|
||||
Trigger ToggleOnFalse(CommandPtr&& command);
|
||||
|
||||
/**
|
||||
* Composes two triggers with logical AND.
|
||||
*
|
||||
* @return A trigger which is active when both component triggers are active.
|
||||
*/
|
||||
Trigger operator&&(std::function<bool()> rhs) {
|
||||
return Trigger(m_loop, [condition = m_condition, rhs = std::move(rhs)] {
|
||||
return condition() && rhs();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Composes two triggers with logical AND.
|
||||
*
|
||||
* @return A trigger which is active when both component triggers are active.
|
||||
*/
|
||||
Trigger operator&&(Trigger rhs) {
|
||||
return Trigger(m_loop, [condition = m_condition, rhs] {
|
||||
return condition() && rhs.m_condition();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Composes two triggers with logical OR.
|
||||
*
|
||||
* @return A trigger which is active when either component trigger is active.
|
||||
*/
|
||||
Trigger operator||(std::function<bool()> rhs) {
|
||||
return Trigger(m_loop, [condition = m_condition, rhs = std::move(rhs)] {
|
||||
return condition() || rhs();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Composes two triggers with logical OR.
|
||||
*
|
||||
* @return A trigger which is active when either component trigger is active.
|
||||
*/
|
||||
Trigger operator||(Trigger rhs) {
|
||||
return Trigger(m_loop, [condition = m_condition, rhs] {
|
||||
return condition() || rhs.m_condition();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Composes a trigger with logical NOT.
|
||||
*
|
||||
* @return A trigger which is active when the component trigger is inactive,
|
||||
* and vice-versa.
|
||||
*/
|
||||
Trigger operator!() {
|
||||
return Trigger(m_loop, [condition = m_condition] { return !condition(); });
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new debounced trigger from this trigger - it will become active
|
||||
* when this trigger has been active for longer than the specified period.
|
||||
*
|
||||
* @param debounceTime The debounce period.
|
||||
* @param type The debounce type.
|
||||
* @return The debounced trigger.
|
||||
*/
|
||||
Trigger Debounce(units::second_t debounceTime,
|
||||
frc::Debouncer::DebounceType type =
|
||||
frc::Debouncer::DebounceType::kRising);
|
||||
|
||||
/**
|
||||
* Returns the current state of this trigger.
|
||||
*
|
||||
* @return A bool representing the current state of the trigger.
|
||||
*/
|
||||
bool Get() const;
|
||||
|
||||
private:
|
||||
/**
|
||||
* Adds a binding to the EventLoop.
|
||||
*
|
||||
* @param body The body of the binding to add.
|
||||
*/
|
||||
void AddBinding(wpi::unique_function<void(bool, bool)>&& body);
|
||||
|
||||
frc::EventLoop* m_loop;
|
||||
std::function<bool()> m_condition;
|
||||
};
|
||||
} // namespace frc2
|
||||
Reference in New Issue
Block a user