-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVirtualGamepad.java
More file actions
235 lines (228 loc) · 9.15 KB
/
Copy pathVirtualGamepad.java
File metadata and controls
235 lines (228 loc) · 9.15 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
package com.walnuthillseagles.walnutlibrary;
import com.qualcomm.robotcore.eventloop.opmode.OpMode;
import com.qualcomm.robotcore.hardware.Gamepad;
/**
* Created by Yan Vologzhanin on 2/7/2016.
*/
public class VirtualGamepad implements Runnable{
public static boolean canProcess = false;
public static double[] doubleValues = new double[12];
public static boolean[] boolValues = new boolean[30];
public Gamepad gamepad1Pointer;
public Gamepad gamepad2Pointer;
public OpMode currentOpMode;
/*The array is initilized as follows:
----------------------------------------------
-Analog
0 - Gamepad 1, X axis, left stick (LEFTX1)
1 - Gamepad 1, Y axis, left stick (LEFTY1)
2 - Gamepad 1, X axis, right stick (RIGHTX1)
3 - Gamepad 1, Y axis, right stick (RIGHTY1)
4 - Gamepad 1, Left Trigger (LEFTZ1)
5 - Gamepad 1, Right Trigger (RIGHTZ1)
6 - Gamepad 2, X axis, left stick (LEFTX2)
7 - Gamepad 2, Y axis, left stick (LEFTY2)
8 - Gamepad 2, X axis, right stick (RIGHTX2)
9 - Gamepad 2, Y axis, right stick (RIGHTY2)
10 - Gamepad 2, Left Trigger (LEFTZ2)
11 - Gamepad 2, Right Trigger (RIGHTZ2)
-Digital
0 - Gamepad 1, a button (A1)
1 - Gamepad 1, b button (B1)
2- Gamepad 1, x button (X1)
3- Gamepad 1, y button (Y1)
4 - Gamepad 1, back button (BACK1)
5 - Gamepad 1, start button (START1)
6 - Gamepad 1, guid button (GUIDE1)
7 - Gamepad 1, dpad left (LEFT1)
8 - Gamepad 1, dpad right (RIGHT1)
9 - Gamepad 1, dpad down (DOWN1)
10 - Gamepad 1, dpad up (UP1)
11 - Gamepad 1, Left bumper (LBUMP1)
12 - Gamepad 1, right bumper (RBUMP1)
13 - Gamepad 1, left stick button (LSTICK1)
14 - Gamepad 1, right stick button (RSTICK1)
15 - Gamepad 2, a button (A2)
16 - Gamepad 2, b button (B2)
17- Gamepad 2, x button (X2)
18- Gamepad 2, y button (Y2)
19 - Gamepad 2, back button (BACK2)
20- Gamepad 2, start button (START2)
21- Gamepad 2, guid button (GUIDE2)
22- Gamepad 2, dpad left (LEFT2)
23- Gamepad 2, dpad right (RIGHT2)
24- Gamepad 2, dpad down (DOWN2)
25 - Gamepad 2, dpad up (UP2)
26 - Gamepad 2, Left bumper (LBUMP2)
27 - Gamepad 2, right bumper (RBUMP2)
28 - Gamepad 2, left stick button (LSTICK2)
29 - Gamepad 2, right stick button (RSTICK2)
---------------------------------------------*/
private void setGamepads(Gamepad newGamepad1, Gamepad newGamepad2){
gamepad1Pointer=newGamepad1;
gamepad2Pointer=newGamepad2;
}
//Method that starts at thread and updates neccesary parts
public void run() {
canProcess = true;
//Will loop and update values until told to fullStop
while (canProcess) {
//Analog Values
doubleValues[0] = gamepad1Pointer.left_stick_x;
doubleValues[1] = gamepad1Pointer.left_stick_y;
doubleValues[2] = gamepad1Pointer.right_stick_x;
doubleValues[3] = gamepad1Pointer.right_stick_y;
doubleValues[4] = gamepad1Pointer.left_trigger;
doubleValues[5] = gamepad1Pointer.right_trigger;
doubleValues[6] = gamepad2Pointer.left_stick_x;
doubleValues[7] = gamepad2Pointer.left_stick_y;
doubleValues[8] = gamepad2Pointer.right_stick_x;
doubleValues[9] = gamepad2Pointer.right_stick_y;
doubleValues[10] = gamepad2Pointer.left_trigger;
doubleValues[11] = gamepad2Pointer.right_trigger;
//Digital Values
boolValues[0] = gamepad1Pointer.a;
boolValues[1] = gamepad1Pointer.b;
boolValues[2] = gamepad1Pointer.x;
boolValues[3] = gamepad1Pointer.y;
boolValues[4] = gamepad1Pointer.back;
boolValues[5] = gamepad1Pointer.start;
boolValues[6] = gamepad1Pointer.guide;
boolValues[7] = gamepad1Pointer.dpad_left;
boolValues[8] = gamepad1Pointer.dpad_right;
boolValues[9] = gamepad1Pointer.dpad_down;
boolValues[10] = gamepad1Pointer.dpad_up;
boolValues[11] = gamepad1Pointer.left_bumper;
boolValues[12] = gamepad1Pointer.right_bumper;
boolValues[13] = gamepad1Pointer.left_stick_button;
boolValues[14] = gamepad1Pointer.right_stick_button;
boolValues[15] = gamepad2Pointer.a;
boolValues[16] = gamepad2Pointer.b;
boolValues[17] = gamepad2Pointer.x;
boolValues[18] = gamepad2Pointer.y;
boolValues[19] = gamepad2Pointer.back;
boolValues[20] = gamepad2Pointer.start;
boolValues[21] = gamepad2Pointer.guide;
boolValues[22] = gamepad2Pointer.dpad_left;
boolValues[23] = gamepad2Pointer.dpad_right;
boolValues[24] = gamepad2Pointer.dpad_down;
boolValues[25] = gamepad2Pointer.dpad_up;
boolValues[26] = gamepad2Pointer.left_bumper;
boolValues[27] = gamepad2Pointer.right_bumper;
boolValues[28] = gamepad2Pointer.left_stick_button;
boolValues[29] = gamepad2Pointer.right_stick_button;
}
}
//Called by elsewhere in the program to terminate processing
public static void stopProcessing(){
canProcess = false;
}
public static void startProcessing(OpMode myOpmode){
VirtualGamepad updater = new VirtualGamepad();
Thread processor = new Thread(updater);
updater.setGamepads(myOpmode.gamepad1, myOpmode.gamepad2);
processor.start();
}
//@TODO Figure out how to handle default Case
//@TODO Figure out how to handle nonstatic context
public double getDoubleTableVal(int index){
switch(index){
//-----------------GamePad1-------------------------//
case(0):
return gamepad1Pointer.left_stick_x;
case(1):
return gamepad1Pointer.left_stick_y;
case(2):
return gamepad1Pointer.right_stick_x;
case(3):
return gamepad1Pointer.right_stick_y;
case(4):
return gamepad1Pointer.left_trigger;
case(5):
return gamepad1Pointer.right_trigger;
//-----------------GamePad2-------------------------//
case(6):
return gamepad2Pointer.left_stick_x;
case(7):
return gamepad2Pointer.left_stick_y;
case(8):
return gamepad2Pointer.right_stick_x;
case(9):
return gamepad2Pointer.right_stick_y;
case(10):
return gamepad2Pointer.left_trigger;
case(11):
return gamepad2Pointer.right_trigger;
default:
return 0;
}
}
public boolean getBoolValue(int index){
switch(index){
//----GamePad1---//
case(0):
return gamepad1Pointer.a;
case(1):
return gamepad1Pointer.b;
case(2):
return gamepad1Pointer.x;
case(3):
return gamepad1Pointer.y;
case(4):
return gamepad1Pointer.back;
case(5):
return gamepad1Pointer.start;
case(6):
return gamepad1Pointer.guide;
case(7):
return gamepad1Pointer.dpad_left;
case(8):
return gamepad1Pointer.dpad_right;
case(9):
return gamepad1Pointer.dpad_down;
case(10):
return gamepad1Pointer.dpad_up;
case(11):
return gamepad1Pointer.left_bumper;
case(12):
return gamepad1Pointer.right_bumper;
case(13):
return gamepad1Pointer.left_stick_button;
case(14):
return gamepad1Pointer.right_stick_button;
//----GamePad2---//
case(15):
return gamepad2Pointer.a;
case(16):
return gamepad2Pointer.b;
case(17):
return gamepad2Pointer.x;
case(18):
return gamepad2Pointer.y;
case(19):
return gamepad2Pointer.back;
case(20):
return gamepad2Pointer.start;
case(21):
return gamepad2Pointer.guide;
case(22):
return gamepad2Pointer.dpad_left;
case(23):
return gamepad2Pointer.dpad_right;
case(24):
return gamepad2Pointer.dpad_down;
case(25):
return gamepad2Pointer.dpad_up;
case(26):
return gamepad2Pointer.left_bumper;
case(27):
return gamepad2Pointer.right_bumper;
case(28):
return gamepad2Pointer.left_stick_button;
case(29):
return gamepad2Pointer.right_stick_button;
default:
return false;
}
}
}