- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- package edu.wpi.first.wpilibj.templates;
- import edu.wpi.first.wpilibj.Joystick;
- import edu.wpi.first.wpilibj.buttons.Button;
- import edu.wpi.first.wpilibj.buttons.JoystickButton;
- /**
- *
- * @author Arhowk
- */
- public class XboxController {
- public Joystick controller;
- ChangeButton a;
- ChangeButton b;
- ChangeButton x;
- ChangeButton y;
- ChangeButton bumperLeft;
- ChangeButton bumperRight;
- ChangeButton stop;
- ChangeButton start;
- ChangeButton buttonLeftJoystick;
- ChangeButton buttonRightJoystick;
- ChangeButton thumbPadNone;
- ChangeButton thumbPadTop;
- ChangeButton thumbPadTopRight;
- ChangeButton thumbPadRight;
- ChangeButton thumbPadBottomRight;
- ChangeButton thumbPadBottom;
- ChangeButton thumbPadBottomLeft;
- ChangeButton thumbPadLeft;
- ChangeButton thumbPadTopLeft;
- StringCollector indexer;
- public XboxController(int index){
- controller = new Joystick(index);
- a = new ChangeButton(controller, 1);
- b = new ChangeButton(controller, 2);
- x = new ChangeButton(controller, 3);
- y = new ChangeButton(controller, 4);
- bumperLeft = new ChangeButton(controller, 5);
- bumperRight = new ChangeButton(controller, 6);
- stop = new ChangeButton(controller, 7);
- start = new ChangeButton(controller, 8);
- buttonLeftJoystick = new ChangeButton(controller, 9);
- buttonRightJoystick = new ChangeButton(controller, 10);
- thumbPadNone = new ChangeButton(controller, -1);
- thumbPadTop = new ChangeButton(controller, 0);
- thumbPadTopRight = new ChangeButton(controller, 45);
- thumbPadRight = new ChangeButton(controller, 90);
- thumbPadBottomRight = new ChangeButton(controller, 135);
- thumbPadBottom = new ChangeButton(controller, 180);
- thumbPadBottomLeft = new ChangeButton(controller, 225);
- thumbPadLeft = new ChangeButton(controller, 270);
- thumbPadTopLeft = new ChangeButton(controller, 315);
- indexer = new StringCollector();
- }
- public double getLeftStickRotate() {
- return controller.getRawAxis(1);
- }
- public double getLeftStickMove() {
- return controller.getRawAxis(2);
- }
- public double getTriggers() {
- return controller.getRawAxis(3);
- }
- public double getRightStickRotate() {
- return controller.getRawAxis(4);
- }
- public double getRightStickMove() {
- return controller.getRawAxis(5);
- }
- public boolean a(){
- return a.runningCommand.isRunning();
- }
- public boolean b(){
- return b.runningCommand.isRunning();
- }
- public boolean x(){
- return x.runningCommand.isRunning();
- }
- public boolean y(){
- return y.runningCommand.isRunning();
- }
- public boolean start(){
- return start.runningCommand.isRunning();
- }
- public boolean stop(){
- return stop.runningCommand.isRunning();
- }
- public boolean buttonLeftJoystick(){
- return buttonLeftJoystick.runningCommand.isRunning();
- }
- public boolean buttonRightJoystick(){
- return buttonRightJoystick.runningCommand.isRunning();
- }
- public boolean bumperLeft(){
- return bumperLeft.runningCommand.isRunning();
- }
- public boolean bumperRight(){
- return bumperRight.runningCommand.isRunning();
- }
- public boolean thumbPadNone(){
- return thumbPadNone.runningCommand.isRunning();
- }
- public boolean thumbPadTop(){
- return thumbPadTop.runningCommand.isRunning();
- }
- public boolean thumbPadTopRight(){
- return thumbPadTopRight.runningCommand.isRunning();
- }
- public boolean thumbPadRight(){
- return thumbPadRight.runningCommand.isRunning();
- }
- public boolean thumbPadBottomRight(){
- return thumbPadBottomRight.runningCommand.isRunning();
- }
- public boolean thumbPadBottom(){
- return thumbPadBottom.runningCommand.isRunning();
- }
- public boolean thumbPadBottomLeft(){
- return thumbPadBottomLeft.runningCommand.isRunning();
- }
- public boolean thumbPadLeft(){
- return thumbPadLeft.runningCommand.isRunning();
- }
- public boolean thumbPadTopLeft(){
- return thumbPadTopLeft.runningCommand.isRunning();
- }
- public Button searchByString(String s){
- for(int i = 1; i < 20; i++){
- try{
- if(indexer.strings[i].equalsIgnoreCase(s)){
- return indexer.buttons[i];
- }
- }catch(NullPointerException ex){
- System.out.println("ERROR : INVALID VALUE REGISTERED FOR A SEARCH VALUE");
- }
- }
- return indexer.buttons[18];
- }
- private class StringCollector{
- public String strings[];
- public Button buttons[];
- public boolean enabled = false;
- public StringCollector(){
- start();
- }
- public void start(){
- if(!enabled){
- buttons = new Button[20];
- strings = new String[20];
- //strings = new String[20];
- strings[1] = new String("A");
- buttons[1] = a;
- strings[2] = new String("B");
- buttons[2] = b;
- strings[3] = new String("X");
- buttons[3] = x;
- strings[4] = new String("Y");
- buttons[4] = y;
- strings[5] = new String("Left Bumper");
- buttons[5] = bumperLeft;
- strings[6] = new String("Right Bumper");
- buttons[6] = bumperRight;
- strings[8] = new String("Start");
- buttons[8] = start;
- strings[7] = new String("Stop");
- buttons[7] = stop;
- strings[9] = new String("Left Joystick");
- buttons[9] = buttonLeftJoystick;
- strings[10] = new String("Right Joystick");
- buttons[10] = buttonRightJoystick;
- strings[11] = new String("Thumb Top");
- buttons[11] = thumbPadTop;
- strings[12] = new String("Thumb Topright");
- buttons[12] = thumbPadTopRight;
- strings[13] = new String("Thumb Right");
- buttons[13] = thumbPadRight;
- strings[14] = new String("Thumb Bottomright");
- buttons[14] = thumbPadBottomRight;
- strings[15] = new String("Thumb Bottom");
- buttons[15] = thumbPadBottom;
- strings[16] = new String("Thumb BottomLeft");
- buttons[16] = thumbPadBottomLeft;
- strings[17] = new String("Thumb Left");
- buttons[17] = thumbPadLeft;
- strings[18] = new String("Thumb TopLeft");
- buttons[18] = thumbPadTopLeft;
- enabled = true;
- }
- }
- }
- }
SHARE
TWEET
Untitled
a guest
Jan 25th, 2013
22
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
RAW Paste Data
