-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDpad.java
53 lines (42 loc) · 1.02 KB
/
Dpad.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
package org.usfirst.frc.team815.robot;
import java.util.HashMap;
import java.util.Map;
import edu.wpi.first.wpilibj.Joystick;
public class Dpad {
public enum Direction {
None(-1),
Up(0),
UpRight(45),
Right(90),
DownRight(135),
Down(180),
DownLeft(225),
Left(270),
UpLeft(315);
private int angle;
private static Map<Integer, Direction> map = new HashMap<Integer, Direction>();
private Direction(int angleIn) {
angle = angleIn;
}
static {
for(Direction direction : Direction.values()) {
map.put(direction.angle, direction);
}
}
public static Direction valueOf(int angleIn) {
return map.get(angleIn);
}
}
Direction direction;
Direction previousDirection;
public Direction GetDirection() {
return direction;
}
public boolean WasDirectionClicked(Direction directionIn) {
return directionIn == direction && directionIn != previousDirection;
}
public void Update(Joystick stick) {
previousDirection = direction;
direction = Direction.valueOf(stick.getPOV());
}
}