-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAutoControllerSelector.java
More file actions
100 lines (85 loc) · 2.47 KB
/
AutoControllerSelector.java
File metadata and controls
100 lines (85 loc) · 2.47 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
package frc.robot.SyncedLibraries;
import java.util.ArrayList;
import frc.robot.SyncedLibraries.SystemBases.ControllerBase;
/**
* This class is used to select the controller that is actively being used.
* The first controller in the list that is being touched is the one that is
* used.
* <p>
* If no controllers are being touched, the nullController is used.
* <p>
* ONLY CHECKS IF JOYSTICK ARE BEING TOUCHED, NOT THE BUTTONS
*/
@Deprecated
public class AutoControllerSelector {
/**
* Further items take lower precedence.
*/
ArrayList<ControllerBase> controllers = new ArrayList<>();
ArrayList<Integer> ports = new ArrayList<>();
ControllerBase ghostController;
Controllers controllersClass;
public AutoControllerSelector(Controllers controllersClass) {
this.ghostController = controllersClass.ghostController;
this.controllersClass = controllersClass;
}
/**
* <h4>NEVER ATTEMPT TO USE THE BUTTONS FROM THIS CONTROLLER</h4>
* <p>
* Using any .get() method from this controller will cause a crash within 2
* minutes
* due to <b>extreme</b> memory usage.
* <p>
* Recommended to treat as if this method is private, but it is public for
* potential future use.
*/
public ControllerBase getController() {
// System.out.println("Getting controller");
if (controllers == null) {
return ghostController;
}
for (int port : ports) {
ControllerBase controller = controllersClass.getPort(port);
if (controller == null) {
continue;
}
if (!controller.isPluggedIn()) {
continue;
}
if (controller.areJoysticksBeingTouched()) {
return controller;
} else {
// System.out.println("Controller on port " + controller.port + " not plugged
// in");
}
}
return ghostController;
}
public AutoControllerSelector addController(Integer... port) {
for (Integer i : port) {
ports.add(i);
}
return this;
}
public double getLeftY() {
return getController().getLeftY();
}
public double getRightY() {
return getController().getRightY();
}
public double getLeftX() {
return getController().getLeftX();
}
public double getRightX() {
return getController().getRightX();
}
public double getLeftTrigger() {
return getController().getLeftTrigger();
}
public double getRightTrigger() {
return getController().getRightTrigger();
}
public double getPOV() {
return getController().getPOV();
}
}