org.usfirst.frc.team3695.robot.util.Xbox   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 10
dl 0
loc 32
c 0
b 0
f 0
rs 10

14 Methods

Rating   Name   Duplication   Size   Complexity  
A deadzone(double) 0 8 4
deadzone 0 8 ?
LEFT_X 0 1 ?
A RT(Joystick) 0 1 1
A RIGHT_Y(Joystick) 0 1 1
A LEFT_Y(Joystick) 0 1 1
RIGHT_X 0 1 ?
A LEFT_X(Joystick) 0 1 1
RIGHT_Y 0 1 ?
A RIGHT_X(Joystick) 0 1 1
A LT(Joystick) 0 1 1
LEFT_Y 0 1 ?
RT 0 1 ?
LT 0 1 ?
1
package org.usfirst.frc.team3695.robot.util;
2
3
import edu.wpi.first.wpilibj.Joystick;
4
5
/** all of the stuff you need to implement X360 controllers */
6
public class Xbox {
0 ignored issues
show
Best Practice introduced by
This looks like a utility class. You may want to hide the implict public constructor behind a private one, so the class cannot be instantiated,
Loading history...
7
	
8
	public static final double DEADZONE = 0.25;
0 ignored issues
show
Comprehensibility introduced by
Fields and methods should not have conflicting names like DEADZONE. While this is technically legal it can lead to misunderstandings and problems with serialization.
Loading history...
9
	
10
	public static final int
11
			A = 1,
12
			B = 2,
0 ignored issues
show
Coding Style introduced by
Declaring several variables on the same line makes your code hard to read. Consider delaring B on a separate line.
Loading history...
13
			X = 3,
0 ignored issues
show
Coding Style introduced by
Declaring several variables on the same line makes your code hard to read. Consider delaring X on a separate line.
Loading history...
14
			Y = 4,
0 ignored issues
show
Coding Style introduced by
Declaring several variables on the same line makes your code hard to read. Consider delaring Y on a separate line.
Loading history...
15
			LB = 5,
0 ignored issues
show
Coding Style introduced by
Declaring several variables on the same line makes your code hard to read. Consider delaring LB on a separate line.
Loading history...
16
			RB = 6,
0 ignored issues
show
Coding Style introduced by
Declaring several variables on the same line makes your code hard to read. Consider delaring RB on a separate line.
Loading history...
17
			BACK = 7,
0 ignored issues
show
Coding Style introduced by
Declaring several variables on the same line makes your code hard to read. Consider delaring BACK on a separate line.
Loading history...
18
			START = 8,
0 ignored issues
show
Coding Style introduced by
Declaring several variables on the same line makes your code hard to read. Consider delaring START on a separate line.
Loading history...
19
			LSTICK = 9,
0 ignored issues
show
Coding Style introduced by
Declaring several variables on the same line makes your code hard to read. Consider delaring LSTICK on a separate line.
Loading history...
20
			RSTICK = 10;
0 ignored issues
show
Coding Style introduced by
Declaring several variables on the same line makes your code hard to read. Consider delaring RSTICK on a separate line.
Loading history...
21
22
	private static double deadzone(double rawAxis) { // deadzone value is in constants
23
		boolean positive = rawAxis > 0.0;
24
		rawAxis *= (positive ? 1.0 : -1.0); //flip if needed
25
		rawAxis -= DEADZONE; //clip dead zone
26
		if(rawAxis < 0.0) rawAxis = 0.0; //trim if less than 0
27
		rawAxis /= (1.0 - DEADZONE); //scale back to 1.0
28
		rawAxis *= (positive ? 1.0 : -1.0); //flip back
29
		return rawAxis;
30
	}
31
	
32
	public static double LEFT_X(Joystick joy) {return deadzone(joy.getRawAxis(0));}
33
	public static double LEFT_Y(Joystick joy) {return deadzone(joy.getRawAxis(1));}
34
	public static double RIGHT_X(Joystick joy) {return deadzone(joy.getRawAxis(4));}
0 ignored issues
show
Comprehensibility introduced by
Consider assigning this magic number 4 to a constant.

Using constants for hard-coded numbers is a best practice. A constant’s name can explain the rationale behind this magic number. It is also easier to find if you ever need to change it.

Loading history...
35
	public static double RIGHT_Y(Joystick joy) {return deadzone(joy.getRawAxis(5));}
0 ignored issues
show
Comprehensibility introduced by
Consider assigning this magic number 5 to a constant.

Using constants for hard-coded numbers is a best practice. A constant’s name can explain the rationale behind this magic number. It is also easier to find if you ever need to change it.

Loading history...
36
	public static double LT(Joystick joy) {return joy.getRawAxis(2);}
0 ignored issues
show
Comprehensibility introduced by
Consider assigning this magic number 2 to a constant.

Using constants for hard-coded numbers is a best practice. A constant’s name can explain the rationale behind this magic number. It is also easier to find if you ever need to change it.

Loading history...
37
	public static double RT(Joystick joy) {return joy.getRawAxis(3);}
0 ignored issues
show
Comprehensibility introduced by
Consider assigning this magic number 3 to a constant.

Using constants for hard-coded numbers is a best practice. A constant’s name can explain the rationale behind this magic number. It is also easier to find if you ever need to change it.

Loading history...
38
}
39