// Path: src/com/limelight/input/Device.java
// public class Device {
// 	private int id;
// 	private int numButtons;
// 	private int numAxes;
// 	
// 	public Device(int deviceID, int numButtons, int numAxes) {
// 		this.id = deviceID;
// 		this.numButtons = numButtons;
// 		this.numAxes = numAxes;
// 	}
// 	
// 	public int getId() {
// 		return id;
// 	}
// 	
// 	public int getNumButtons() {
// 		return numButtons;
// 	}
// 	
// 	public int getNumAxes() {
// 		return numAxes;
// 	}
// 	
// 	@Override
// 	public int hashCode() {
// 		return id;
// 	}
// 	
// 	@Override
// 	public boolean equals(Object o) {
// 		return (o instanceof Device && ((Device) o).id == id);
// 	}
// }
// 
// Path: src/com/limelight/input/DeviceListener.java
// public interface DeviceListener {
// 	public void handleButton(Device device, int buttonId, boolean pressed);
// 	public void handleAxis(Device device, int axisId, float newValue, float lastValue);
// 	public void handleDeviceAdded(Device device);
// 	public void handleDeviceRemoved(Device device);
// }
// 
// Path: src/com/limelight/input/gamepad/GamepadMapping.java
// public class Mapping implements Serializable {
// 	private static final long serialVersionUID = -8407172977953214242L;
// 		
// 	/**
// 	 * The component this mapping belongs to
// 	 */
// 	public GamepadComponent padComp;
// 		
// 	/**
// 	 * Whether the value of this component should be inverted
// 	 */
// 	public boolean invert;
// 		
// 	/**
// 	 * Whether this component should be treated as a trigger
// 	 */
// 	public boolean trigger;
// 		
// 	/**
// 	 * Constructs a new mapping with the specified configuration
// 	 * @param padComp the component this mapping belongs to
// 	 * @param invert whether the value should be inverted
// 	 * @param trigger whether this component should be treated as a trigger
// 	 */
// 	public Mapping(GamepadComponent padComp, boolean invert, boolean trigger) {
// 		this.padComp = padComp;
// 		this.invert = invert;
// 		this.trigger = trigger;
// 	}
// }


import java.util.HashMap;
import com.limelight.LimeLog;
import com.limelight.input.Device;
import com.limelight.input.DeviceListener;
import com.limelight.input.gamepad.GamepadMapping.Mapping;
import com.limelight.input.gamepad.SourceComponent.Direction;
import com.limelight.input.gamepad.SourceComponent.Type;
import com.limelight.nvstream.NvConnection;
import com.limelight.nvstream.input.ControllerPacket;
import com.limelight.settings.GamepadSettingsManager;
				if ((currentControllers & (1 << i)) == 0) {
					currentControllers |= (1 << i);
					LimeLog.info("Assigned controller "+i);
					controllerNumber = i;
					return;
				}
			}
			
			controllerNumber = 0;
			LimeLog.info("No controller numbers left; using 0");
		}
		
		public void releaseControllerNumber() {
			LimeLog.info("Controller "+controllerNumber+" is now available");
			currentControllers &= ~(1 << controllerNumber);
		}
	}

	private NvConnection conn;
	private HashMap<Device, Gamepad> gamepads = new HashMap<Device, Gamepad>();
	private int currentControllers;

	public GamepadHandler(NvConnection conn) {
		this.conn = conn;
	}

	public GamepadHandler() {
		this(null);
	}
	
// Path: src/com/limelight/input/Device.java
// public class Device {
// 	private int id;
// 	private int numButtons;
// 	private int numAxes;
// 	
// 	public Device(int deviceID, int numButtons, int numAxes) {
// 		this.id = deviceID;
// 		this.numButtons = numButtons;
// 		this.numAxes = numAxes;
// 	}
// 	
// 	public int getId() {
// 		return id;
// 	}
// 	
// 	public int getNumButtons() {
// 		return numButtons;
// 	}
// 	
// 	public int getNumAxes() {
// 		return numAxes;
// 	}
// 	
// 	@Override
// 	public int hashCode() {
// 		return id;
// 	}
// 	
// 	@Override
// 	public boolean equals(Object o) {
// 		return (o instanceof Device && ((Device) o).id == id);
// 	}
// }
// 
// Path: src/com/limelight/input/DeviceListener.java
// public interface DeviceListener {
// 	public void handleButton(Device device, int buttonId, boolean pressed);
// 	public void handleAxis(Device device, int axisId, float newValue, float lastValue);
// 	public void handleDeviceAdded(Device device);
// 	public void handleDeviceRemoved(Device device);
// }
// 
// Path: src/com/limelight/input/gamepad/GamepadMapping.java
// public class Mapping implements Serializable {
// 	private static final long serialVersionUID = -8407172977953214242L;
// 		
// 	/**
// 	 * The component this mapping belongs to
// 	 */
// 	public GamepadComponent padComp;
// 		
// 	/**
// 	 * Whether the value of this component should be inverted
// 	 */
// 	public boolean invert;
// 		
// 	/**
// 	 * Whether this component should be treated as a trigger
// 	 */
// 	public boolean trigger;
// 		
// 	/**
// 	 * Constructs a new mapping with the specified configuration
// 	 * @param padComp the component this mapping belongs to
// 	 * @param invert whether the value should be inverted
// 	 * @param trigger whether this component should be treated as a trigger
// 	 */
// 	public Mapping(GamepadComponent padComp, boolean invert, boolean trigger) {
// 		this.padComp = padComp;
// 		this.invert = invert;
// 		this.trigger = trigger;
// 	}
// }


// Path: src/com/limelight/input/gamepad/GamepadHandler.java
import java.util.HashMap;
import com.limelight.LimeLog;
import com.limelight.input.Device;
import com.limelight.input.DeviceListener;
import com.limelight.input.gamepad.GamepadMapping.Mapping;
import com.limelight.input.gamepad.SourceComponent.Direction;
import com.limelight.input.gamepad.SourceComponent.Type;
import com.limelight.nvstream.NvConnection;
import com.limelight.nvstream.input.ControllerPacket;
import com.limelight.settings.GamepadSettingsManager;

				if ((currentControllers & (1 << i)) == 0) {
					currentControllers |= (1 << i);
					LimeLog.info("Assigned controller "+i);
					controllerNumber = i;
					return;
				}
			}
			
			controllerNumber = 0;
			LimeLog.info("No controller numbers left; using 0");
		}
		
		public void releaseControllerNumber() {
			LimeLog.info("Controller "+controllerNumber+" is now available");
			currentControllers &= ~(1 << controllerNumber);
		}
	}

	private NvConnection conn;
	private HashMap<Device, Gamepad> gamepads = new HashMap<Device, Gamepad>();
	private int currentControllers;

	public GamepadHandler(NvConnection conn) {
		this.conn = conn;
	}

	public GamepadHandler() {
		this(null);
	}
	
	private Gamepad getGamepad(Device dev, boolean create) {