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.*;
012import com.ctre.phoenixpro.signals.*;
013
014/**
015 *  Configs that directly affect motor-output.
016 * <p>
017 *  Includes Motor Invert and various limit features.
018 */
019public class HardwareLimitSwitchConfigs implements ParentConfiguration
020{
021    /**
022     * Determines if limit is normally-open (default) or normally-closed.
023     *
024     */
025    public ForwardLimitTypeValue ForwardLimitType = ForwardLimitTypeValue.NormallyOpen;
026    /**
027     * If enabled, the position is auto-set to a specific value, specified
028     * by ForwardLimitAutosetPositionValue
029     *
030     *  <ul>
031     *  <li> <b>Default Value:</b> False
032     *  </ul>
033     */
034    public boolean ForwardLimitAutosetPositionEnable = false;
035    /**
036     * The value to auto-set the position to.  This has no effect if
037     * ForwardLimitAutosetPositionEnable is false.
038     *
039     *  <ul>
040     *  <li> <b>Minimum Value:</b> -3.4e+38
041     *  <li> <b>Maximum Value:</b> 3.4e+38
042     *  <li> <b>Default Value:</b> 0
043     *  <li> <b>Units:</b> rotations
044     *  </ul>
045     */
046    public double ForwardLimitAutosetPositionValue = 0;
047    /**
048     * If enabled, motor output is set to neutral when forward limit
049     * switch is asseted and positive output is requested.
050     *
051     *  <ul>
052     *  <li> <b>Default Value:</b> True
053     *  </ul>
054     */
055    public boolean ForwardLimitEnable = true;
056    /**
057     * Determines where to poll the forward limit switch.  This defaults
058     * to the limit switch pin on the limit switch connector.
059     *
060     */
061    public ForwardLimitSourceValue ForwardLimitSource = ForwardLimitSourceValue.LimitSwitchPin;
062    /**
063     * Device ID of the device if using remote limit switch features.
064     *
065     *  <ul>
066     *  <li> <b>Minimum Value:</b> 0
067     *  <li> <b>Maximum Value:</b> 62
068     *  <li> <b>Default Value:</b> 0
069     *  <li> <b>Units:</b> 
070     *  </ul>
071     */
072    public int ForwardLimitRemoteSensorID = 0;
073    /**
074     * Determines if limit is normally-open (default) or normally-closed.
075     *
076     */
077    public ReverseLimitTypeValue ReverseLimitType = ReverseLimitTypeValue.NormallyOpen;
078    /**
079     * If enabled, the position is auto-set to a specific value, specified
080     * by ReverseLimitAutosetPositionValue
081     *
082     *  <ul>
083     *  <li> <b>Default Value:</b> False
084     *  </ul>
085     */
086    public boolean ReverseLimitAutosetPositionEnable = false;
087    /**
088     * The value to auto-set the position to.  This has no effect if
089     * ReverseLimitAutosetPositionEnable is false.
090     *
091     *  <ul>
092     *  <li> <b>Minimum Value:</b> -3.4e+38
093     *  <li> <b>Maximum Value:</b> 3.4e+38
094     *  <li> <b>Default Value:</b> 0
095     *  <li> <b>Units:</b> rotations
096     *  </ul>
097     */
098    public double ReverseLimitAutosetPositionValue = 0;
099    /**
100     * If enabled, motor output is set to neutral when reverse limit
101     * switch is asseted and positive output is requested.
102     *
103     *  <ul>
104     *  <li> <b>Default Value:</b> True
105     *  </ul>
106     */
107    public boolean ReverseLimitEnable = true;
108    /**
109     * Determines where to poll the reverse limit switch.  This defaults
110     * to the limit switch pin on the limit switch connector.
111     *
112     */
113    public ReverseLimitSourceValue ReverseLimitSource = ReverseLimitSourceValue.LimitSwitchPin;
114    /**
115     * Device ID of the device if using remote limit switch features.
116     *
117     *  <ul>
118     *  <li> <b>Minimum Value:</b> 0
119     *  <li> <b>Maximum Value:</b> 62
120     *  <li> <b>Default Value:</b> 0
121     *  <li> <b>Units:</b> 
122     *  </ul>
123     */
124    public int ReverseLimitRemoteSensorID = 0;
125
126    @Override
127    public String toString()
128    {
129        String ss = "Config Group: HardwareLimitSwitch\n";
130        ss += "Name: \"ForwardLimitType\" Value: \"" + ForwardLimitType + "\"" + "\n";
131        ss += "Name: \"ForwardLimitAutosetPositionEnable\" Value: \"" + ForwardLimitAutosetPositionEnable + "\"" + "\n";
132        ss += "Name: \"ForwardLimitAutosetPositionValue\" Value: \"" + ForwardLimitAutosetPositionValue + "rotations\"" + "\n";
133        ss += "Name: \"ForwardLimitEnable\" Value: \"" + ForwardLimitEnable + "\"" + "\n";
134        ss += "Name: \"ForwardLimitSource\" Value: \"" + ForwardLimitSource + "\"" + "\n";
135        ss += "Name: \"ForwardLimitRemoteSensorID\" Value: \"" + ForwardLimitRemoteSensorID + "\"" + "\n";
136        ss += "Name: \"ReverseLimitType\" Value: \"" + ReverseLimitType + "\"" + "\n";
137        ss += "Name: \"ReverseLimitAutosetPositionEnable\" Value: \"" + ReverseLimitAutosetPositionEnable + "\"" + "\n";
138        ss += "Name: \"ReverseLimitAutosetPositionValue\" Value: \"" + ReverseLimitAutosetPositionValue + "rotations\"" + "\n";
139        ss += "Name: \"ReverseLimitEnable\" Value: \"" + ReverseLimitEnable + "\"" + "\n";
140        ss += "Name: \"ReverseLimitSource\" Value: \"" + ReverseLimitSource + "\"" + "\n";
141        ss += "Name: \"ReverseLimitRemoteSensorID\" Value: \"" + ReverseLimitRemoteSensorID + "\"" + "\n";
142        return ss;
143    }
144
145    /**
146     *
147     */
148    public StatusCode deserialize(String string)
149    {
150        ForwardLimitType = ForwardLimitTypeValue.valueOf(ConfigJNI.Deserializeint(SpnValue.Config_ForwardLimitType.value, string));
151        ForwardLimitAutosetPositionEnable = ConfigJNI.Deserializeboolean(SpnValue.Config_ForwardLimitAutosetPosEnable.value, string);
152        ForwardLimitAutosetPositionValue = ConfigJNI.Deserializedouble(SpnValue.Config_ForwardLimitAutosetPosValue.value, string);
153        ForwardLimitEnable = ConfigJNI.Deserializeboolean(SpnValue.Config_ForwardLimitEnable.value, string);
154        ForwardLimitSource = ForwardLimitSourceValue.valueOf(ConfigJNI.Deserializeint(SpnValue.Config_ForwardLimitSource.value, string));
155        ForwardLimitRemoteSensorID = ConfigJNI.Deserializeint(SpnValue.Config_ForwardLimitRemoteSensorID.value, string);
156        ReverseLimitType = ReverseLimitTypeValue.valueOf(ConfigJNI.Deserializeint(SpnValue.Config_ReverseLimitType.value, string));
157        ReverseLimitAutosetPositionEnable = ConfigJNI.Deserializeboolean(SpnValue.Config_ReverseLimitAutosetPosEnable.value, string);
158        ReverseLimitAutosetPositionValue = ConfigJNI.Deserializedouble(SpnValue.Config_ReverseLimitAutosetPosValue.value, string);
159        ReverseLimitEnable = ConfigJNI.Deserializeboolean(SpnValue.Config_ReverseLimitEnable.value, string);
160        ReverseLimitSource = ReverseLimitSourceValue.valueOf(ConfigJNI.Deserializeint(SpnValue.Config_ReverseLimitSource.value, string));
161        ReverseLimitRemoteSensorID = ConfigJNI.Deserializeint(SpnValue.Config_ReverseLimitRemoteSensorID.value, string);
162        return  StatusCode.OK;
163    }
164
165    /**
166     *
167     */
168    public String serialize()
169    {
170        String ss = "";
171        ss += ConfigJNI.Serializeint(1449, ForwardLimitType.value);
172        ss += ConfigJNI.Serializeboolean(1450, ForwardLimitAutosetPositionEnable);
173        ss += ConfigJNI.Serializedouble(1451, ForwardLimitAutosetPositionValue);
174        ss += ConfigJNI.Serializeboolean(1452, ForwardLimitEnable);
175        ss += ConfigJNI.Serializeint(1453, ForwardLimitSource.value);
176        ss += ConfigJNI.Serializeint(1454, ForwardLimitRemoteSensorID);
177        ss += ConfigJNI.Serializeint(1455, ReverseLimitType.value);
178        ss += ConfigJNI.Serializeboolean(1456, ReverseLimitAutosetPositionEnable);
179        ss += ConfigJNI.Serializedouble(1457, ReverseLimitAutosetPositionValue);
180        ss += ConfigJNI.Serializeboolean(1458, ReverseLimitEnable);
181        ss += ConfigJNI.Serializeint(1459, ReverseLimitSource.value);
182        ss += ConfigJNI.Serializeint(1460, ReverseLimitRemoteSensorID);
183        return ss;
184    }
185}
186