11package ca .team4308 .absolutelib .control ;
22
3- import edu . wpi . first . wpilibj . Joystick ;
3+ import ca . team4308 . absolutelib . control . XBoxWrapper . XBoxMapping ;
44import edu .wpi .first .wpilibj .GenericHID .RumbleType ;
5+ import edu .wpi .first .wpilibj .Joystick ;
56import edu .wpi .first .wpilibj2 .command .button .JoystickButton ;
7+ import edu .wpi .first .wpilibj2 .command .button .POVButton ;
68import edu .wpi .first .wpilibj2 .command .button .Trigger ;
79
810public class RazerWrapper {
9- public static class RazerMapping {
10- public static int A = 1 ;
11- public static int B = 2 ;
12- public static int X = 3 ;
13- public static int Y = 4 ;
14-
15- public static int LB = 5 ;
16- public static int RB = 6 ;
17-
18- public static int Start = 7 ;
19- public static int Back = 8 ;
20-
21- public static int LeftStickButton = 9 ;
22- public static int RightStickButton = 10 ;
23- }
24-
25- public final Joystick joystick ;
26-
27- public final JoystickButton A ;
28- public final JoystickButton B ;
29- public final JoystickButton X ;
30- public final JoystickButton Y ;
31-
32- public final JoystickButton LB ;
33- public final JoystickButton RB ;
34-
35- public final JoystickButton M1 ;
36- public final JoystickButton M2 ;
37-
38- public final JoystickButton LeftStickButton ;
39- public final JoystickButton RightStickButton ;
40-
41- public final POVToJoystick M3 ;
42- public final POVToJoystick M4 ;
43- public final POVToJoystick M5 ;
44- public final POVToJoystick M6 ;
45-
46- public final Trigger RightTriggerTrigger ;
47- public final Trigger LeftTriggerTrigger ;
48-
49- public RazerWrapper (int port ) {
50- /*
51- * requires: m1 to be start
52- * m2 to be back
53- * m3 to be povup
54- * m4 to be povdown
55- * m5 to be povleft
56- * m6 to be povright
57- *
58- * these buttons will do the same thing, but should not be used anyways
59- */
60-
61- this .joystick = new Joystick (port );
62-
63- this .A = new JoystickButton (joystick , RazerMapping .A );
64- this .B = new JoystickButton (joystick , RazerMapping .B );
65- this .X = new JoystickButton (joystick , RazerMapping .X );
66- this .Y = new JoystickButton (joystick , RazerMapping .Y );
67-
68- this .LB = new JoystickButton (joystick , RazerMapping .LB );
69- this .RB = new JoystickButton (joystick , RazerMapping .RB );
70- this .LeftStickButton = new JoystickButton (joystick , RazerMapping .LeftStickButton );
71- this .RightStickButton = new JoystickButton (joystick , RazerMapping .RightStickButton );
72-
73- this .M1 = new JoystickButton (joystick , RazerMapping .Start );
74- this .M2 = new JoystickButton (joystick , RazerMapping .Back );
75-
76- this .M3 = new POVToJoystick (joystick , 0 );
77- this .M4 = new POVToJoystick (joystick , 180 );
78- this .M5 = new POVToJoystick (joystick , 90 );
79- this .M6 = new POVToJoystick (joystick , 270 );
80-
81- this .RightTriggerTrigger = new Trigger (() -> getRightTriggerAsBoolean ());
82- this .LeftTriggerTrigger = new Trigger (() -> getLeftTriggerAsBoolean ());
83- }
84-
85- public double getLeftX () {
86- return joystick .getRawAxis (0 );
87- }
88-
89- public double getLeftY () {
90- return joystick .getRawAxis (1 );
91- }
92-
93- public double getRightX () {
94- return joystick .getRawAxis (4 );
95- }
96-
97- public double getRightY () {
98- return joystick .getRawAxis (5 );
99- }
100-
101- public double getLeftTrigger () {
102- return joystick .getRawAxis (2 );
103- }
104-
105- public double getRightTrigger () {
106- return joystick .getRawAxis (3 );
107- }
108-
109- public boolean getLeftTriggerAsBoolean () {
110- return (joystick .getRawAxis (2 ) > 0.5 );
111- }
112-
113- public boolean getRightTriggerAsBoolean () {
114- return (joystick .getRawAxis (3 ) > 0.15 );
115- }
116-
117- public void setRumble (RumbleType type , double power ) {
118- joystick .setRumble (type , power );
119- }
120- }
11+ public static class RazerMapping {
12+ public static int A = 1 ;
13+ public static int B = 2 ;
14+ public static int X = 3 ;
15+ public static int Y = 4 ;
16+
17+ public static int LB = 5 ;
18+ public static int RB = 6 ;
19+
20+ public static int Start = 7 ;
21+ public static int Back = 8 ;
22+
23+ public static int LeftStickButton = 9 ;
24+ public static int RightStickButton = 10 ;
25+ }
26+
27+ public final Joystick joystick ;
28+
29+ public final JoystickButton A ;
30+ public final JoystickButton B ;
31+ public final JoystickButton X ;
32+ public final JoystickButton Y ;
33+
34+ public final JoystickButton LB ;
35+ public final JoystickButton RB ;
36+
37+ public final JoystickButton M1 ;
38+ public final JoystickButton M2 ;
39+
40+ public final JoystickButton LeftStickButton ;
41+ public final JoystickButton RightStickButton ;
42+
43+ public final POVToJoystick M3 ;
44+ public final POVToJoystick M4 ;
45+ public final POVToJoystick M5 ;
46+ public final POVToJoystick M6 ;
47+
48+ public final Trigger RightTrigger ;
49+ public final Trigger LeftTrigger ;
50+
51+ public final JoystickButton Start ;
52+ public final JoystickButton Back ;
53+
54+ public final POVButton povUp ;
55+ public final POVButton povRight ;
56+ public final POVButton povDown ;
57+ public final POVButton povLeft ;
58+
59+ public RazerWrapper (int port ) {
60+ /*
61+ * requires: m1 to be start
62+ * m2 to be back
63+ * m3 to be povup
64+ * m4 to be povdown
65+ * m5 to be povleft
66+ * m6 to be povright
67+ *
68+ * these buttons will do the same thing, but should not be used anyways
69+ */
70+
71+ this .joystick = new Joystick (port );
72+
73+ this .A = new JoystickButton (joystick , RazerMapping .A );
74+ this .B = new JoystickButton (joystick , RazerMapping .B );
75+ this .X = new JoystickButton (joystick , RazerMapping .X );
76+ this .Y = new JoystickButton (joystick , RazerMapping .Y );
77+
78+ this .LB = new JoystickButton (joystick , RazerMapping .LB );
79+ this .RB = new JoystickButton (joystick , RazerMapping .RB );
80+ this .LeftStickButton = new JoystickButton (joystick , RazerMapping .LeftStickButton );
81+ this .RightStickButton = new JoystickButton (joystick , RazerMapping .RightStickButton );
82+
83+ this .M1 = new JoystickButton (joystick , RazerMapping .Start );
84+ this .M2 = new JoystickButton (joystick , RazerMapping .Back );
85+
86+ this .M3 = new POVToJoystick (joystick , 0 );
87+ this .M4 = new POVToJoystick (joystick , 180 );
88+ this .M5 = new POVToJoystick (joystick , 270 );
89+ this .M6 = new POVToJoystick (joystick , 90 );
90+
91+ this .RightTrigger = new Trigger (() -> getRightTriggerAsBoolean ());
92+ this .LeftTrigger = new Trigger (() -> getLeftTriggerAsBoolean ());
93+
94+ this .Start = new JoystickButton (joystick , XBoxMapping .Start );
95+ this .Back = new JoystickButton (joystick , XBoxMapping .Back );
96+
97+ this .povUp = new POVButton (joystick , 0 );
98+ this .povRight = new POVButton (joystick , 90 );
99+ this .povDown = new POVButton (joystick , 180 );
100+ this .povLeft = new POVButton (joystick , 270 );
101+ }
102+
103+ public double getLeftX () {
104+ return joystick .getRawAxis (0 );
105+ }
106+
107+ public double getLeftY () {
108+ return joystick .getRawAxis (1 );
109+ }
110+
111+ public double getRightX () {
112+ return joystick .getRawAxis (4 );
113+ }
114+
115+ public double getRightY () {
116+ return joystick .getRawAxis (5 );
117+ }
118+
119+ public double getLeftTrigger () {
120+ return joystick .getRawAxis (2 );
121+ }
122+
123+ public double getRightTrigger () {
124+ return joystick .getRawAxis (3 );
125+ }
126+
127+ public boolean getLeftTriggerAsBoolean () {
128+ return (joystick .getRawAxis (2 ) > 0.5 );
129+ }
130+
131+ public boolean getRightTriggerAsBoolean () {
132+ return (joystick .getRawAxis (3 ) > 0.5 );
133+ }
134+
135+ public boolean getLeftTriggerAsBoolean (double threshold ) {
136+ return (joystick .getRawAxis (2 ) > threshold );
137+ }
138+
139+ public boolean getRightTriggerAsBoolean (double threshold ) {
140+ return (joystick .getRawAxis (3 ) > threshold );
141+ }
142+
143+ public void setRumble (RumbleType type , double power ) {
144+ joystick .setRumble (type , power );
145+ }
146+ }
0 commit comments