001/*
002 * Copyright (C) Cross The Road Electronics.  All rights reserved.
003 * License information can be found in CTRE_LICENSE.txt
004 * For support and suggestions contact support@ctr-electronics.com or file
005 * an issue tracker at https://github.com/CrossTheRoadElec/Phoenix-Releases
006 */
007package com.ctre.phoenixpro.configs;
008
009import com.ctre.phoenixpro.StatusCode;
010import com.ctre.phoenixpro.configs.jni.ConfigJNI;
011import com.ctre.phoenixpro.spns.*;
012
013/**
014 *  Configs that directly affect motor-output.
015 * <p>
016 *  Includes Motor Invert and various limit features.
017 */
018public class SoftwareLimitSwitchConfigs implements ParentConfiguration
019{
020    /**
021     * If enabled, the motor output is set to neutral if position exceeds
022     * ForwardSoftLimitThreshold and forward output is requested.
023     *
024     *  <ul>
025     *  <li> <b>Default Value:</b> False
026     *  </ul>
027     */
028    public boolean ForwardSoftLimitEnable = false;
029    /**
030     * If enabled, the motor output is set to neutral if position exceeds
031     * ReverseSoftLimitThreshold and reverse output is requested.
032     *
033     *  <ul>
034     *  <li> <b>Default Value:</b> False
035     *  </ul>
036     */
037    public boolean ReverseSoftLimitEnable = false;
038    /**
039     * Position threshold for forward soft limit features.
040     * ForwardSoftLimitEnable must be enabled for this to take effect.
041     *
042     *  <ul>
043     *  <li> <b>Minimum Value:</b> -3.4e+38
044     *  <li> <b>Maximum Value:</b> 3.4e+38
045     *  <li> <b>Default Value:</b> 0
046     *  <li> <b>Units:</b> rotations
047     *  </ul>
048     */
049    public double ForwardSoftLimitThreshold = 0;
050    /**
051     * Position threshold for reverse soft limit features.
052     * ReverseSoftLimitEnable must be enabled for this to take effect.
053     *
054     *  <ul>
055     *  <li> <b>Minimum Value:</b> -3.4e+38
056     *  <li> <b>Maximum Value:</b> 3.4e+38
057     *  <li> <b>Default Value:</b> 0
058     *  <li> <b>Units:</b> rotations
059     *  </ul>
060     */
061    public double ReverseSoftLimitThreshold = 0;
062
063    @Override
064    public String toString()
065    {
066        String ss = "Config Group: SoftwareLimitSwitch\n";
067        ss += "Name: \"ForwardSoftLimitEnable\" Value: \"" + ForwardSoftLimitEnable + "\"" + "\n";
068        ss += "Name: \"ReverseSoftLimitEnable\" Value: \"" + ReverseSoftLimitEnable + "\"" + "\n";
069        ss += "Name: \"ForwardSoftLimitThreshold\" Value: \"" + ForwardSoftLimitThreshold + "rotations\"" + "\n";
070        ss += "Name: \"ReverseSoftLimitThreshold\" Value: \"" + ReverseSoftLimitThreshold + "rotations\"" + "\n";
071        return ss;
072    }
073
074    /**
075     *
076     */
077    public StatusCode deserialize(String string)
078    {
079        ForwardSoftLimitEnable = ConfigJNI.Deserializeboolean(SpnValue.Config_ForwardSoftLimitEnable.value, string);
080        ReverseSoftLimitEnable = ConfigJNI.Deserializeboolean(SpnValue.Config_ReverseSoftLimitEnable.value, string);
081        ForwardSoftLimitThreshold = ConfigJNI.Deserializedouble(SpnValue.Config_ForwardSoftLimitThreshold.value, string);
082        ReverseSoftLimitThreshold = ConfigJNI.Deserializedouble(SpnValue.Config_ReverseSoftLimitThreshold.value, string);
083        return  StatusCode.OK;
084    }
085
086    /**
087     *
088     */
089    public String serialize()
090    {
091        String ss = "";
092        ss += ConfigJNI.Serializeboolean(1461, ForwardSoftLimitEnable);
093        ss += ConfigJNI.Serializeboolean(1462, ReverseSoftLimitEnable);
094        ss += ConfigJNI.Serializedouble(1463, ForwardSoftLimitThreshold);
095        ss += ConfigJNI.Serializedouble(1464, ReverseSoftLimitThreshold);
096        return ss;
097    }
098}
099