-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathMultiTrigger.java
39 lines (32 loc) · 1 KB
/
MultiTrigger.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
package com.team254.lib.util;
/**
* Class to differentiate between tapping and holding a joystick button/trigger
*/
public class MultiTrigger {
private final double mTimeout;
private boolean lastPressed = false;
private final LatchedBoolean wasTapped = new LatchedBoolean();
private final LatchedBoolean wasHeld = new LatchedBoolean();
private boolean lastTapped = false;
private final TimeDelayedBoolean isHeld = new TimeDelayedBoolean();
public MultiTrigger(double timeout) {
mTimeout = timeout;
}
public void update(boolean pressed) {
lastPressed = pressed;
lastTapped = wasTapped.update(pressed);
isHeld.update(pressed, mTimeout);
}
public boolean wasTapped() {
return lastTapped;
}
public boolean isPressed() {
return lastPressed;
}
public boolean isHeld() {
return isHeld.update(lastPressed, mTimeout);
}
public boolean holdStarted() {
return wasHeld.update(isHeld());
}
}