-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlasmaButton.java
81 lines (70 loc) · 1.43 KB
/
PlasmaButton.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
package frc.robot.controllers;
import edu.wpi.first.wpilibj.*;
public class PlasmaButton {
private final int joystickPort;
private final byte buttonNumByte;
private boolean isHeld = false;
private boolean isToggled = false;
/**
* Contructor for the button class
*
* @param buttonNum - ID value of the button
* @param joystickPort - Joystick port that the button is on
*
* @author Nic A
*/
public PlasmaButton(int buttonNum, int joystickPort) {
this.joystickPort = joystickPort;
this.buttonNumByte = (byte)buttonNum;
}
/**
* Check if button is pressed
*
* @return True if button is pressed
*
* @author Nic A
*/
public boolean isPressed(){
return DriverStation.getStickButton(joystickPort, buttonNumByte);
}
/**
* Checks if button has been switched from off to on
*
* @return True once when button is toggled on
*
* @author Nic A
*/
public boolean isOffToOn(){
if(!isHeld && isPressed()){
isHeld = true;
return true;
}
else{
isHeld = isPressed();
return false;
}
}
/**
* Checks if button has been switched from on to off
*
* @return True once when button is toggled off
*
* @author Nic A
*/
public boolean isOnToOff(){
if(isHeld && !isPressed()){
isHeld = false;
return true;
}
else{
isHeld = isPressed();
return false;
}
}
public boolean isToggledOn(){
if(isOnToOff()){
isToggled = !isToggled;
}
return isToggled;
}
}