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.phoenix6.StatusCode;
010import com.ctre.phoenixpro.hardware.DeviceIdentifier;
011import com.ctre.phoenix6.configs.jni.ConfigJNI;
012
013/**
014 * Class for CANcoder, a CAN based magnetic encoder that provides absolute and
015 * relative position along with filtered velocity.
016 *
017 * This handles the configurations for the {@link com.ctre.phoenixpro.hardware.CANcoder}
018 *
019 * @deprecated Classes in the phoenixpro package will be removed in 2024.
020 *             Users should instead use classes from the phoenix6 package.
021 */
022@Deprecated(forRemoval = true)
023public class CANcoderConfigurator extends ParentConfigurator
024{
025    public CANcoderConfigurator (DeviceIdentifier id)
026    {
027        super(id);
028    }
029
030    /**
031     * Refreshes the values of the specified config group.
032     * <p>
033     * This will wait up to {@link #defaultTimeoutSeconds}.
034     * <p>
035     * Call to refresh the selected configs from the device.
036     *
037     * @param configs The configs to refresh
038     * @return StatusCode of refreshing the configs
039     */
040    public StatusCode refresh(CANcoderConfiguration configs)
041    {
042        return refresh(configs, defaultTimeoutSeconds);
043    }
044
045    /**
046     * Refreshes the values of the specified config group.
047     * <p>
048     * Call to refresh the selected configs from the device.
049     *
050     * @param configs The configs to refresh
051     * @param timeoutSeconds Maximum amount of time to wait when performing configuration
052     * @return StatusCode of refreshing the configs
053     */
054    public StatusCode refresh(CANcoderConfiguration configs, double timeoutSeconds)
055    {
056        StringBuilder serializedString = new StringBuilder();
057        StatusCode err = getConfigsPrivate(serializedString, timeoutSeconds);
058        if (err == StatusCode.OK) {
059            /* Only deserialize if we successfully got configs */
060            configs.deserialize(serializedString.toString());
061        }
062        return err;
063    }
064
065    /**
066     * Applies the contents of the specified config to the device.
067     * <p>
068     * This will wait up to {@link #defaultTimeoutSeconds}.
069     * <p>
070     * Call to apply the selected configs.
071     *
072     * @param configs Configs to apply against.
073     * @return StatusCode of the set command
074     */
075    public StatusCode apply(CANcoderConfiguration configs)
076    {
077        return apply(configs, defaultTimeoutSeconds);
078    }
079
080    /**
081     * Applies the contents of the specified config to the device.
082     * <p>
083     * Call to apply the selected configs.
084     *
085     * @param configs Configs to apply against.
086     * @param timeoutSeconds Maximum amount of time to wait when performing configuration
087     * @return StatusCode of the set command
088     */
089    public StatusCode apply(CANcoderConfiguration configs, double timeoutSeconds)
090    {
091        return setConfigsPrivate(configs.serialize(), timeoutSeconds, configs.FutureProofConfigs, false);
092    }
093
094
095    /**
096     * Refreshes the values of the specified config group.
097     * <p>
098     * This will wait up to {@link #defaultTimeoutSeconds}.
099     * <p>
100     * Call to refresh the selected configs from the device.
101     *
102     * @param configs The configs to refresh
103     * @return StatusCode of refreshing the configs
104     */
105    public StatusCode refresh(MagnetSensorConfigs configs)
106    {
107        return refresh(configs, defaultTimeoutSeconds);
108    }
109
110    /**
111     * Refreshes the values of the specified config group.
112     * <p>
113     * Call to refresh the selected configs from the device.
114     *
115     * @param configs The configs to refresh
116     * @param timeoutSeconds Maximum amount of time to wait when performing configuration
117     * @return StatusCode of refreshing the configs
118     */
119    public StatusCode refresh(MagnetSensorConfigs configs, double timeoutSeconds)
120    {
121        StringBuilder serializedString = new StringBuilder();
122        StatusCode err = getConfigsPrivate(serializedString, timeoutSeconds);
123        if (err == StatusCode.OK) {
124            /* Only deserialize if we successfully got configs */
125            configs.deserialize(serializedString.toString());
126        }
127        return err;
128    }
129
130    /**
131     * Applies the contents of the specified config to the device.
132     * <p>
133     * This will wait up to {@link #defaultTimeoutSeconds}.
134     * <p>
135     * Call to apply the selected configs.
136     *
137     * @param configs Configs to apply against.
138     * @return StatusCode of the set command
139     */
140    public StatusCode apply(MagnetSensorConfigs configs)
141    {
142        return apply(configs, defaultTimeoutSeconds);
143    }
144
145    /**
146     * Applies the contents of the specified config to the device.
147     * <p>
148     * Call to apply the selected configs.
149     *
150     * @param configs Configs to apply against.
151     * @param timeoutSeconds Maximum amount of time to wait when performing configuration
152     * @return StatusCode of the set command
153     */
154    public StatusCode apply(MagnetSensorConfigs configs, double timeoutSeconds)
155    {
156        return setConfigsPrivate(configs.serialize(), timeoutSeconds, false, false);
157    }
158
159    
160    /**
161     * The position to set the sensor position to right now.
162     * <p>
163     * This will wait up to {@link #defaultTimeoutSeconds}.
164     * <p>
165     * This is available in the configurator in case the user wants
166     * to initialize their device entirely without passing a device
167     * reference down to the code that performs the initialization.
168     * In this case, the user passes down the configurator object
169     * and performs all the initialization code on the object.
170     *
171     * @param newValue Value to set to.
172     * @return StatusCode of the set command
173     */
174    public StatusCode setPosition(double newValue) {
175        return setPosition(newValue, defaultTimeoutSeconds);
176    }
177    /**
178     * The position to set the sensor position to right now.
179     * <p>
180     * This is available in the configurator in case the user wants
181     * to initialize their device entirely without passing a device
182     * reference down to the code that performs the initialization.
183     * In this case, the user passes down the configurator object
184     * and performs all the initialization code on the object.
185     *
186     * @param newValue Value to set to.
187     * @param timeoutSeconds Maximum time to wait up to in seconds.
188     * @return StatusCode of the set command
189     */
190    public StatusCode setPosition(double newValue, double timeoutSeconds) {
191        String serialized = ConfigJNI.Serializedouble(1010, newValue);
192        return setConfigsPrivate(serialized, timeoutSeconds, false, true);
193    }
194    
195    /**
196     * Clear the sticky faults in the device.
197     * <p>
198     * This typically has no impact on the device functionality.  Instead,
199     * it just clears telemetry faults that are accessible via API and
200     * Tuner Self-Test.
201     * <p>
202     * This will wait up to {@link #defaultTimeoutSeconds}.
203     * <p>
204     * This is available in the configurator in case the user wants
205     * to initialize their device entirely without passing a device
206     * reference down to the code that performs the initialization.
207     * In this case, the user passes down the configurator object
208     * and performs all the initialization code on the object.
209     * @return StatusCode of the set command
210     */
211    public StatusCode clearStickyFaults() {
212        return clearStickyFaults(defaultTimeoutSeconds);
213    }
214    /**
215     * Clear the sticky faults in the device.
216     * <p>
217     * This typically has no impact on the device functionality.  Instead,
218     * it just clears telemetry faults that are accessible via API and
219     * Tuner Self-Test.
220     * <p>
221     * This is available in the configurator in case the user wants
222     * to initialize their device entirely without passing a device
223     * reference down to the code that performs the initialization.
224     * In this case, the user passes down the configurator object
225     * and performs all the initialization code on the object.
226     * @param timeoutSeconds Maximum time to wait up to in seconds.
227     * @return StatusCode of the set command
228     */
229    public StatusCode clearStickyFaults(double timeoutSeconds) {
230        String serialized = ConfigJNI.Serializedouble(1476, 0);
231        return setConfigsPrivate(serialized, timeoutSeconds, false, true);
232    }
233}