mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-07-02 02:51:42 +00:00
Changed joystick port numbers to be zero-based for C++ and Java.
Change-Id: Ifd55e8654be3b15abbe7460d2e9e6fff8acd9977
This commit is contained in:
@@ -19,7 +19,7 @@ OI::OI() {
|
||||
SmartDashboard::PutData("Open Claw", new OpenClaw());
|
||||
SmartDashboard::PutData("Close Claw", new CloseClaw());
|
||||
|
||||
joy= new Joystick(1);
|
||||
joy= new Joystick(0);
|
||||
|
||||
|
||||
// Create some buttons
|
||||
|
||||
@@ -11,7 +11,7 @@ class Robot: public IterativeRobot
|
||||
public:
|
||||
Robot() :
|
||||
myRobot(0, 1), // these must be initialized in the same order
|
||||
stick(1), // as they are declared above.
|
||||
stick(0), // as they are declared above.
|
||||
lw(NULL),
|
||||
autoLoopCounter(0)
|
||||
{
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
#include "Commands/SetCollectionSpeed.h"
|
||||
|
||||
OI::OI() {
|
||||
joystick = new Joystick(1);
|
||||
joystick = new Joystick(0);
|
||||
|
||||
R1 = new JoystickButton(joystick, 12);
|
||||
R1->WhenPressed(new LowGoal());
|
||||
|
||||
@@ -18,7 +18,7 @@ class Robot: public SampleRobot
|
||||
public:
|
||||
Robot() :
|
||||
myRobot(0, 1), // these must be initialized in the same order
|
||||
stick(1) // as they are declared above.
|
||||
stick(0) // as they are declared above.
|
||||
{
|
||||
myRobot.SetExpiration(0.1);
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
|
||||
* interface to the commands and command groups that allow control of the robot.
|
||||
*/
|
||||
public class OI {
|
||||
private Joystick joy = new Joystick(1);
|
||||
private Joystick joy = new Joystick(0);
|
||||
|
||||
public OI() {
|
||||
// Put Some buttons on the SmartDashboard
|
||||
|
||||
@@ -23,7 +23,7 @@ public class Robot extends IterativeRobot {
|
||||
*/
|
||||
public void robotInit() {
|
||||
myRobot = new RobotDrive(0,1);
|
||||
stick = new Joystick(1);
|
||||
stick = new Joystick(0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -23,7 +23,7 @@ public class OI {
|
||||
public Joystick joystick;
|
||||
|
||||
public OI() {
|
||||
joystick = new Joystick(1);
|
||||
joystick = new Joystick(0);
|
||||
|
||||
new JoystickButton(joystick, 12).whenPressed(new LowGoal());
|
||||
new JoystickButton(joystick, 10).whenPressed(new Collect());
|
||||
|
||||
@@ -30,7 +30,7 @@ public class Robot extends SampleRobot {
|
||||
public Robot() {
|
||||
myRobot = new RobotDrive(0, 1);
|
||||
myRobot.setExpiration(0.1);
|
||||
stick = new Joystick(1);
|
||||
stick = new Joystick(0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -179,7 +179,7 @@ float DriverStation::GetBatteryVoltage()
|
||||
*/
|
||||
float DriverStation::GetStickAxis(uint32_t stick, uint32_t axis)
|
||||
{
|
||||
if (stick < 1 || stick > kJoystickPorts)
|
||||
if (stick >= kJoystickPorts)
|
||||
{
|
||||
wpi_setWPIError(BadJoystickIndex);
|
||||
return 0;
|
||||
@@ -191,7 +191,7 @@ float DriverStation::GetStickAxis(uint32_t stick, uint32_t axis)
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
int8_t value = m_joystickAxes[stick - 1].axes[axis - 1];
|
||||
int8_t value = m_joystickAxes[stick].axes[axis - 1];
|
||||
|
||||
if(value < 0)
|
||||
{
|
||||
@@ -212,13 +212,13 @@ float DriverStation::GetStickAxis(uint32_t stick, uint32_t axis)
|
||||
*/
|
||||
short DriverStation::GetStickButtons(uint32_t stick)
|
||||
{
|
||||
if (stick < 1 || stick > kJoystickPorts)
|
||||
if (stick >= kJoystickPorts)
|
||||
{
|
||||
wpi_setWPIError(BadJoystickIndex);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return m_joystickButtons[stick - 1];
|
||||
return m_joystickButtons[stick];
|
||||
}
|
||||
|
||||
bool DriverStation::IsEnabled()
|
||||
|
||||
@@ -73,8 +73,12 @@ void Joystick::InitJoystick(uint32_t numAxisTypes, uint32_t numButtonTypes)
|
||||
joysticks[i] = NULL;
|
||||
joySticksInitialized = true;
|
||||
}
|
||||
joysticks[m_port - 1] = this;
|
||||
|
||||
if (m_port >= DriverStation::kJoystickPorts) {
|
||||
wpi_setWPIError(BadJoystickIndex);
|
||||
} else {
|
||||
joysticks[m_port] = this;
|
||||
}
|
||||
|
||||
m_ds = DriverStation::GetInstance();
|
||||
m_axes = new uint32_t[numAxisTypes];
|
||||
m_buttons = new uint32_t[numButtonTypes];
|
||||
@@ -82,11 +86,11 @@ void Joystick::InitJoystick(uint32_t numAxisTypes, uint32_t numButtonTypes)
|
||||
|
||||
Joystick * Joystick::GetStickForPort(uint32_t port)
|
||||
{
|
||||
Joystick *stick = joysticks[port - 1];
|
||||
Joystick *stick = joysticks[port];
|
||||
if (stick == NULL)
|
||||
{
|
||||
stick = new Joystick(port);
|
||||
joysticks[port - 1] = stick;
|
||||
joysticks[port] = stick;
|
||||
}
|
||||
return stick;
|
||||
}
|
||||
|
||||
@@ -224,15 +224,15 @@ public class DriverStation implements RobotState.Interface {
|
||||
* @return The value of the axis on the joystick.
|
||||
*/
|
||||
public double getStickAxis(int stick, int axis) {
|
||||
if(stick < 1 || stick > kJoystickPorts) {
|
||||
throw new RuntimeException("Joystick index is out of range, should be 1-4");
|
||||
if(stick < 0 || stick >= kJoystickPorts) {
|
||||
throw new RuntimeException("Joystick index is out of range, should be 0-3");
|
||||
}
|
||||
|
||||
if (axis < 1 || axis > kJoystickAxes) {
|
||||
throw new RuntimeException("Joystick axis is out of range");
|
||||
}
|
||||
|
||||
byte value = (byte)m_joystickAxes[stick - 1][axis - 1];
|
||||
byte value = (byte)m_joystickAxes[stick][axis - 1];
|
||||
|
||||
if(value < 0) {
|
||||
return value / 128.0;
|
||||
@@ -249,11 +249,11 @@ public class DriverStation implements RobotState.Interface {
|
||||
* @return The state of the buttons on the joystick.
|
||||
*/
|
||||
public int getStickButtons(final int stick) {
|
||||
if(stick < 1 || stick > kJoystickPorts) {
|
||||
throw new RuntimeException("Joystick index is out of range, should be 1-4");
|
||||
if(stick < 0 || stick >= kJoystickPorts) {
|
||||
throw new RuntimeException("Joystick index is out of range, should be 0-3");
|
||||
}
|
||||
|
||||
return (int)m_joystickButtons[stick - 1];
|
||||
return (int)m_joystickButtons[stick];
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user