2016-11-18 23:05:37 -08:00
|
|
|
/*----------------------------------------------------------------------------*/
|
2019-10-29 21:34:10 -07: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. */
|
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
|
2018-07-20 00:03:45 -07:00
|
|
|
#include "frc/XboxController.h"
|
2016-11-18 23:05:37 -08:00
|
|
|
|
2018-07-20 00:03:45 -07:00
|
|
|
#include <hal/HAL.h>
|
2017-08-27 00:11:52 -07:00
|
|
|
|
2016-11-18 23:05:37 -08:00
|
|
|
using namespace frc;
|
|
|
|
|
|
2017-10-27 21:45:56 -07:00
|
|
|
XboxController::XboxController(int port) : GenericHID(port) {
|
2019-10-29 21:34:10 -07:00
|
|
|
HAL_Report(HALUsageReporting::kResourceType_XboxController, port + 1);
|
2016-11-18 23:05:37 -08:00
|
|
|
}
|
|
|
|
|
|
2016-11-20 07:25:03 -08:00
|
|
|
double XboxController::GetX(JoystickHand hand) const {
|
2016-11-18 23:05:37 -08:00
|
|
|
if (hand == kLeftHand) {
|
|
|
|
|
return GetRawAxis(0);
|
|
|
|
|
} else {
|
|
|
|
|
return GetRawAxis(4);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-20 07:25:03 -08:00
|
|
|
double XboxController::GetY(JoystickHand hand) const {
|
2016-11-18 23:05:37 -08:00
|
|
|
if (hand == kLeftHand) {
|
|
|
|
|
return GetRawAxis(1);
|
|
|
|
|
} else {
|
|
|
|
|
return GetRawAxis(5);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-27 21:45:56 -07:00
|
|
|
double XboxController::GetTriggerAxis(JoystickHand hand) const {
|
|
|
|
|
if (hand == kLeftHand) {
|
|
|
|
|
return GetRawAxis(2);
|
|
|
|
|
} else {
|
|
|
|
|
return GetRawAxis(3);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-18 23:05:37 -08:00
|
|
|
bool XboxController::GetBumper(JoystickHand hand) const {
|
|
|
|
|
if (hand == kLeftHand) {
|
2017-10-27 21:45:56 -07:00
|
|
|
return GetRawButton(static_cast<int>(Button::kBumperLeft));
|
|
|
|
|
} else {
|
|
|
|
|
return GetRawButton(static_cast<int>(Button::kBumperRight));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool XboxController::GetBumperPressed(JoystickHand hand) {
|
|
|
|
|
if (hand == kLeftHand) {
|
|
|
|
|
return GetRawButtonPressed(static_cast<int>(Button::kBumperLeft));
|
|
|
|
|
} else {
|
|
|
|
|
return GetRawButtonPressed(static_cast<int>(Button::kBumperRight));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool XboxController::GetBumperReleased(JoystickHand hand) {
|
|
|
|
|
if (hand == kLeftHand) {
|
|
|
|
|
return GetRawButtonReleased(static_cast<int>(Button::kBumperLeft));
|
2016-11-18 23:05:37 -08:00
|
|
|
} else {
|
2017-10-27 21:45:56 -07:00
|
|
|
return GetRawButtonReleased(static_cast<int>(Button::kBumperRight));
|
2016-11-18 23:05:37 -08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool XboxController::GetStickButton(JoystickHand hand) const {
|
|
|
|
|
if (hand == kLeftHand) {
|
2017-10-27 21:45:56 -07:00
|
|
|
return GetRawButton(static_cast<int>(Button::kStickLeft));
|
2016-11-18 23:05:37 -08:00
|
|
|
} else {
|
2017-10-27 21:45:56 -07:00
|
|
|
return GetRawButton(static_cast<int>(Button::kStickRight));
|
2016-11-18 23:05:37 -08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-27 21:45:56 -07:00
|
|
|
bool XboxController::GetStickButtonPressed(JoystickHand hand) {
|
2016-11-18 23:05:37 -08:00
|
|
|
if (hand == kLeftHand) {
|
2017-10-27 21:45:56 -07:00
|
|
|
return GetRawButtonPressed(static_cast<int>(Button::kStickLeft));
|
2016-11-18 23:05:37 -08:00
|
|
|
} else {
|
2017-10-27 21:45:56 -07:00
|
|
|
return GetRawButtonPressed(static_cast<int>(Button::kStickRight));
|
2016-11-18 23:05:37 -08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-27 21:45:56 -07:00
|
|
|
bool XboxController::GetStickButtonReleased(JoystickHand hand) {
|
|
|
|
|
if (hand == kLeftHand) {
|
|
|
|
|
return GetRawButtonReleased(static_cast<int>(Button::kStickLeft));
|
|
|
|
|
} else {
|
|
|
|
|
return GetRawButtonReleased(static_cast<int>(Button::kStickRight));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool XboxController::GetAButton() const {
|
|
|
|
|
return GetRawButton(static_cast<int>(Button::kA));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool XboxController::GetAButtonPressed() {
|
|
|
|
|
return GetRawButtonPressed(static_cast<int>(Button::kA));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool XboxController::GetAButtonReleased() {
|
|
|
|
|
return GetRawButtonReleased(static_cast<int>(Button::kA));
|
|
|
|
|
}
|
2016-11-18 23:05:37 -08:00
|
|
|
|
2017-10-27 21:45:56 -07:00
|
|
|
bool XboxController::GetBButton() const {
|
|
|
|
|
return GetRawButton(static_cast<int>(Button::kB));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool XboxController::GetBButtonPressed() {
|
|
|
|
|
return GetRawButtonPressed(static_cast<int>(Button::kB));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool XboxController::GetBButtonReleased() {
|
|
|
|
|
return GetRawButtonReleased(static_cast<int>(Button::kB));
|
|
|
|
|
}
|
2016-11-18 23:05:37 -08:00
|
|
|
|
2017-10-27 21:45:56 -07:00
|
|
|
bool XboxController::GetXButton() const {
|
|
|
|
|
return GetRawButton(static_cast<int>(Button::kX));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool XboxController::GetXButtonPressed() {
|
|
|
|
|
return GetRawButtonPressed(static_cast<int>(Button::kX));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool XboxController::GetXButtonReleased() {
|
|
|
|
|
return GetRawButtonReleased(static_cast<int>(Button::kX));
|
|
|
|
|
}
|
2016-11-18 23:05:37 -08:00
|
|
|
|
2017-10-27 21:45:56 -07:00
|
|
|
bool XboxController::GetYButton() const {
|
|
|
|
|
return GetRawButton(static_cast<int>(Button::kY));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool XboxController::GetYButtonPressed() {
|
|
|
|
|
return GetRawButtonPressed(static_cast<int>(Button::kY));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool XboxController::GetYButtonReleased() {
|
|
|
|
|
return GetRawButtonReleased(static_cast<int>(Button::kY));
|
|
|
|
|
}
|
2016-11-18 23:05:37 -08:00
|
|
|
|
2017-10-27 21:45:56 -07:00
|
|
|
bool XboxController::GetBackButton() const {
|
|
|
|
|
return GetRawButton(static_cast<int>(Button::kBack));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool XboxController::GetBackButtonPressed() {
|
|
|
|
|
return GetRawButtonPressed(static_cast<int>(Button::kBack));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool XboxController::GetBackButtonReleased() {
|
|
|
|
|
return GetRawButtonReleased(static_cast<int>(Button::kBack));
|
|
|
|
|
}
|
2016-11-18 23:05:37 -08:00
|
|
|
|
2017-10-27 21:45:56 -07:00
|
|
|
bool XboxController::GetStartButton() const {
|
|
|
|
|
return GetRawButton(static_cast<int>(Button::kStart));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool XboxController::GetStartButtonPressed() {
|
|
|
|
|
return GetRawButtonPressed(static_cast<int>(Button::kStart));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool XboxController::GetStartButtonReleased() {
|
|
|
|
|
return GetRawButtonReleased(static_cast<int>(Button::kStart));
|
|
|
|
|
}
|