package org.dirtymechanics.frc.actuator;

import edu.wpi.first.wpilibj.Solenoid;
import org.dirtymechanics.frc.util.Updatable;

/**
 * Controls a double solenoid with logic to debounce input and disable redundant
 * relays to conserve power.
 *
 * @author Daniel Ruess
 */
public class DoubleSolenoid implements Updatable {

    /**
     * The time to wait after firing to disable the open valve.
     */
    private static final int FIRE_WAIT = 1000;

    /**
     * The spike controlling the opening of the valve.
     */
    private final Solenoid openSpike;
    /**
     * The spike controlling the closing of the valve.
     */
    private final Solenoid closeSpike;
    /**
     * The state of the solenoid.
     */
    private boolean state;
    /**
     * Whether or not the state has changes.
     */
    private boolean stateChanged = true;
    /**
     * The time of the last state change.
     */
    private long lastStateChange;

    /**
     * Creates a new double solenoid with a 1000ms debounce and initial state of
     * false.
     *
     * @param openSpike The spike controlling the open valve.
     * @param closeSpike The spike controlling the close valve.
     */
    public DoubleSolenoid(Solenoid openSpike, Solenoid closeSpike) {
        this(openSpike, closeSpike, false);
    }

    /**
     * Creates a new double solenoid.
     *
     * @param openSpike The spike controlling the open valve.
     * @param closeSpike The spike controlling the close valve.
     * @param initialState The initial state to start in.
     */
    public DoubleSolenoid(Solenoid openSpike, Solenoid closeSpike, boolean initialState) {
        this.openSpike = openSpike;
        this.closeSpike = closeSpike;
        this.state = initialState;
    }

    /**
     * Sets the state of the solenoid. True being open, false being close.
     *
     * @param state The state of the solenoid.
     */
    public void set(boolean state) {
        if (this.state != state) {
            stateChanged = true;
        }
        this.state = state;
    }

    /**
     * Inverts the state.
     */
    public void flip() {
        set(!state);
    }

    public void setOpen() {
        set(true);
    }

    public void setClosed() {
        set(false);
    }

    /**
     * Called per cycle to update the state of the valves.
     */
    public void update() {
        if (state) {
            openSpike.set(true);
            closeSpike.set(false);
        } else {
            openSpike.set(false);
            closeSpike.set(true);
        }
    }
}

@@ -124,1068 +124,163 @@
 le;%0A
-%0A/**%0A * Controls a double solenoid with logic to debounce input and disable redundant%0A * relays to conserve power.%0A *%0A * @author Daniel Ruess%0A */%0Apublic class DoubleSolenoid implements Updatable %7B%0A%0A    /**%0A     * The time to wait after firing to disable the open valve.%0A     */%0A    private static final int FIRE_WAIT = 1000;%0A%0A    /**%0A     * The spike controlling the opening of the valve.%0A     */%0A    private final Solenoid openSpike;%0A    /**%0A     * The spike controlling the closing of the valve.%0A     */%0A    private final Solenoid closeSpike;%0A    /**%0A     * The state of the solenoid.%0A     */%0A    private boolean state;%0A    /**%0A     * Whether or not the state has changes.%0A     */%0A    private boolean stateChanged = true;%0A    /**%0A     * The time of the last state change.%0A     */%0A    private long lastStateChange;%0A%0A    /**%0A     * Creates a new double solenoid with a 1000ms debounce and initial state of%0A     * false.%0A     *%0A     * @param openSpike The spike controlling the open valve.%0A     * @param closeSpike The spike controlling the close valve.%0A     */
+public class DoubleSolenoid implements Updatable %7B%0A    private final Solenoid openSpike;%0A    private final Solenoid closeSpike;%0A    private boolean state;%0A
 %0A   
@@ -606,38 +606,8 @@
 ate 
-The initial state to start in.
 %0A   
@@ -1004,86 +1004,8 @@
 ) %7B%0A
-        if (this.state != state) %7B%0A            stateChanged = true;%0A        %7D%0A
     

remove dead code