-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGamepad.java
More file actions
277 lines (232 loc) · 5.58 KB
/
Gamepad.java
File metadata and controls
277 lines (232 loc) · 5.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
package org.scotsbots.robotbase.utils;
import edu.wpi.first.wpilibj.Joystick;
/**
* Replaces WPILib joystick class for easily acessing buttons.
* <strong>Configured for 'D' switch setting on back of controller!</strong>
* <br> Originally adapted from Adambots code.
* @author Nathan Fenner
* @author Domenic Portuesi
*
*/
public class Gamepad
{
public Joystick joystick;
/**
* XBOX 360 West Face Button
*/
private static final int BUTTON_X = 1;
/**
* XBOX 360 South Face Button
*/
private static final int BUTTON_A = 2;
/**
* XBOX 360 East Face Button
*/
private static final int BUTTON_B = 3;
/**
* XBOX 360 North Face Button
*/
private static final int BUTTON_Y = 4;
/**
* XBOX 360 Left Bumper (Top)
*/
private static final int BUTTON_LB = 5;
/**
* XBOX 360 Right Bumper (Top)
*/
private static final int BUTTON_RB = 6; // right bumper top
/**
* XBOX 360 Back Button
*/
private static final int BUTTON_BACK = 9;
/**
* XBOX 360 Start Button
*/
private static final int BUTTON_START = 10;
/**
* XBOX 360 Left Horizontal Axis (Left=-1, Right=1)
*/
private static final int AXIS_LEFT_X = 0;
/**
* XBOX 360 Left Vertical Axis (Up=-1, Down=1)
*/
private static final int AXIS_LEFT_Y = 1;
/**
* XBOX 360 Right Horizontal Axis (Left=-1, Right=1)
*/
private static final int AXIS_RIGHT_X = 2;
/**
* XBOX 360 Right Vertical Axis (Up=-1, Down=1)
*/
private static final int AXIS_RIGHT_Y = 3;
private static final int BUTTON_R3 = 12;
private static final int BUTTON_L3 = 11;
private static final int BUTTON_RT = 8; //Right trigger, bottom
private static final int BUTTON_LT = 7;
private static final int BUTTON_SELECT = 9;
private Gamepad(int port)
{
joystick = new Joystick(port);
}
//HOW THEY ARE NAMED:
//Set1 : PrimaryLeftAttack, PrimaryRightAttack, SecondaryAttack
//set2 : Primary Gamepad, Secondary Gamepad
//Your set of controllers is set when you called tank drive!
//-Domenic
public static Gamepad primaryGamepad = new Gamepad(0);
public static AttackJoystick primaryLeftAttackJoystick = new AttackJoystick(0);
public static AttackJoystick primaryRightAttackJoystick = new AttackJoystick(1);
public static Gamepad secondaryGamepad = new Gamepad(1);
public static Gamepad secondaryAttackJoystick = new Gamepad(2);
public static Object secondaryAttackjoystickget;
/**
* Returns the value of the trigger with a deadzone.
*
* @return
*/
public static double createDeadzone(double triggerValue)
{
return Math.abs(triggerValue) < 0.15 ? 0 : triggerValue;
}
public static double createDeadzoneTrigger(double triggerValue)
{
return Math.abs(triggerValue) < .5 ? 0 : triggerValue;
}
/**
* Corresponds to HORIZONTAL input on the LEFT joystick.
*
* @return The X coordinate of the left joystick (-1 is LEFT, 1 is RIGHT)
*/
public double getLeftX()
{
return createDeadzone(joystick.getRawAxis(AXIS_LEFT_X));
}
/**
* Corresponds to VERTICAL input on the LEFT joystick.
*
* @return The Y coordinate of the LEFT joystick (-1 is UP, 1 is DOWN)
*/
public double getLeftY()
{
return createDeadzone(joystick.getRawAxis(AXIS_LEFT_Y));
}
/**
* Corresponds to HORIZONTAL input on the RIGHT joystick
*
* @return The X coordinate of the RIGHT joystick (-1 is LEFT, 1 is RIGHT)
*/
public double getRightX()
{
return createDeadzone(joystick.getRawAxis(AXIS_RIGHT_X));
}
/**
* Corresponds to VERTICAL input on the RIGHT joystick
*
* @return The Y coordinate of the RIGHT joystick (-1 is UP, 1 is DOWN)
*/
public double getRightY()
{
return createDeadzone(joystick.getRawAxis(AXIS_RIGHT_Y));
}
/*
public double getLeftT()
{
return createDeadzoneTrigger(joystick.getRawAxis(AXIS_LEFT_T));
}
*/
public boolean getLeftT()
{
return joystick.getRawButton(BUTTON_LT);
}
/*
public double getRightT()
{
return createDeadzoneTrigger(joystick.getRawAxis(AXIS_RIGHT_T));
}
*/
public boolean getRightT()
{
return joystick.getRawButton(BUTTON_RT); //right trigger
}
//TODO Fix these
//@Deprecated
public boolean getDPadLeft()
{
return joystick.getPOV() == 270;
//return joystick.getRawAxis(AXIS_DPAD_X) < -0.5;
}
//@Deprecated
public boolean getDPadRight()
{
return joystick.getPOV() == 90;
//return joystick.getRawAxis(AXIS_DPAD_X) > 0.5;
}
//@Deprecated
public boolean getDPadUp()
{
return joystick.getPOV() == 0;
//return joystick.getRawAxis(AXIS_DPAD_Y) < -0.5;
}
//@Deprecated
public boolean getDPadDown()
{
return joystick.getPOV() == 180;
//return joystick.getRawAxis(AXIS_DPAD_Y) > 0.5;
}
/**
*
* @return Is the left bumper pressed? [top one]
*/
public boolean getLB()
{
return joystick.getRawButton(BUTTON_LB);
}
/**
*
* @return Is the right bumper pressed? [top one]
*/
public boolean getRB()
{
return joystick.getRawButton(BUTTON_RB);
}
public boolean getA()
{
return joystick.getRawButton(BUTTON_A);
}
public boolean getB()
{
return joystick.getRawButton(BUTTON_B);
}
public boolean getX()
{
return joystick.getRawButton(BUTTON_X);
}
public boolean getY()
{
return joystick.getRawButton(BUTTON_Y);
}
public boolean getStart()
{
return joystick.getRawButton(BUTTON_START);
}
public boolean getBack()
{
return joystick.getRawButton(BUTTON_BACK);
}
public boolean getR3()
{
return joystick.getRawButton(BUTTON_R3);
}
public boolean getL3()
{
return joystick.getRawButton(BUTTON_L3);
}
public boolean getSelect()
{
return joystick.getRawButton(BUTTON_SELECT);
}
public static boolean secondaryAttackjoystickgetLeftT() {
// TODO Auto-generated method stub
return false;
}
}