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.phoenix6.configs;
008
009import com.ctre.phoenix6.StatusCode;
010import com.ctre.phoenix6.configs.jni.ConfigJNI;
011import com.ctre.phoenix6.spns.*;
012
013/**
014 * Configs that affect how software-limit switches behave.
015 * <p>
016 * Includes enabling software-limit switches and the threshold at
017 * which they are tripped.
018 */
019public class SoftwareLimitSwitchConfigs implements ParentConfiguration
020{
021    /**
022     * If enabled, the motor output is set to neutral if position exceeds
023     * ForwardSoftLimitThreshold and forward output is requested.
024     * 
025     * <ul>
026     *   <li> <b>Default Value:</b> False
027     * </ul>
028     */
029    public boolean ForwardSoftLimitEnable = false;
030    /**
031     * If enabled, the motor output is set to neutral if position exceeds
032     * ReverseSoftLimitThreshold and reverse output is requested.
033     * 
034     * <ul>
035     *   <li> <b>Default Value:</b> False
036     * </ul>
037     */
038    public boolean ReverseSoftLimitEnable = false;
039    /**
040     * Position threshold for forward soft limit features.
041     * ForwardSoftLimitEnable must be enabled for this to take effect.
042     * 
043     * <ul>
044     *   <li> <b>Minimum Value:</b> -3.4e+38
045     *   <li> <b>Maximum Value:</b> 3.4e+38
046     *   <li> <b>Default Value:</b> 0
047     *   <li> <b>Units:</b> rotations
048     * </ul>
049     */
050    public double ForwardSoftLimitThreshold = 0;
051    /**
052     * Position threshold for reverse soft limit features.
053     * ReverseSoftLimitEnable must be enabled for this to take effect.
054     * 
055     * <ul>
056     *   <li> <b>Minimum Value:</b> -3.4e+38
057     *   <li> <b>Maximum Value:</b> 3.4e+38
058     *   <li> <b>Default Value:</b> 0
059     *   <li> <b>Units:</b> rotations
060     * </ul>
061     */
062    public double ReverseSoftLimitThreshold = 0;
063    
064    /**
065     * Modifies this configuration's ForwardSoftLimitEnable parameter and returns itself for
066     * method-chaining and easier to use config API.
067     * <p>
068     * If enabled, the motor output is set to neutral if position exceeds
069     * ForwardSoftLimitThreshold and forward output is requested.
070     * 
071     * <ul>
072     *   <li> <b>Default Value:</b> False
073     * </ul>
074     *
075     * @param newForwardSoftLimitEnable Parameter to modify
076     * @return Itself
077     */
078    public SoftwareLimitSwitchConfigs withForwardSoftLimitEnable(boolean newForwardSoftLimitEnable)
079    {
080        ForwardSoftLimitEnable = newForwardSoftLimitEnable;
081        return this;
082    }
083    /**
084     * Modifies this configuration's ReverseSoftLimitEnable parameter and returns itself for
085     * method-chaining and easier to use config API.
086     * <p>
087     * If enabled, the motor output is set to neutral if position exceeds
088     * ReverseSoftLimitThreshold and reverse output is requested.
089     * 
090     * <ul>
091     *   <li> <b>Default Value:</b> False
092     * </ul>
093     *
094     * @param newReverseSoftLimitEnable Parameter to modify
095     * @return Itself
096     */
097    public SoftwareLimitSwitchConfigs withReverseSoftLimitEnable(boolean newReverseSoftLimitEnable)
098    {
099        ReverseSoftLimitEnable = newReverseSoftLimitEnable;
100        return this;
101    }
102    /**
103     * Modifies this configuration's ForwardSoftLimitThreshold parameter and returns itself for
104     * method-chaining and easier to use config API.
105     * <p>
106     * Position threshold for forward soft limit features.
107     * ForwardSoftLimitEnable must be enabled for this to take effect.
108     * 
109     * <ul>
110     *   <li> <b>Minimum Value:</b> -3.4e+38
111     *   <li> <b>Maximum Value:</b> 3.4e+38
112     *   <li> <b>Default Value:</b> 0
113     *   <li> <b>Units:</b> rotations
114     * </ul>
115     *
116     * @param newForwardSoftLimitThreshold Parameter to modify
117     * @return Itself
118     */
119    public SoftwareLimitSwitchConfigs withForwardSoftLimitThreshold(double newForwardSoftLimitThreshold)
120    {
121        ForwardSoftLimitThreshold = newForwardSoftLimitThreshold;
122        return this;
123    }
124    /**
125     * Modifies this configuration's ReverseSoftLimitThreshold parameter and returns itself for
126     * method-chaining and easier to use config API.
127     * <p>
128     * Position threshold for reverse soft limit features.
129     * ReverseSoftLimitEnable must be enabled for this to take effect.
130     * 
131     * <ul>
132     *   <li> <b>Minimum Value:</b> -3.4e+38
133     *   <li> <b>Maximum Value:</b> 3.4e+38
134     *   <li> <b>Default Value:</b> 0
135     *   <li> <b>Units:</b> rotations
136     * </ul>
137     *
138     * @param newReverseSoftLimitThreshold Parameter to modify
139     * @return Itself
140     */
141    public SoftwareLimitSwitchConfigs withReverseSoftLimitThreshold(double newReverseSoftLimitThreshold)
142    {
143        ReverseSoftLimitThreshold = newReverseSoftLimitThreshold;
144        return this;
145    }
146
147    
148
149    @Override
150    public String toString()
151    {
152        String ss = "Config Group: SoftwareLimitSwitch\n";
153        ss += "Name: \"ForwardSoftLimitEnable\" Value: \"" + ForwardSoftLimitEnable + "\"" + "\n";
154        ss += "Name: \"ReverseSoftLimitEnable\" Value: \"" + ReverseSoftLimitEnable + "\"" + "\n";
155        ss += "Name: \"ForwardSoftLimitThreshold\" Value: \"" + ForwardSoftLimitThreshold + "rotations\"" + "\n";
156        ss += "Name: \"ReverseSoftLimitThreshold\" Value: \"" + ReverseSoftLimitThreshold + "rotations\"" + "\n";
157        return ss;
158    }
159
160    /**
161     *
162     */
163    public StatusCode deserialize(String to_deserialize)
164    {
165        ForwardSoftLimitEnable = ConfigJNI.Deserializeboolean(SpnValue.Config_ForwardSoftLimitEnable.value, to_deserialize);
166        ReverseSoftLimitEnable = ConfigJNI.Deserializeboolean(SpnValue.Config_ReverseSoftLimitEnable.value, to_deserialize);
167        ForwardSoftLimitThreshold = ConfigJNI.Deserializedouble(SpnValue.Config_ForwardSoftLimitThreshold.value, to_deserialize);
168        ReverseSoftLimitThreshold = ConfigJNI.Deserializedouble(SpnValue.Config_ReverseSoftLimitThreshold.value, to_deserialize);
169        return  StatusCode.OK;
170    }
171
172    /**
173     *
174     */
175    public String serialize()
176    {
177        String ss = "";
178        ss += ConfigJNI.Serializeboolean(SpnValue.Config_ForwardSoftLimitEnable.value, ForwardSoftLimitEnable);
179        ss += ConfigJNI.Serializeboolean(SpnValue.Config_ReverseSoftLimitEnable.value, ReverseSoftLimitEnable);
180        ss += ConfigJNI.Serializedouble(SpnValue.Config_ForwardSoftLimitThreshold.value, ForwardSoftLimitThreshold);
181        ss += ConfigJNI.Serializedouble(SpnValue.Config_ReverseSoftLimitThreshold.value, ReverseSoftLimitThreshold);
182        return ss;
183    }
184}
185