package org.frc4931.zach.drive;
import edu.wpi.first.wpilibj.Jaguar;
import edu.wpi.first.wpilibj.Sendable;
import edu.wpi.first.wpilibj.SpeedController;
import edu.wpi.first.wpilibj.Talon;
import edu.wpi.first.wpilibj.Victor;
import edu.wpi.first.wpilibj.tables.ITable;
/**
 * A class that represents a physical motor and its associated speed controller
 * @author zach
 *
 */
public class Motor implements Sendable{
	public static final int TALON_SPEED_CONTROLLER = 1;
	public static final int VICTOR_SPEED_CONTROLLER = 2;
	public static final int JAGUAR_SPEED_CONTROLLER = 3;
	
	protected final SpeedController controller;
	private final int channel;
	
	private final String type;
	private ITable table;
	
	/**
	 * Creates a motor class of the specified type on the given channel.
	 * @param channel the PWM output that the motor controller is connected to.
	 * @param type the name displayed in the SmartDashboard.  
	 * It must contain the case insensitive string "talon", "jaguar", 
	 * or "victor" depending on the type of the motor controller.
	 */
	public Motor(int channel, int type){
		this.type = ""+type;
		this.channel = channel;
		switch(type){
			case TALON_SPEED_CONTROLLER:
				controller = new Talon(channel);
				break;
			case VICTOR_SPEED_CONTROLLER:
				controller = new Victor(channel);
				break;
			case JAGUAR_SPEED_CONTROLLER:
				controller = new Jaguar(channel);
				break;
			default:
				controller = null;
				break;
		}
	}
	
	/**Set the speed of the motor as a double between -1.0 and 1.0.
	 * 
	 * @param speed the speed to set the motor to, between -1.0 and 1.0.
	 */
	public void setSpeed(double speed){
		controller.set(speed);
	}
	
	/**
	 * Returns the current speed of the motor as a double from -1.0 to 1.0.
	 * @return the speed of the motor from -1.0 to 1.0.
	 */
	public double getSpeed(){
		return controller.get();
	}
	
	/**
	 * Returns the class that represents the physical motor controller.
	 * @return the SpeedController that is attached to the motor.
	 */
	public SpeedController getController(){
		return controller;
	}
	
	public void stop(){
		setSpeed(0);
	}
	
	/*SmartDashboard Information*/
	//@Override
	public String getSmartDashboardType() {
		return type;
	}
	//@Override
	public ITable getTable() {
		return table;
	}
	//@Override
	public void initTable(ITable table) {
		 this.table = table;
		 if (table != null) {
			 table.putNumber("Speed", getSpeed());
			 table.putNumber("Channel", channel);
		 }
	}
}

@@ -1042,32 +1042,463 @@
 ontroller.%0A%09 */%0A
+%09public Motor(int channel, SpeedControllerType type)%7B%0A%09%09this.type = %22%22+type;%0A%09%09this.channel = channel;%0A%09%09if(type.equals(SpeedControllerType.TALON))%7B%0A%09%09%09controller = new Talon(channel);%0A%09%09%7Delse if(type.equals(SpeedControllerType.VICTOR))%7B%0A%09%09%09controller = new Victor(channel);%0A%09%09%7Delse if(type.equals(SpeedControllerType.JAGUAR))%7B%0A%09%09%09controller = new Jaguar(channel);%0A%09%09%7Delse%7B%0A%09%09%09controller = null;%0A%09%09%7D%0A%09%7D%0A%09%0A%09/**%0A%09 * @deprecated%0A%09 */%0A
 %09public Motor(in
@@ -2894,10 +2894,489 @@
 %09%09 %7D%0A%09%7D%0A
+%09public static class SpeedControllerType%7B%0A%09%09public static final SpeedControllerType TALON = new SpeedControllerType(0);%0A%09%09public static final SpeedControllerType VICTOR = new SpeedControllerType(1);%0A%09%09public static final SpeedControllerType JAGUAR = new SpeedControllerType(2);%0A%09%09%0A%09%09private final int value;%0A%09%09%0A%09%09private SpeedControllerType(int value)%7B%0A%09%09%09this.value = value;%0A%09%09%7D%0A%09%09%0A%09%09public boolean equals(SpeedControllerType motor)%7B%0A%09%09%09return this.value == motor.value;%0A%09%09%7D%0A%09%7D%0A
 %7D%0A

Modify Motor to use an enum to specify the type of speed controller