SHARE
TWEET

Untitled

a guest Jan 25th, 2013 22 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  * To change this template, choose Tools | Templates
  3.  * and open the template in the editor.
  4.  */
  5. package edu.wpi.first.wpilibj.templates;
  6.  
  7. import edu.wpi.first.wpilibj.Joystick;
  8. import edu.wpi.first.wpilibj.buttons.Button;
  9. import edu.wpi.first.wpilibj.buttons.JoystickButton;
  10.  
  11. /**
  12.  *
  13.  * @author Arhowk
  14.  */
  15. public class XboxController {
  16.     public Joystick controller;
  17.         ChangeButton a;
  18.         ChangeButton b;
  19.         ChangeButton x;
  20.         ChangeButton y;
  21.         ChangeButton bumperLeft;
  22.         ChangeButton bumperRight;
  23.         ChangeButton stop;
  24.         ChangeButton start;
  25.         ChangeButton buttonLeftJoystick;
  26.         ChangeButton buttonRightJoystick;
  27.         ChangeButton thumbPadNone;
  28.         ChangeButton thumbPadTop;
  29.         ChangeButton thumbPadTopRight;
  30.         ChangeButton thumbPadRight;
  31.         ChangeButton thumbPadBottomRight;
  32.         ChangeButton thumbPadBottom;
  33.         ChangeButton thumbPadBottomLeft;
  34.         ChangeButton thumbPadLeft;
  35.         ChangeButton thumbPadTopLeft;
  36.         StringCollector indexer;
  37.     public XboxController(int index){
  38.         controller = new Joystick(index);
  39.         a = new ChangeButton(controller, 1);
  40.         b = new ChangeButton(controller, 2);
  41.         x = new ChangeButton(controller, 3);
  42.         y = new ChangeButton(controller, 4);
  43.         bumperLeft = new ChangeButton(controller, 5);
  44.         bumperRight = new ChangeButton(controller, 6);
  45.         stop = new ChangeButton(controller, 7);
  46.         start = new ChangeButton(controller, 8);
  47.         buttonLeftJoystick = new ChangeButton(controller, 9);
  48.         buttonRightJoystick = new ChangeButton(controller, 10);
  49.         thumbPadNone = new ChangeButton(controller, -1);
  50.         thumbPadTop = new ChangeButton(controller, 0);
  51.         thumbPadTopRight = new ChangeButton(controller, 45);
  52.         thumbPadRight = new ChangeButton(controller, 90);
  53.         thumbPadBottomRight = new ChangeButton(controller, 135);
  54.         thumbPadBottom = new ChangeButton(controller, 180);
  55.         thumbPadBottomLeft = new ChangeButton(controller, 225);
  56.         thumbPadLeft = new ChangeButton(controller, 270);
  57.         thumbPadTopLeft = new ChangeButton(controller, 315);
  58.         indexer = new StringCollector();
  59.     }
  60.     public double getLeftStickRotate() {
  61.         return controller.getRawAxis(1);
  62.     }
  63.     public double getLeftStickMove() {
  64.         return controller.getRawAxis(2);
  65.     }
  66.     public double getTriggers() {
  67.         return controller.getRawAxis(3);
  68.     }
  69.     public double getRightStickRotate() {
  70.         return controller.getRawAxis(4);
  71.     }
  72.     public double getRightStickMove() {
  73.         return controller.getRawAxis(5);
  74.     }
  75.     public boolean a(){
  76.         return a.runningCommand.isRunning();
  77.     }
  78.     public boolean b(){
  79.         return b.runningCommand.isRunning();
  80.     }
  81.     public boolean x(){
  82.         return x.runningCommand.isRunning();
  83.     }
  84.     public boolean y(){
  85.         return y.runningCommand.isRunning();
  86.     }
  87.     public boolean start(){
  88.         return start.runningCommand.isRunning();
  89.     }
  90.     public boolean stop(){
  91.         return stop.runningCommand.isRunning();
  92.     }
  93.     public boolean buttonLeftJoystick(){
  94.         return buttonLeftJoystick.runningCommand.isRunning();
  95.     }
  96.     public boolean buttonRightJoystick(){
  97.         return buttonRightJoystick.runningCommand.isRunning();
  98.     }
  99.     public boolean bumperLeft(){
  100.         return bumperLeft.runningCommand.isRunning();
  101.     }
  102.     public boolean bumperRight(){
  103.         return bumperRight.runningCommand.isRunning();
  104.     }
  105.     public boolean thumbPadNone(){
  106.         return thumbPadNone.runningCommand.isRunning();
  107.     }
  108.     public boolean thumbPadTop(){
  109.         return thumbPadTop.runningCommand.isRunning();
  110.     }
  111.     public boolean thumbPadTopRight(){
  112.         return thumbPadTopRight.runningCommand.isRunning();
  113.     }
  114.     public boolean thumbPadRight(){
  115.         return thumbPadRight.runningCommand.isRunning();
  116.     }
  117.     public boolean thumbPadBottomRight(){
  118.         return thumbPadBottomRight.runningCommand.isRunning();
  119.     }
  120.     public boolean thumbPadBottom(){
  121.         return thumbPadBottom.runningCommand.isRunning();
  122.     }
  123.     public boolean thumbPadBottomLeft(){
  124.         return thumbPadBottomLeft.runningCommand.isRunning();
  125.     }
  126.     public boolean thumbPadLeft(){
  127.         return thumbPadLeft.runningCommand.isRunning();
  128.     }
  129.     public boolean thumbPadTopLeft(){
  130.         return thumbPadTopLeft.runningCommand.isRunning();
  131.     }
  132.     public Button searchByString(String s){
  133.         for(int i = 1; i < 20; i++){
  134.             try{
  135.                 if(indexer.strings[i].equalsIgnoreCase(s)){
  136.                     return indexer.buttons[i];
  137.                 }
  138.             }catch(NullPointerException ex){
  139.                 System.out.println("ERROR : INVALID VALUE REGISTERED FOR A SEARCH VALUE");
  140.             }
  141.         }
  142.         return indexer.buttons[18];
  143.     }
  144.     private class StringCollector{
  145.         public String strings[];
  146.         public Button buttons[];
  147.         public boolean enabled = false;
  148.         public StringCollector(){
  149.             start();
  150.         }
  151.         public void start(){
  152.             if(!enabled){
  153.               buttons = new Button[20];
  154.               strings = new String[20];
  155.               //strings = new String[20];
  156.               strings[1] = new String("A");
  157.               buttons[1] = a;
  158.               strings[2] = new String("B");
  159.               buttons[2] = b;
  160.               strings[3] = new String("X");
  161.               buttons[3] = x;
  162.               strings[4] = new String("Y");
  163.               buttons[4] = y;
  164.               strings[5] = new String("Left Bumper");
  165.               buttons[5] = bumperLeft;
  166.               strings[6] = new String("Right Bumper");
  167.               buttons[6] = bumperRight;
  168.               strings[8] = new String("Start");
  169.               buttons[8] = start;
  170.               strings[7] = new String("Stop");
  171.               buttons[7] = stop;
  172.               strings[9] = new String("Left Joystick");
  173.               buttons[9] = buttonLeftJoystick;
  174.               strings[10] = new String("Right Joystick");
  175.               buttons[10] = buttonRightJoystick;
  176.               strings[11] = new String("Thumb Top");
  177.               buttons[11] = thumbPadTop;
  178.               strings[12] = new String("Thumb Topright");
  179.               buttons[12] = thumbPadTopRight;
  180.               strings[13] = new String("Thumb Right");
  181.               buttons[13] = thumbPadRight;
  182.               strings[14] = new String("Thumb Bottomright");
  183.               buttons[14] = thumbPadBottomRight;
  184.               strings[15] = new String("Thumb Bottom");
  185.               buttons[15] = thumbPadBottom;
  186.               strings[16] = new String("Thumb BottomLeft");
  187.               buttons[16] = thumbPadBottomLeft;
  188.               strings[17] = new String("Thumb Left");
  189.               buttons[17] = thumbPadLeft;
  190.               strings[18] = new String("Thumb TopLeft");
  191.               buttons[18] = thumbPadTopLeft;
  192.                enabled = true;
  193.             }
  194.            
  195.         }
  196.     }
  197. }
RAW Paste Data
Top