-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f8eef54
commit bf6d59e
Showing
3 changed files
with
94 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package org.usfirst.frc.team4737.lib; | ||
|
||
import edu.wpi.first.wpilibj.Joystick; | ||
import edu.wpi.first.wpilibj.buttons.JoystickButton; | ||
|
||
public class LogitechController { | ||
|
||
public class Axis { | ||
private final Joystick controller; | ||
private final int axis; | ||
|
||
private double deadzone; | ||
|
||
public Axis(Joystick controller, int axis) { | ||
this.controller = controller; | ||
this.axis = axis; | ||
} | ||
|
||
public void setDeadzone(double radius) { | ||
if (radius < 0) throw new IllegalArgumentException("Deadzone cannot be less than 0."); | ||
this.deadzone = radius; | ||
} | ||
|
||
public double getRaw() { | ||
return controller.getRawAxis(axis); | ||
} | ||
|
||
public double get() { | ||
double raw = getRaw(); | ||
if (raw < -deadzone) { | ||
return scale(raw, -1, -deadzone, -1, 0); | ||
} else if (raw > deadzone) { | ||
return scale(raw, deadzone, 1, 0, 1); | ||
} else { | ||
return 0; | ||
} | ||
} | ||
|
||
private double scale(double val, double valLow, double valHigh, double newLow, double newHigh) { | ||
double reduced = (val - valLow) / (valHigh - valLow); | ||
return reduced * (newHigh - newLow) + newLow; | ||
} | ||
} | ||
|
||
public class Thumbstick { | ||
public final Axis X, Y; | ||
|
||
public Thumbstick(Joystick controller, int axisX, int axisY) { | ||
X = new Axis(controller, axisX); | ||
Y = new Axis(controller, axisY); | ||
} | ||
} | ||
|
||
public final Joystick controller; | ||
public final JoystickButton A; | ||
public final JoystickButton B; | ||
public final JoystickButton X; | ||
public final JoystickButton Y; | ||
public final JoystickButton RB; | ||
public final JoystickButton LB; | ||
public final Thumbstick LS; | ||
public final Thumbstick RS; | ||
public final Axis LT; | ||
public final Axis RT; | ||
|
||
public LogitechController(int usbPort) { | ||
controller = new Joystick(usbPort); | ||
A = new JoystickButton(controller, -1); // TODO map the correct button IDs | ||
B = new JoystickButton(controller, -1); | ||
X = new JoystickButton(controller, -1); | ||
Y = new JoystickButton(controller, -1); | ||
RB = new JoystickButton(controller, -1); | ||
LB = new JoystickButton(controller, -1); | ||
LS = new Thumbstick(controller, -1, -1); | ||
RS = new Thumbstick(controller, -1, -1); | ||
LT = new Axis(controller, -1); | ||
RT = new Axis(controller, -1); | ||
} | ||
|
||
// TODO add rumble if possible | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters