package com.edinarobotics.utils.gamepad;

import edu.wpi.first.wpilibj.Joystick;

/**
 * Represents a gamepad with two joysticks and several buttons.
 * Makes interacting with a gamepad easier.
 * Returns results through a GamepadResult.
 */
public class Gamepad extends Joystick{
    public static final int LEFT_X_AXIS = 1;
    public static final int LEFT_Y_AXIS = 2;
    public static final int RIGHT_X_AXIS = 3;
    public static final int RIGHT_Y_AXIS = 4;
    
    public static final int DPAD_X = 5;
    public static final int DPAD_Y = 6;
    
    public static final int LEFT_BUMPER = 5;
    public static final int LEFT_TRIGGER = 7;
    public static final int RIGHT_BUMPER = 6;
    public static final int RIGHT_TRIGGER = 8;
    public static final int BUTTON_1 = 1;
    public static final int BUTTON_2 = 2;
    public static final int BUTTON_3 = 3;
    public static final int BUTTON_4 = 4;
    public static final int BUTTON_9 = 9;
    public static final int BUTTON_10 = 10;
    
    public static final int LEFT_JOYSTICK_BUTTON = 11;
    public static final int RIGHT_JOYSTICK_BUTTON = 12;
                    
    private static final double DPAD_THRESHOLD = 0.9;
    
    public Gamepad(int port){
        super(port);
    }
    
    public double getLeftX(){
        return this.getRawAxis(LEFT_X_AXIS);
    }
    
    public double getLeftY(){
        return this.getRawAxis(LEFT_Y_AXIS);
    }
    
    public double getRightX(){
        return this.getRawAxis(RIGHT_X_AXIS);
    }
    
    public double getRightY(){
        return this.getRawAxis(RIGHT_Y_AXIS);
    }
    
    public int getDPadX()
    {
        return dPadToInt(this.getRawAxis(DPAD_X));
    }
    
    public int getDPadY()
    {
        return dPadToInt(this.getRawAxis(DPAD_Y));
    }
    
    private int dPadToInt(double value){
        if(value >= DPAD_THRESHOLD){
            return 1;
        }
        else if(value <= -DPAD_THRESHOLD){
            return -1;
        }
        return 0;
    }
    
    public GamepadResult getJoysticks(){
        return new GamepadResult(getLeftX(),getLeftY(),getRightX(),getRightY());
    }

}

@@ -73,16 +73,69 @@
 oystick;
+%0Aimport edu.wpi.first.wpilibj.buttons.JoystickButton;
 %0A%0A/**%0A *
@@ -1057,236 +1057,1699 @@
 lic 
-static final int LEFT_JOYSTICK_BUTTON = 11;%0A    public static final int RIGHT_JOYSTICK_BUTTON = 12;%0A                    %0A    private static final double DPAD_THRESHOLD = 0.9;%0A    %0A    public Gamepad(int port)%7B%0A        super(port
+final JoystickButton LEFT_BUMPER_BUTTON;%0A    public final JoystickButton LEFT_TRIGGER_BUTTON;%0A    public final JoystickButton RIGHT_BUMPER_BUTTON;%0A    public final JoystickButton RIGHT_TRIGGER_BUTTON;%0A    public final JoystickButton BUTTON_1_BUTTON;%0A    public final JoystickButton BUTTON_2_BUTTON;%0A    public final JoystickButton BUTTON_3_BUTTON;%0A    public final JoystickButton BUTTON_4_BUTTON;%0A    public final JoystickButton BUTTON_9_BUTTON;%0A    public final JoystickButton BUTTON_10_BUTTON;%0A    public final JoystickButton LEFT_JOYSTICK_BUTTON_BUTTON;%0A    public final JoystickButton RIGHT_JOYSTICK_BUTTON_BUTTON;%0A    %0A    public static final int LEFT_JOYSTICK_BUTTON = 11;%0A    public static final int RIGHT_JOYSTICK_BUTTON = 12;%0A                    %0A    private static final double DPAD_THRESHOLD = 0.9;%0A    %0A    public Gamepad(int port)%7B%0A        super(port);%0A        LEFT_BUMPER_BUTTON = new JoystickButton(this, LEFT_BUMPER);%0A        LEFT_TRIGGER_BUTTON = new JoystickButton(this, LEFT_TRIGGER);%0A        RIGHT_BUMPER_BUTTON = new JoystickButton(this, RIGHT_BUMPER);%0A        RIGHT_TRIGGER_BUTTON = new JoystickButton(this, RIGHT_TRIGGER);%0A        BUTTON_1_BUTTON = new JoystickButton(this, BUTTON_1);%0A        BUTTON_2_BUTTON = new JoystickButton(this, BUTTON_2);%0A        BUTTON_3_BUTTON = new JoystickButton(this, BUTTON_3);%0A        BUTTON_4_BUTTON = new JoystickButton(this, BUTTON_4);%0A        BUTTON_9_BUTTON = new JoystickButton(this, BUTTON_9);%0A        BUTTON_10_BUTTON = new JoystickButton(this, BUTTON_10);%0A        LEFT_JOYSTICK_BUTTON_BUTTON = new JoystickButton(this, LEFT_JOYSTICK_BUTTON);%0A        RIGHT_JOYSTICK_BUTTON_BUTTON = new JoystickButton(this, RIGHT_JOYSTICK_BUTTON
 );%0A 

Add JoystickButton objects to Gamepad.