-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathController.java
120 lines (89 loc) · 2.24 KB
/
Controller.java
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
package org.usfirst.frc.team815.robot;
import java.util.ArrayList;
import edu.wpi.first.wpilibj.Joystick;
public class Controller {
public enum ButtonName {
A(1),
B(2),
X(3),
Y(4),
LB(5),
RB(6),
Select(7),
Start(8),
LJ(9),
RJ(10);
private final int index;
ButtonName(int indexIn) {
index = indexIn;
}
public int GetIndex() {
return index;
}
}
public enum AnalogName {
LeftJoyX(0),
LeftJoyY(1),
LeftTrigger(2),
RightTrigger(3),
RightJoyX(4),
RightJoyY(5);
private final int index;
AnalogName(int indexIn) {
index = indexIn;
}
public int GetIndex() {
return index;
}
}
private final double analogThreshold = 0.1;
private Joystick stick;
private ArrayList<Button> buttons = new ArrayList<Button>();
private ArrayList<Analog> analogs = new ArrayList<Analog>();
private Dpad dpad = new Dpad();
public Controller(int port) {
stick = new Joystick(port);
for(ButtonName i : ButtonName.values()) {
buttons.add(new Button(i.GetIndex()));
}
for(AnalogName i : AnalogName.values()) {
analogs.add(new Analog(i.GetIndex()));
}
}
public void Update() {
for(Button i : buttons) {
i.Update(stick);
}
for(Analog i : analogs) {
i.Update(stick, analogThreshold);
}
dpad.Update(stick);
}
public boolean IsPressed(ButtonName button) {
return buttons.get(button.GetIndex()-1).IsPressed();
}
public boolean WasClicked(ButtonName button) {
return buttons.get(button.GetIndex()-1).WasClicked();
}
public boolean WasReleased(ButtonName button) {
return buttons.get(button.GetIndex()-1).WasReleased();
}
public boolean IsToggled(ButtonName button) {
return buttons.get(button.GetIndex()-1).IsToggled();
}
public double GetValue(AnalogName analog) {
return analogs.get(analog.GetIndex()).GetValue();
}
public boolean JustActivated(AnalogName analog) {
return analogs.get(analog.GetIndex()).JustActivated();
}
public boolean JustZeroed(AnalogName analog) {
return analogs.get(analog.GetIndex()).JustZeroed();
}
public Dpad.Direction GetDpadDirection() {
return dpad.GetDirection();
}
public boolean WasDpadDirectionClicked(Dpad.Direction directionIn) {
return dpad.WasDirectionClicked(directionIn);
}
}