// RobotBuilder Version: 1.0
//
// This file was generated by RobotBuilder. It contains sections of
// code that are automatically generated and assigned by robotbuilder.
// These sections will be updated in the future when you export to
// Java from RobotBuilder. Do not put any code or make any change in
// the blocks indicating autogenerated code or it will be lost on an
// update. Deleting the comments indicating the section will prevent
// it from being updated in the future.
package org.usfirst.frc330.Beachbot2014Java.subsystems;
import org.usfirst.frc330.Beachbot2014Java.RobotMap;
import org.usfirst.frc330.Beachbot2014Java.commands.*;
import edu.wpi.first.wpilibj.*;
import edu.wpi.first.wpilibj.command.Subsystem;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
import org.usfirst.frc330.Beachbot2014Java.Robot;
/**
 *
 */
public class Wings extends Subsystem {
    // BEGIN AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=DECLARATIONS
    DoubleSolenoid wingSolenoid = RobotMap.wingsWingSolenoid;
    DigitalInput wingLeftLimitSwitch = RobotMap.wingsWingLeftLimitSwitch;
    DigitalInput wingRightLimitSwitch = RobotMap.wingsWingRightLimitSwitch;
    // END AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=DECLARATIONS
    
    // Put methods for controlling this subsystem
    // here. Call these from Commands.
    public void initDefaultCommand() {
        // BEGIN AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=DEFAULT_COMMAND
    // END AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=DEFAULT_COMMAND
	
        // Set the default command for a subsystem here.
        //setDefaultCommand(new MySpecialCommand());
    }
    
    public Wings() {
        SmartDashboard.putBoolean("WingsOverride", false);
    }
    
    public boolean areWingsOpenUnsafe() {
        return wingSolenoid.get() == DoubleSolenoid.Value.kForward;
    }
    
    public boolean areWingsOpen()
    {
        if (wingSolenoid.get() == DoubleSolenoid.Value.kForward
                && (wingOpenTime + getWingsOpenWait()) < Timer.getFPGATimestamp()
                && ((wingLeftLimitSwitch.get() == true && wingRightLimitSwitch.get() == true)
                || SmartDashboard.getBoolean("WingsOverride", false)))
            return true;
        else
            return false;
    }
    
    public void toggleWings()
    {
        if (wingSolenoid.get() == DoubleSolenoid.Value.kForward) {
            setWingsClose();
        }
        else {
            setWingsOpen();
        }
    }
    private double wingOpenTime;
    
    public double getWingOpenTime()
    {
        return wingOpenTime;
    }
    
    public void setWingsOpen()
    {
        if (wingSolenoid.get() != DoubleSolenoid.Value.kForward) {
            wingOpenTime = Timer.getFPGATimestamp();
            wingSolenoid.set(DoubleSolenoid.Value.kForward);
        }
    }
        
    public void setWingsClose()
    {
        if (Robot.arm.areWingsSafeToClose())
            wingSolenoid.set(DoubleSolenoid.Value.kReverse);
    }
 
    public double getWingsOpenWait() {
        double wingsOpenWait = 0.75;
        if (Preferences.getInstance().containsKey("WingsOpenWait"))
        {
            wingsOpenWait = Preferences.getInstance().getDouble(
                            "WingsOpenWait",wingsOpenWait);
        } else 
        {
            Preferences.getInstance().putDouble("WingsOpenWait", 
                                                wingsOpenWait);
            Preferences.getInstance().save();
        }
        return wingsOpenWait;
    }
    
}

@@ -1649,24 +1649,41 @@
 c Wings() %7B%0A
+        super();%0A
         Smar
@@ -2097,19 +2097,20 @@
 et() == 
-tru
+fals
 e && win
@@ -2136,19 +2136,20 @@
 et() == 
-tru
+fals
 e)%0A     

fix wings limit switch direction