package org.usfirst.frc.team4342.api.pnuematics;

import org.usfirst.frc.team4342.api.logging.ExceptionInfo;
import org.usfirst.frc.team4342.robot.components.Repository;

import edu.wpi.first.wpilibj.DigitalInput;
import edu.wpi.first.wpilibj.Relay;
import edu.wpi.first.wpilibj.Relay.Value;

/**
 * This class is for controlling a compressor
 */
public class Compressor 
{
	private static boolean enabled;
	private static boolean run;
	
	/**
	 * Spawns a thread that automatically checks if the compressor should be on
	 */
	public static void startAutomaticMode(Relay relay, DigitalInput pSwitch)
	{
		if(run)
			return;
		
		run = true;
		
		Thread t = new Thread(new Runnable() 
		{
			@Override
			public void run()
			{
				while(run)
				{
					try
					{
						double velocity = Math.sqrt(Math.pow(Repository.Navx.getVelocityX(), 2) + Math.pow(Repository.Navx.getVelocityY(), 2));
						double throttle = Math.sqrt(Math.pow(Repository.DriveStick.getX(), 2) + Math.pow(Repository.DriveStick.getY(), 2));
						double ratio = (velocity/throttle);
						double PUSH_VALUE = 20;
						
						if(pSwitch.get() || (ratio < PUSH_VALUE)
						{
							relay.set(Value.kOff);
							enabled = false;
						}
						else
						{
							relay.set(Value.kForward);
							enabled = true;
						}
						
						Thread.sleep(100);
					}
					catch(Exception ex)
					{
						Repository.Logs.error(
							"Unexpected error with compressor (" + ExceptionInfo.getType(ex) + ")", 
							ex
						);
						
						break;
					}
				}
			}
		});
		
		t.start();
	}
	
	public static void stopAutomaticMode()
	{
		run = false;
	}
	
	/**
	 * Determine if the compressor is disabled
	 * @return true if the compressor is off, false otherwise
	 */
	public synchronized boolean isDisabled()
	{
		return !enabled;
	}
	
	/**
	 * Determine if the compressor is enabled
	 * @return true if the compressor is on, false otherwise
	 */
	public synchronized boolean isEnabled()
	{
		return enabled;
	}
}

@@ -758,24 +758,30 @@
 %09%09%09%09%7B%0A%09%09%09%09%09%09
+final 
 double veloc
@@ -890,24 +890,30 @@
  2));%0A%09%09%09%09%09%09
+final 
 double throt
@@ -1018,24 +1018,30 @@
  2));%0A%09%09%09%09%09%09
+final 
 double ratio
@@ -1070,16 +1070,22 @@
 ;%0A%09%09%09%09%09%09
+final 
 double P
@@ -1098,16 +1098,18 @@
 LUE = 20
+.0
 ;%0A%09%09%09%09%09%09
@@ -1155,16 +1155,17 @@
 H_VALUE)
+)
 %0A%09%09%09%09%09%09%7B

Update Compressor.java