src/main/java/com/kennedyrobotics/hardware/leds/ctre/ICANdle.java
<reponame>nowireless/TurretSwervepackage com.kennedyrobotics.hardware.leds.ctre;

import com.ctre.phoenix.ErrorCode;
import com.ctre.phoenix.ParamEnum;
import com.ctre.phoenix.led.*;

public interface ICANdle {

    /**
     * Gets the Voltage of VBat as measured by CANdle
     * @return Voltage of VBat
     */
    public double getBusVoltage();

    /**
     * Gets the Voltage of the 5V line as measured by CANdle
     * @return Voltage of the 5V line
     */
    public double get5VRailVoltage();

    /**
     * Gets the low-side current as measured by CANdle
     * @return Current in Amps
     */
    public double getCurrent();

    /**
     * Gets the temperature of the CANdle in Celcius
     * @return Temperature in Celcius
     */
    public double getTemperature();

    /**
     * Gets the applied vbat modulation in percent.
     * If the CANdle is configured to always enable VBat, this returns 1
     * If the CANdle is confgigured to always disable VBat, this returns 0
     * Otherwise it returns the last set Modulation as a value [0, 1]
     * @return VBat Output Modulation
     */
    public double getVBatModulation();

    /**
     * Gets the maximum number of simultaneous animations this version of CANdle firmware supports.
     * If you specify an animation slot >= to this return, Phoenix will error out.
     * You can also get the maximum count from a self-test snapshot.
     * @return Maximum number of simultaneous animations this version of firmware supports.
     */
    public int getMaxSimultaneousAnimationCount();

    /**
     * Animates the CANdle with the passed-in animation
     * If the animation changes after calling this function,
     *  it must be passed into animate again for the changes to take effect
     * @param animation The animation that CANdle will run. If this is null, it will clear the animation at the specified slot
     * @return ErrorCode generated by function. OK indicates no error.
     */
    public ErrorCode animate(Animation animation);

    /**
     * Animates the CANdle with the passed-in animation
     * If the animation changes after calling this function,
     *  it must be passed into animate again for the changes to take effect
     * @param animation The animation that CANdle will run. If this is null, it will clear the animation at the specified slot
     * @param animSlot The animation slot to use for the animation, range is [0, getMaxSimultaneousAnimationCount()) exclusive
     * @return ErrorCode generated by function. OK indicates no error.
     */
    public ErrorCode animate(Animation animation, int animSlot);

    /**
     * Clears the animation occurring in the selected selected animSlot.
     * @param animSlot Animation slot to clear
     * @return ErrorCode generated by function. OK indicates no error.
     */
    public ErrorCode clearAnimation(int animSlot);

    /**
     * Sets a block of LEDs to the specified color
     * @param r The amount of Red to set, range is [0, 255]
     * @param g The amount of Green to set, range is [0, 255]
     * @param b The amount of Blue to set, range is [0, 255]
     * @param w The amount of White to set, range is [0, 255]. This only applies for LED strips with white in them.
     * @param startIdx Where to start setting the LEDs
     * @param count The number of LEDs to apply this to
     * @return ErrorCode generated by function. OK indicates no error.
     */
    public ErrorCode setLEDs(int r, int g, int b, int w, int startIdx, int count);

    /**
     * Sets a block of LEDs to the specified color.
     * @param r The amount of Red to set, range is [0, 255]
     * @param g The amount of Green to set, range is [0, 255]
     * @param b The amount of Blue to set, range is [0, 255]
     * @return ErrorCode generated by function. OK indicates no error.
     */
    public ErrorCode setLEDs(int r, int g, int b);

    /**
     * Modulates the VBat output to the specified duty cycle percentage
     * This function will only do something if the CANdle's VBatOutput is configured to Modulated
     * @param dutyCyclePrcnt The duty cycle of the output modulation [0, 1]
     * @return ErrorCode generated by function. OK indicates no error.
     */
    public ErrorCode modulateVBatOutput(double dutyCyclePrcnt);

    /**
     * Configures what the CANdle should do if it loses communications to the Controller
     * @param disableWhenLOS Set to true to disable the LEDs on Loss of Signal.
     * @param timeoutMs
     *            Timeout value in ms. If nonzero, function will wait for
     *            config success and report an error if it times out.
     *            If zero, no blocking or checking is performed.
     * @return ErrorCode generated by function. OK indicates no error.
     */
    public ErrorCode configLOSBehavior(boolean disableWhenLOS, int timeoutMs);

    /**
     * Configures what the CANdle should do if it loses communications to the Controller
     * @param disableWhenLOS Set to true to disable the LEDs on Loss of Signal.
     * @return ErrorCode generated by function. OK indicates no error.
     */
    public ErrorCode configLOSBehavior(boolean disableWhenLOS);

    /**
     * Configures the type of LED the CANdle controls
     * @param type The type of the LEDs the CANdle controls
     * @param timeoutMs
     *            Timeout value in ms. If nonzero, function will wait for
     *            config success and report an error if it times out.
     *            If zero, no blocking or checking is performed.
     * @return ErrorCode generated by function. OK indicates no error.
     */
    public ErrorCode configLEDType(com.ctre.phoenix.led.CANdle.LEDStripType type, int timeoutMs);

    /**
     * Configures the type of LED the CANdle controls
     * @param type The type of the LEDs the CANdle controls
     * @return ErrorCode generated by function. OK indicates no error.
     */
    public ErrorCode configLEDType(com.ctre.phoenix.led.CANdle.LEDStripType type);

    /**
     * Configures the brightness scalar to be applied to every LED output.
     * This value is bounded to [0, 1].
     *
     * Setting this to 1 will allow the LEDs to function at max brightness.
     * Setting this to 0.5 will scale all values to half their applied value.
     * Setting this to 0 will turn off the LEDs.
     *
     * Forcing the LEDs off this way may be useful in certain testing circumstances
     * but is generally not necessary. Self-test (Tuner) may be used to verify what
     * the effective scalar is in case user forgot to restore the scalar to a
     * non-zero value.
     *
     * @param brightness Value from [0, 1] that will scale the LED output.
     * @param timeoutMs
    Timeout value in ms. If nonzero, function will wait for
    config success and report an error if it times out.
    If zero, no blocking or checking is performed.
     * @return Error Code generated by function. 0 indicates no error.
     */
    public ErrorCode configBrightnessScalar(double brightness, int timeoutMs);

    /**
     * Configures the brightness scalar to be applied to every LED output.
     * This value is bounded to [0, 1].
     *
     * Setting this to 1 will allow the LEDs to function at max brightness.
     * Setting this to 0.5 will scale all values to half their applied value.
     * Setting this to 0 will turn off the LEDs.
     *
     * Forcing the LEDs off this way may be useful in certain testing circumstances
     * but is generally not necessary. Self-test (Tuner) may be used to verify what
     * the effective scalar is in case user forgot to restore the scalar to a
     * non-zero value.
     *
     * @param brightness Value from [0, 1] that will scale the LED output.
     * @return Error Code generated by function. 0 indicates no error.
     */
    public ErrorCode configBrightnessScalar(double brightness);

    /**
     * Configures how the status led will behave when the CANdle is actively controlling LEDs
     * If the CANdle is LOS or not actively commanded a value, it will always turn on its status LED.
     * @param disableWhenRunning Disables the status LED when the CANdle is running
     * @param timeoutMs
    Timeout value in ms. If nonzero, function will wait for
    config success and report an error if it times out.
    If zero, no blocking or checking is performed.
     * @return Error Code generated by function. 0 indicates no error.
     */
    public ErrorCode configStatusLedState(boolean disableWhenRunning, int timeoutMs);

    /**
     * Configures how the status led will behave when the CANdle is actively controlling LEDs
     * If the CANdle is LOS or not actively commanded a value, it will always turn on its status LED.
     * @param disableWhenRunning Disables the status LED when the CANdle is running
     * @return Error Code generated by function. 0 indicates no error.
     */
    public ErrorCode configStatusLedState(boolean disableWhenRunning);

    /**
     * Configures how the VBat Output will behave
     * @param mode VBat Output Behavior
     * @param timeoutMs
    Timeout value in ms. If nonzero, function will wait for
    config success and report an error if it times out.
    If zero, no blocking or checking is performed.
     * @return Error Code generated by function. 0 indicates no error.
     */
    public ErrorCode configVBatOutput(com.ctre.phoenix.led.CANdle.VBatOutputMode mode, int timeoutMs);

    /**
     * Configures how the VBat Output will behave
     * @param mode VBat Output Behavior
     * @return Error Code generated by function. 0 indicates no error.
     */
    public ErrorCode configVBatOutput(com.ctre.phoenix.led.CANdle.VBatOutputMode mode);

    /**
     * Configures the enable state for the 5V rail. This also affects the on-board LEDs.
     * @param enable5V True to enable the 5V rail.
     * @param timeoutMs
     *            Timeout value in ms. If nonzero, function will wait for
     *            config success and report an error if it times out.
     *            If zero, no blocking or checking is performed.
     * @return ErrorCode generated by function. OK indicates no error.
     */
    public ErrorCode configV5Enabled(boolean enable5V, int timeoutMs);

    /**
     * Configures the enable state for the 5V rail. This also disables the on-board LEDs.
     * @param enable5V True to enable the 5V rail.
     * @return ErrorCode generated by function. OK indicates no error.
     */
    public ErrorCode configV5Enabled(boolean enable5V);

    /**
     * Gets a parameter. Generally this is not used.
     * This can be utilized in
     * - Using new features without updating API installation.
     * - Errata workarounds to circumvent API implementation.
     * - Allows for rapid testing / unit testing of firmware.
     *
     * @param param
     *            Parameter enumeration.
     * @param ordinal
     *            Ordinal of parameter.
     * @param timeoutMs
     *            Timeout value in ms. If nonzero, function will wait for
     *            config success and report an error if it times out.
     *            If zero, no blocking or checking is performed.
     * @return Value of parameter.
     */
    public double configGetParameter(ParamEnum param, int ordinal, int timeoutMs);

    /**
     * Gets a parameter. Generally this is not used.
     * This can be utilized in
     * - Using new features without updating API installation.
     * - Errata workarounds to circumvent API implementation.
     * - Allows for rapid testing / unit testing of firmware.
     *
     * @param param
     *            Parameter enumeration.
     * @param ordinal
     *            Ordinal of parameter.
     * @return Value of parameter.
     */
    public double configGetParameter(ParamEnum param, int ordinal);

    /**
     * Sets a parameter. Generally this is not used.
     * This can be utilized in
     * - Using new features without updating API installation.
     * - Errata workarounds to circumvent API implementation.
     * - Allows for rapid testing / unit testing of firmware.
     *
     * @param param
     *            Parameter enumeration.
     * @param value
     *            Value of parameter.
     * @param subValue
     *            Subvalue for parameter. Maximum value of 255.
     * @param ordinal
     *            Ordinal of parameter.
     * @param timeoutMs
     *            Timeout value in ms. If nonzero, function will wait for
     *            config success and report an error if it times out.
     *            If zero, no blocking or checking is performed.
     * @return Error Code generated by function. 0 indicates no error.
     */
    public ErrorCode configSetParameter(ParamEnum param, double value, int subValue, int ordinal, int timeoutMs);

    /**
     * Sets a parameter. Generally this is not used.
     * This can be utilized in
     * - Using new features without updating API installation.
     * - Errata workarounds to circumvent API implementation.
     * - Allows for rapid testing / unit testing of firmware.
     *
     * @param param
     *            Parameter enumeration.
     * @param value
     *            Value of parameter.
     * @param subValue
     *            Subvalue for parameter. Maximum value of 255.
     * @param ordinal
     *            Ordinal of parameter.
     * @return Error Code generated by function. 0 indicates no error.
     */
    public ErrorCode configSetParameter(ParamEnum param, double value, int subValue, int ordinal);

    /**
     * Gets the value of a custom parameter. This is for arbitrary use.
     *
     * Sometimes it is necessary to save calibration/duty cycle/output
     * information in the device. Particularly if the
     * device is part of a subsystem that can be replaced.
     *
     * @param paramIndex
     *            Index of custom parameter. [0-1]
     * @param timeoutMs
     *            Timeout value in ms. If nonzero, function will wait for
     *            config success and report an error if it times out.
     *            If zero, no blocking or checking is performed.
     * @return Value of the custom param.
     */
    public int configGetCustomParam(int paramIndex, int timeoutMs);

    /**
     * Gets the value of a custom parameter. This is for arbitrary use.
     *
     * Sometimes it is necessary to save calibration/duty cycle/output
     * information in the device. Particularly if the
     * device is part of a subsystem that can be replaced.
     *
     * @param paramIndex
     *            Index of custom parameter. [0-1]
     * @return Value of the custom param.
     */
    public int configGetCustomParam(int paramIndex);

    /**
     * Sets the value of a custom parameter. This is for arbitrary use.
     *
     * Sometimes it is necessary to save calibration/duty cycle/output
     * information in the device. Particularly if the
     * device is part of a subsystem that can be replaced.
     *
     * @param paramIndex
     *            Index of custom parameter. [0-1]
     * @param value
     *            Value for custom parameter.
     * @param timeoutMs
     *            Timeout value in ms. If nonzero, function will wait for
     *            config success and report an error if it times out.
     *            If zero, no blocking or checking is performed.
     * @return Error Code generated by function. 0 indicates no error.
     */
    public ErrorCode configSetCustomParam(int paramIndex, int value, int timeoutMs);

    /**
     * Sets the value of a custom parameter. This is for arbitrary use.
     *
     * Sometimes it is necessary to save calibration/duty cycle/output
     * information in the device. Particularly if the
     * device is part of a subsystem that can be replaced.
     *
     * @param paramIndex
     *            Index of custom parameter. [0-1]
     * @param value
     *            Value for custom parameter.
     * @return Error Code generated by function. 0 indicates no error.
     */
    public ErrorCode configSetCustomParam(int paramIndex, int value);

    /**
     * Configures all persistent settings to defaults.
     *
     * @param timeoutMs
     *              Timeout value in ms. If nonzero, function will wait for
     *              config success and report an error if it times out.
     *              If zero, no blocking or checking is performed.
     *
     * @return Error Code generated by function. 0 indicates no error.
     */
    public ErrorCode configFactoryDefault(int timeoutMs);

    /**
     * Configures all persistent settings to defaults.
     *
     * @return Error Code generated by function. 0 indicates no error.
     */
    public ErrorCode configFactoryDefault();

    /**
     * Gets the CANdle fault status
     *
     * @param toFill Container for fault statuses.
     * @return Error Code generated by function. OK indicates no error.
     */
    public ErrorCode getFaults(CANdleFaults toFill);

    /**
     * Gets the CANdle sticky fault status
     *
     * @param toFill Container for sticky fault statuses.
     * @return Error Code generated by function. OK indicates no error.
     */
    public ErrorCode getStickyFaults(CANdleStickyFaults toFill);

    /**
     * Clears the sticky faults.
     *
     * @param timeoutMs
     *            Timeout value in ms. If nonzero, function will wait for
     *            config success and report an error if it times out.
     *            If zero, no blocking or checking is performed.
     * @return Error Code generated by function. 0 indicates no error.
     */
    public ErrorCode clearStickyFaults(int timeoutMs);

    /**
     * Clears the sticky faults.
     *
     * @return Error Code generated by function. 0 indicates no error.
     */
    public ErrorCode clearStickyFaults();

    /**
     * Returns true if the device has reset since last call.
     *
     * @return Has a Device Reset Occurred?
     */
    public boolean hasResetOccurred();

    /**
     * Sets the period of the given status frame.
     *
     * @param frame
     *            Frame whose period is to be changed.
     * @param periodMs
     *            Period in ms for the given frame.
     * @param timeoutMs
     *            Timeout value in ms. If nonzero, function will wait for
     *            config success and report an error if it times out.
     *            If zero, no blocking or checking is performed.
     * @return Error Code generated by function. 0 indicates no error.
     */
    public ErrorCode setStatusFramePeriod(CANdleStatusFrame frame, int periodMs, int timeoutMs);

    /**
     * Sets the period of the given status frame.
     *
     * @param frame
     *            Frame whose period is to be changed.
     * @param periodMs
     *            Period in ms for the given frame.
     * @return Error Code generated by function. 0 indicates no error.
     */
    public ErrorCode setStatusFramePeriod(CANdleStatusFrame frame, int periodMs);

    /**
     * Gets the period of the given status frame.
     *
     * @param frame
     *            Frame to get the period of.
     * @param timeoutMs
     *            Timeout value in ms. If nonzero, function will wait for
     *            config success and report an error if it times out.
     *            If zero, no blocking or checking is performed.
     * @return Period of the given status frame.
     */
    public int getStatusFramePeriod(CANdleStatusFrame frame, int timeoutMs);

    /**
     * Gets the period of the given status frame.
     *
     * @param frame
     *            Frame to get the period of.
     * @return Period of the given status frame.
     */
    public int getStatusFramePeriod(CANdleStatusFrame frame);

    /**
     * Sets the period of the given control frame.
     *
     * @param frame
     *            Frame whose period is to be changed.
     * @param periodMs
     *            Period in ms for the given frame.
     * @return Error Code generated by function. 0 indicates no error.
     */
    public ErrorCode setControlFramePeriod(CANdleControlFrame frame, int periodMs);

    /**
     * Configures all persistent settings.
     *
     * @param allConfigs        Object with all of the persistant settings
     * @param timeoutMs
     *              Timeout value in ms. If nonzero, function will wait for
     *              config success and report an error if it times out.
     *              If zero, no blocking or checking is performed.
     * @return Error Code generated by function. 0 indicates no error.
     */
    public ErrorCode configAllSettings(CANdleConfiguration allConfigs, int timeoutMs);

    /**
     * Configures all persistent settings.
     *
     * @param allConfigs        Object with all of the persistant settings
     * @return Error Code generated by function. 0 indicates no error.
     */
    public ErrorCode configAllSettings(CANdleConfiguration allConfigs);

    /**
     * Gets all persistant settings.
     *
     * @param allConfigs        Object with all of the persistant settings
     * @param timeoutMs
     *              Timeout value in ms. If nonzero, function will wait for
     *              config success and report an error if it times out.
     *              If zero, no blocking or checking is performed.
     */
    public void getAllConfigs(CANdleConfiguration allConfigs, int timeoutMs);

    /**
     * Gets all persistant settings.
     *
     * @param allConfigs        Object with all of the persistant settings
     */
    public void getAllConfigs(CANdleConfiguration allConfigs);

    /**
     * Call GetLastError() generated by this object.
     * Not all functions return an error code but can
     * potentially report errors.
     *
     * This function can be used to retrieve those error codes.
     *
     * @return The last ErrorCode generated.
     */
    public ErrorCode getLastError();
}
