package com.thegongoliers.commands;

import com.thegongoliers.hardware.Hardware;
import com.thegongoliers.input.current.HighCurrentSensor;
import edu.wpi.first.wpilibj.buttons.Trigger;
import edu.wpi.first.wpilibj.command.Command;

import java.util.function.DoubleSupplier;

/**
 * This class contains several helper methods to ensure safe operation of the robot (aka. prevents stuff from breaking)
 */
public class SafetyCommands {

    private SafetyCommands(){}

    /**
     * Runs a command when the current is too high
     * @param currentSensor the high current sensor
     * @param command the command to run
     * @return the trigger that is binded to the high current sensor (was set to automatically start command already)
     */
    public static Trigger whenHighCurrent(HighCurrentSensor currentSensor, Command command){
        Trigger trigger = Hardware.makeTrigger(currentSensor::isTriggered);
        trigger.whenActive(command);
        return trigger;
    }

    /**
     * Runs a command when the value exceeds the range
     * @param value a function which retrieves a value
     * @param minimum the minimum the value can be (inclusive)
     * @param maximum the maximum the value can be (inclusive)
     * @param command the command to run
     * @return the trigger that is binded to the range (was set to automatically start command already)
     */
    public static Trigger whenOutOfBounds(DoubleSupplier value, double minimum, double maximum, Command command){
        Trigger trigger = Hardware.makeTrigger(() -> value.getAsDouble() < minimum || value.getAsDouble() > maximum);
        trigger.whenActive(command);
        return trigger;
    }

}

@@ -974,16 +974,534 @@
 %0A    %7D%0A%0A
+    /**%0A     * Runs a command while the current is too high%0A     * @param currentSensor the high current sensor%0A     * @param command the command to run%0A     * @return the trigger that is binded to the high current sensor (was set to automatically start command already)%0A     */%0A    public static Trigger whileHighCurrent(HighCurrentSensor currentSensor, Command command)%7B%0A        Trigger trigger = Hardware.makeTrigger(currentSensor::isTriggered);%0A        trigger.whileActive(command);%0A        return trigger;%0A    %7D%0A%0A
     /**%0A
@@ -2189,10 +2189,710 @@
 %0A    %7D%0A%0A
+    /**%0A     * Runs a command while the value exceeds the range%0A     * @param value a function which retrieves a value%0A     * @param minimum the minimum the value can be (inclusive)%0A     * @param maximum the maximum the value can be (inclusive)%0A     * @param command the command to run%0A     * @return the trigger that is binded to the range (was set to automatically start command already)%0A     */%0A    public static Trigger whileOutOfBounds(DoubleSupplier value, double minimum, double maximum, Command command)%7B%0A        Trigger trigger = Hardware.makeTrigger(() -%3E value.getAsDouble() %3C minimum %7C%7C value.getAsDouble() %3E maximum);%0A        trigger.whileActive(command);%0A        return trigger;%0A    %7D%0A%0A
 %7D%0A

Add while active states to the safety commands