mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-07-04 03:11:43 +00:00
Add Axis enum in XboxController (#2253)
This commit is contained in:
committed by
Peter Johnson
parent
ab9647ff5b
commit
d4c8ee5915
@@ -1,5 +1,5 @@
|
|||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
/* Copyright (c) 2016-2019 FIRST. All Rights Reserved. */
|
/* Copyright (c) 2016-2020 FIRST. All Rights Reserved. */
|
||||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
/* 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 */
|
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||||
/* the project. */
|
/* the project. */
|
||||||
@@ -17,25 +17,25 @@ XboxController::XboxController(int port) : GenericHID(port) {
|
|||||||
|
|
||||||
double XboxController::GetX(JoystickHand hand) const {
|
double XboxController::GetX(JoystickHand hand) const {
|
||||||
if (hand == kLeftHand) {
|
if (hand == kLeftHand) {
|
||||||
return GetRawAxis(0);
|
return GetRawAxis(static_cast<int>(Axis::kLeftX));
|
||||||
} else {
|
} else {
|
||||||
return GetRawAxis(4);
|
return GetRawAxis(static_cast<int>(Axis::kRightX));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
double XboxController::GetY(JoystickHand hand) const {
|
double XboxController::GetY(JoystickHand hand) const {
|
||||||
if (hand == kLeftHand) {
|
if (hand == kLeftHand) {
|
||||||
return GetRawAxis(1);
|
return GetRawAxis(static_cast<int>(Axis::kLeftY));
|
||||||
} else {
|
} else {
|
||||||
return GetRawAxis(5);
|
return GetRawAxis(static_cast<int>(Axis::kRightY));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
double XboxController::GetTriggerAxis(JoystickHand hand) const {
|
double XboxController::GetTriggerAxis(JoystickHand hand) const {
|
||||||
if (hand == kLeftHand) {
|
if (hand == kLeftHand) {
|
||||||
return GetRawAxis(2);
|
return GetRawAxis(static_cast<int>(Axis::kLeftTrigger));
|
||||||
} else {
|
} else {
|
||||||
return GetRawAxis(3);
|
return GetRawAxis(static_cast<int>(Axis::kRightTrigger));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
/* Copyright (c) 2016-2019 FIRST. All Rights Reserved. */
|
/* Copyright (c) 2016-2020 FIRST. All Rights Reserved. */
|
||||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
/* 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 */
|
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||||
/* the project. */
|
/* the project. */
|
||||||
@@ -244,6 +244,15 @@ class XboxController : public GenericHID {
|
|||||||
kBack = 7,
|
kBack = 7,
|
||||||
kStart = 8
|
kStart = 8
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum class Axis {
|
||||||
|
kLeftX = 0,
|
||||||
|
kRightX = 4,
|
||||||
|
kLeftY = 1,
|
||||||
|
kRightY = 5,
|
||||||
|
kLeftTrigger = 2,
|
||||||
|
kRightTrigger = 3
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace frc
|
} // namespace frc
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
/* Copyright (c) 2016-2019 FIRST. All Rights Reserved. */
|
/* Copyright (c) 2016-2020 FIRST. All Rights Reserved. */
|
||||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
/* 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 */
|
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||||
/* the project. */
|
/* the project. */
|
||||||
@@ -41,6 +41,25 @@ public class XboxController extends GenericHID {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents an axis on an XboxController.
|
||||||
|
*/
|
||||||
|
public enum Axis {
|
||||||
|
kLeftX(0),
|
||||||
|
kRightX(4),
|
||||||
|
kLeftY(1),
|
||||||
|
kRightY(5),
|
||||||
|
kLeftTrigger(2),
|
||||||
|
kRightTrigger(3);
|
||||||
|
|
||||||
|
@SuppressWarnings({"MemberName", "PMD.SingularField"})
|
||||||
|
public final int value;
|
||||||
|
|
||||||
|
Axis(int value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct an instance of a joystick. The joystick index is the USB port on the drivers
|
* Construct an instance of a joystick. The joystick index is the USB port on the drivers
|
||||||
* station.
|
* station.
|
||||||
@@ -62,9 +81,9 @@ public class XboxController extends GenericHID {
|
|||||||
@Override
|
@Override
|
||||||
public double getX(Hand hand) {
|
public double getX(Hand hand) {
|
||||||
if (hand.equals(Hand.kLeft)) {
|
if (hand.equals(Hand.kLeft)) {
|
||||||
return getRawAxis(0);
|
return getRawAxis(Axis.kLeftX.value);
|
||||||
} else {
|
} else {
|
||||||
return getRawAxis(4);
|
return getRawAxis(Axis.kRightX.value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -77,9 +96,9 @@ public class XboxController extends GenericHID {
|
|||||||
@Override
|
@Override
|
||||||
public double getY(Hand hand) {
|
public double getY(Hand hand) {
|
||||||
if (hand.equals(Hand.kLeft)) {
|
if (hand.equals(Hand.kLeft)) {
|
||||||
return getRawAxis(1);
|
return getRawAxis(Axis.kLeftY.value);
|
||||||
} else {
|
} else {
|
||||||
return getRawAxis(5);
|
return getRawAxis(Axis.kRightY.value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -91,9 +110,9 @@ public class XboxController extends GenericHID {
|
|||||||
*/
|
*/
|
||||||
public double getTriggerAxis(Hand hand) {
|
public double getTriggerAxis(Hand hand) {
|
||||||
if (hand.equals(Hand.kLeft)) {
|
if (hand.equals(Hand.kLeft)) {
|
||||||
return getRawAxis(2);
|
return getRawAxis(Axis.kLeftTrigger.value);
|
||||||
} else {
|
} else {
|
||||||
return getRawAxis(3);
|
return getRawAxis(Axis.kRightTrigger.value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user