2016-11-18 23:05:37 -08:00
|
|
|
/*----------------------------------------------------------------------------*/
|
2019-08-17 01:21:49 -04:00
|
|
|
/* Copyright (c) 2016-2019 FIRST. All Rights Reserved. */
|
2016-11-18 23:05:37 -08:00
|
|
|
/* 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. */
|
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
2018-07-20 00:03:45 -07:00
|
|
|
#include "frc/GenericHID.h"
|
2016-11-18 23:05:37 -08:00
|
|
|
|
|
|
|
|
namespace frc {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Handle input from Xbox 360 or Xbox One controllers connected to the Driver
|
|
|
|
|
* Station.
|
|
|
|
|
*
|
|
|
|
|
* This class handles Xbox input that comes from the Driver Station. Each time a
|
2017-10-27 21:45:56 -07:00
|
|
|
* value is requested the most recent value is returned. There is a single class
|
2016-11-18 23:05:37 -08:00
|
|
|
* instance for each controller and the mapping of ports to hardware buttons
|
|
|
|
|
* depends on the code in the Driver Station.
|
|
|
|
|
*/
|
2017-10-27 21:45:56 -07:00
|
|
|
class XboxController : public GenericHID {
|
2016-11-18 23:05:37 -08:00
|
|
|
public:
|
2018-05-31 20:47:15 -07:00
|
|
|
/**
|
|
|
|
|
* Construct an instance of an Xbox controller.
|
|
|
|
|
*
|
|
|
|
|
* The controller index is the USB port on the Driver Station.
|
|
|
|
|
*
|
|
|
|
|
* @param port The port on the Driver Station that the controller is plugged
|
|
|
|
|
* into (0-5).
|
|
|
|
|
*/
|
2016-11-18 23:05:37 -08:00
|
|
|
explicit XboxController(int port);
|
2018-05-31 20:47:15 -07:00
|
|
|
|
2016-11-18 23:05:37 -08:00
|
|
|
virtual ~XboxController() = default;
|
|
|
|
|
|
2018-09-24 00:08:25 -07:00
|
|
|
XboxController(XboxController&&) = default;
|
|
|
|
|
XboxController& operator=(XboxController&&) = default;
|
2016-11-18 23:05:37 -08:00
|
|
|
|
2018-05-31 20:47:15 -07:00
|
|
|
/**
|
|
|
|
|
* Get the X axis value of the controller.
|
|
|
|
|
*
|
|
|
|
|
* @param hand Side of controller whose value should be returned.
|
|
|
|
|
*/
|
2016-11-20 07:25:03 -08:00
|
|
|
double GetX(JoystickHand hand) const override;
|
2018-05-31 20:47:15 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the Y axis value of the controller.
|
|
|
|
|
*
|
|
|
|
|
* @param hand Side of controller whose value should be returned.
|
|
|
|
|
*/
|
2016-11-20 07:25:03 -08:00
|
|
|
double GetY(JoystickHand hand) const override;
|
2018-05-31 20:47:15 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the trigger axis value of the controller.
|
|
|
|
|
*
|
|
|
|
|
* @param hand Side of controller whose value should be returned.
|
|
|
|
|
*/
|
2017-10-27 21:45:56 -07:00
|
|
|
double GetTriggerAxis(JoystickHand hand) const;
|
2016-11-18 23:05:37 -08:00
|
|
|
|
2018-05-31 20:47:15 -07:00
|
|
|
/**
|
|
|
|
|
* Read the value of the bumper button on the controller.
|
|
|
|
|
*
|
|
|
|
|
* @param hand Side of controller whose value should be returned.
|
|
|
|
|
*/
|
2017-10-27 21:45:56 -07:00
|
|
|
bool GetBumper(JoystickHand hand) const;
|
2018-05-31 20:47:15 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Whether the bumper was pressed since the last check.
|
|
|
|
|
*
|
|
|
|
|
* @param hand Side of controller whose value should be returned.
|
|
|
|
|
* @return Whether the button was pressed since the last check.
|
|
|
|
|
*/
|
2017-10-27 21:45:56 -07:00
|
|
|
bool GetBumperPressed(JoystickHand hand);
|
2018-05-31 20:47:15 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Whether the bumper was released since the last check.
|
|
|
|
|
*
|
|
|
|
|
* @param hand Side of controller whose value should be returned.
|
|
|
|
|
* @return Whether the button was released since the last check.
|
|
|
|
|
*/
|
2017-10-27 21:45:56 -07:00
|
|
|
bool GetBumperReleased(JoystickHand hand);
|
2016-11-18 23:05:37 -08:00
|
|
|
|
2018-05-31 20:47:15 -07:00
|
|
|
/**
|
|
|
|
|
* Read the value of the stick button on the controller.
|
|
|
|
|
*
|
|
|
|
|
* @param hand Side of controller whose value should be returned.
|
|
|
|
|
* @return The state of the button.
|
|
|
|
|
*/
|
2017-10-27 21:45:56 -07:00
|
|
|
bool GetStickButton(JoystickHand hand) const;
|
2018-05-31 20:47:15 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Whether the stick button was pressed since the last check.
|
|
|
|
|
*
|
|
|
|
|
* @param hand Side of controller whose value should be returned.
|
|
|
|
|
* @return Whether the button was pressed since the last check.
|
|
|
|
|
*/
|
2017-10-27 21:45:56 -07:00
|
|
|
bool GetStickButtonPressed(JoystickHand hand);
|
2018-05-31 20:47:15 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Whether the stick button was released since the last check.
|
|
|
|
|
*
|
|
|
|
|
* @param hand Side of controller whose value should be returned.
|
|
|
|
|
* @return Whether the button was released since the last check.
|
|
|
|
|
*/
|
2017-10-27 21:45:56 -07:00
|
|
|
bool GetStickButtonReleased(JoystickHand hand);
|
2016-11-18 23:05:37 -08:00
|
|
|
|
2018-05-31 20:47:15 -07:00
|
|
|
/**
|
|
|
|
|
* Read the value of the A button on the controller.
|
|
|
|
|
*
|
|
|
|
|
* @return The state of the button.
|
|
|
|
|
*/
|
2016-11-18 23:05:37 -08:00
|
|
|
bool GetAButton() const;
|
2018-05-31 20:47:15 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Whether the A button was pressed since the last check.
|
|
|
|
|
*
|
|
|
|
|
* @return Whether the button was pressed since the last check.
|
|
|
|
|
*/
|
2017-10-27 21:45:56 -07:00
|
|
|
bool GetAButtonPressed();
|
2018-05-31 20:47:15 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Whether the A button was released since the last check.
|
|
|
|
|
*
|
|
|
|
|
* @return Whether the button was released since the last check.
|
|
|
|
|
*/
|
2017-10-27 21:45:56 -07:00
|
|
|
bool GetAButtonReleased();
|
|
|
|
|
|
2018-05-31 20:47:15 -07:00
|
|
|
/**
|
|
|
|
|
* Read the value of the B button on the controller.
|
|
|
|
|
*
|
|
|
|
|
* @return The state of the button.
|
|
|
|
|
*/
|
2016-11-18 23:05:37 -08:00
|
|
|
bool GetBButton() const;
|
2018-05-31 20:47:15 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Whether the B button was pressed since the last check.
|
|
|
|
|
*
|
|
|
|
|
* @return Whether the button was pressed since the last check.
|
|
|
|
|
*/
|
2017-10-27 21:45:56 -07:00
|
|
|
bool GetBButtonPressed();
|
2018-05-31 20:47:15 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Whether the B button was released since the last check.
|
|
|
|
|
*
|
|
|
|
|
* @return Whether the button was released since the last check.
|
|
|
|
|
*/
|
2017-10-27 21:45:56 -07:00
|
|
|
bool GetBButtonReleased();
|
|
|
|
|
|
2018-05-31 20:47:15 -07:00
|
|
|
/**
|
|
|
|
|
* Read the value of the X button on the controller.
|
|
|
|
|
*
|
|
|
|
|
* @return The state of the button.
|
|
|
|
|
*/
|
2016-11-18 23:05:37 -08:00
|
|
|
bool GetXButton() const;
|
2018-05-31 20:47:15 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Whether the X button was pressed since the last check.
|
|
|
|
|
*
|
|
|
|
|
* @return Whether the button was pressed since the last check.
|
|
|
|
|
*/
|
2017-10-27 21:45:56 -07:00
|
|
|
bool GetXButtonPressed();
|
2018-05-31 20:47:15 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Whether the X button was released since the last check.
|
|
|
|
|
*
|
|
|
|
|
* @return Whether the button was released since the last check.
|
|
|
|
|
*/
|
2017-10-27 21:45:56 -07:00
|
|
|
bool GetXButtonReleased();
|
|
|
|
|
|
2018-05-31 20:47:15 -07:00
|
|
|
/**
|
|
|
|
|
* Read the value of the Y button on the controller.
|
|
|
|
|
*
|
|
|
|
|
* @return The state of the button.
|
|
|
|
|
*/
|
2016-11-18 23:05:37 -08:00
|
|
|
bool GetYButton() const;
|
2018-05-31 20:47:15 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Whether the Y button was pressed since the last check.
|
|
|
|
|
*
|
|
|
|
|
* @return Whether the button was pressed since the last check.
|
|
|
|
|
*/
|
2017-10-27 21:45:56 -07:00
|
|
|
bool GetYButtonPressed();
|
2018-05-31 20:47:15 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Whether the Y button was released since the last check.
|
|
|
|
|
*
|
|
|
|
|
* @return Whether the button was released since the last check.
|
|
|
|
|
*/
|
2017-10-27 21:45:56 -07:00
|
|
|
bool GetYButtonReleased();
|
|
|
|
|
|
2018-05-31 20:47:15 -07:00
|
|
|
/**
|
|
|
|
|
* Whether the Y button was released since the last check.
|
|
|
|
|
*
|
|
|
|
|
* @return Whether the button was released since the last check.
|
|
|
|
|
*/
|
2016-11-18 23:05:37 -08:00
|
|
|
bool GetBackButton() const;
|
2018-05-31 20:47:15 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Whether the back button was pressed since the last check.
|
|
|
|
|
*
|
|
|
|
|
* @return Whether the button was pressed since the last check.
|
|
|
|
|
*/
|
2017-10-27 21:45:56 -07:00
|
|
|
bool GetBackButtonPressed();
|
2018-05-31 20:47:15 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Whether the back button was released since the last check.
|
|
|
|
|
*
|
|
|
|
|
* @return Whether the button was released since the last check.
|
|
|
|
|
*/
|
2017-10-27 21:45:56 -07:00
|
|
|
bool GetBackButtonReleased();
|
|
|
|
|
|
2018-05-31 20:47:15 -07:00
|
|
|
/**
|
|
|
|
|
* Read the value of the start button on the controller.
|
|
|
|
|
*
|
|
|
|
|
* @param hand Side of controller whose value should be returned.
|
|
|
|
|
* @return The state of the button.
|
|
|
|
|
*/
|
2016-11-18 23:05:37 -08:00
|
|
|
bool GetStartButton() const;
|
2018-05-31 20:47:15 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Whether the start button was pressed since the last check.
|
|
|
|
|
*
|
|
|
|
|
* @return Whether the button was pressed since the last check.
|
|
|
|
|
*/
|
2017-10-27 21:45:56 -07:00
|
|
|
bool GetStartButtonPressed();
|
2018-05-31 20:47:15 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Whether the start button was released since the last check.
|
|
|
|
|
*
|
|
|
|
|
* @return Whether the button was released since the last check.
|
|
|
|
|
*/
|
2017-10-27 21:45:56 -07:00
|
|
|
bool GetStartButtonReleased();
|
2016-11-18 23:05:37 -08:00
|
|
|
|
2017-10-27 21:45:56 -07:00
|
|
|
enum class Button {
|
|
|
|
|
kBumperLeft = 5,
|
|
|
|
|
kBumperRight = 6,
|
|
|
|
|
kStickLeft = 9,
|
|
|
|
|
kStickRight = 10,
|
|
|
|
|
kA = 1,
|
|
|
|
|
kB = 2,
|
|
|
|
|
kX = 3,
|
|
|
|
|
kY = 4,
|
|
|
|
|
kBack = 7,
|
|
|
|
|
kStart = 8
|
|
|
|
|
};
|
2016-11-18 23:05:37 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace frc
|