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.hardware.DeviceIdentifier;
011import com.ctre.phoenixpro.configs.jni.ConfigJNI;
012
013/**
014 * Class description for the Pigeon 2 IMU sensor that measures orientation.
015 *
016 * This handles the configurations for the {@link com.ctre.phoenixpro.hardware.Pigeon2}
017 */
018public class Pigeon2Configurator extends ParentConfigurator
019{
020    public Pigeon2Configurator (DeviceIdentifier id)
021    {
022        super(id);
023    }
024
025    /**
026     * Refreshes the values of the specified config group.
027     * <p>
028     * This will wait up to {@link #defaultTimeoutSeconds}.
029     * <p>
030     * Call to refresh the selected configs from the device.
031     *
032     * @param configs The configs to refresh
033     * @return StatusCode of refreshing the configs
034     */
035    public StatusCode refresh(Pigeon2Configuration configs)
036    {
037        return refresh(configs, defaultTimeoutSeconds);
038    }
039
040    /**
041     * Refreshes the values of the specified config group.
042     * <p>
043     * Call to refresh the selected configs from the device.
044     *
045     * @param configs The configs to refresh
046     * @param timeoutSeconds Maximum amount of time to wait when performing configuration
047     * @return StatusCode of refreshing the configs
048     */
049    public StatusCode refresh(Pigeon2Configuration configs, double timeoutSeconds)
050    {
051        StringBuilder serializedString = new StringBuilder();
052        StatusCode err = getConfigsPrivate(serializedString, timeoutSeconds);
053        if (err == StatusCode.OK) {
054            /* Only deserialize if we successfully got configs */
055            configs.deserialize(serializedString.toString());
056        }
057        return err;
058    }
059
060    /**
061     * Applies the contents of the specified config to the device.
062     * <p>
063     * This will wait up to {@link #defaultTimeoutSeconds}.
064     * <p>
065     * Call to apply the selected configs.
066     *
067     * @param configs Configs to apply against.
068     * @return StatusCode of the set command
069     */
070    public StatusCode apply(Pigeon2Configuration configs)
071    {
072        return apply(configs, defaultTimeoutSeconds);
073    }
074
075    /**
076     * Applies the contents of the specified config to the device.
077     * <p>
078     * Call to apply the selected configs.
079     *
080     * @param configs Configs to apply against.
081     * @param timeoutSeconds Maximum amount of time to wait when performing configuration
082     * @return StatusCode of the set command
083     */
084    public StatusCode apply(Pigeon2Configuration configs, double timeoutSeconds)
085    {
086        return setConfigsPrivate(configs.serialize(), timeoutSeconds, configs.FutureProofConfigs, false);
087    }
088
089
090    /**
091     * Refreshes the values of the specified config group.
092     * <p>
093     * This will wait up to {@link #defaultTimeoutSeconds}.
094     * <p>
095     * Call to refresh the selected configs from the device.
096     *
097     * @param configs The configs to refresh
098     * @return StatusCode of refreshing the configs
099     */
100    public StatusCode refresh(MountPoseConfigs configs)
101    {
102        return refresh(configs, defaultTimeoutSeconds);
103    }
104
105    /**
106     * Refreshes the values of the specified config group.
107     * <p>
108     * Call to refresh the selected configs from the device.
109     *
110     * @param configs The configs to refresh
111     * @param timeoutSeconds Maximum amount of time to wait when performing configuration
112     * @return StatusCode of refreshing the configs
113     */
114    public StatusCode refresh(MountPoseConfigs configs, double timeoutSeconds)
115    {
116        StringBuilder serializedString = new StringBuilder();
117        StatusCode err = getConfigsPrivate(serializedString, timeoutSeconds);
118        if (err == StatusCode.OK) {
119            /* Only deserialize if we successfully got configs */
120            configs.deserialize(serializedString.toString());
121        }
122        return err;
123    }
124
125    /**
126     * Applies the contents of the specified config to the device.
127     * <p>
128     * This will wait up to {@link #defaultTimeoutSeconds}.
129     * <p>
130     * Call to apply the selected configs.
131     *
132     * @param configs Configs to apply against.
133     * @return StatusCode of the set command
134     */
135    public StatusCode apply(MountPoseConfigs configs)
136    {
137        return apply(configs, defaultTimeoutSeconds);
138    }
139
140    /**
141     * Applies the contents of the specified config to the device.
142     * <p>
143     * Call to apply the selected configs.
144     *
145     * @param configs Configs to apply against.
146     * @param timeoutSeconds Maximum amount of time to wait when performing configuration
147     * @return StatusCode of the set command
148     */
149    public StatusCode apply(MountPoseConfigs configs, double timeoutSeconds)
150    {
151        return setConfigsPrivate(configs.serialize(), timeoutSeconds, false, false);
152    }
153
154
155    /**
156     * Refreshes the values of the specified config group.
157     * <p>
158     * This will wait up to {@link #defaultTimeoutSeconds}.
159     * <p>
160     * Call to refresh the selected configs from the device.
161     *
162     * @param configs The configs to refresh
163     * @return StatusCode of refreshing the configs
164     */
165    public StatusCode refresh(GyroTrimConfigs configs)
166    {
167        return refresh(configs, defaultTimeoutSeconds);
168    }
169
170    /**
171     * Refreshes the values of the specified config group.
172     * <p>
173     * Call to refresh the selected configs from the device.
174     *
175     * @param configs The configs to refresh
176     * @param timeoutSeconds Maximum amount of time to wait when performing configuration
177     * @return StatusCode of refreshing the configs
178     */
179    public StatusCode refresh(GyroTrimConfigs configs, double timeoutSeconds)
180    {
181        StringBuilder serializedString = new StringBuilder();
182        StatusCode err = getConfigsPrivate(serializedString, timeoutSeconds);
183        if (err == StatusCode.OK) {
184            /* Only deserialize if we successfully got configs */
185            configs.deserialize(serializedString.toString());
186        }
187        return err;
188    }
189
190    /**
191     * Applies the contents of the specified config to the device.
192     * <p>
193     * This will wait up to {@link #defaultTimeoutSeconds}.
194     * <p>
195     * Call to apply the selected configs.
196     *
197     * @param configs Configs to apply against.
198     * @return StatusCode of the set command
199     */
200    public StatusCode apply(GyroTrimConfigs configs)
201    {
202        return apply(configs, defaultTimeoutSeconds);
203    }
204
205    /**
206     * Applies the contents of the specified config to the device.
207     * <p>
208     * Call to apply the selected configs.
209     *
210     * @param configs Configs to apply against.
211     * @param timeoutSeconds Maximum amount of time to wait when performing configuration
212     * @return StatusCode of the set command
213     */
214    public StatusCode apply(GyroTrimConfigs configs, double timeoutSeconds)
215    {
216        return setConfigsPrivate(configs.serialize(), timeoutSeconds, false, false);
217    }
218
219
220    /**
221     * Refreshes the values of the specified config group.
222     * <p>
223     * This will wait up to {@link #defaultTimeoutSeconds}.
224     * <p>
225     * Call to refresh the selected configs from the device.
226     *
227     * @param configs The configs to refresh
228     * @return StatusCode of refreshing the configs
229     */
230    public StatusCode refresh(Pigeon2FeaturesConfigs configs)
231    {
232        return refresh(configs, defaultTimeoutSeconds);
233    }
234
235    /**
236     * Refreshes the values of the specified config group.
237     * <p>
238     * Call to refresh the selected configs from the device.
239     *
240     * @param configs The configs to refresh
241     * @param timeoutSeconds Maximum amount of time to wait when performing configuration
242     * @return StatusCode of refreshing the configs
243     */
244    public StatusCode refresh(Pigeon2FeaturesConfigs configs, double timeoutSeconds)
245    {
246        StringBuilder serializedString = new StringBuilder();
247        StatusCode err = getConfigsPrivate(serializedString, timeoutSeconds);
248        if (err == StatusCode.OK) {
249            /* Only deserialize if we successfully got configs */
250            configs.deserialize(serializedString.toString());
251        }
252        return err;
253    }
254
255    /**
256     * Applies the contents of the specified config to the device.
257     * <p>
258     * This will wait up to {@link #defaultTimeoutSeconds}.
259     * <p>
260     * Call to apply the selected configs.
261     *
262     * @param configs Configs to apply against.
263     * @return StatusCode of the set command
264     */
265    public StatusCode apply(Pigeon2FeaturesConfigs configs)
266    {
267        return apply(configs, defaultTimeoutSeconds);
268    }
269
270    /**
271     * Applies the contents of the specified config to the device.
272     * <p>
273     * Call to apply the selected configs.
274     *
275     * @param configs Configs to apply against.
276     * @param timeoutSeconds Maximum amount of time to wait when performing configuration
277     * @return StatusCode of the set command
278     */
279    public StatusCode apply(Pigeon2FeaturesConfigs configs, double timeoutSeconds)
280    {
281        return setConfigsPrivate(configs.serialize(), timeoutSeconds, false, false);
282    }
283
284    
285    /**
286     * The yaw to set the Pigeon2 to right now.
287     * <p>
288     * This will wait up to {@link #defaultTimeoutSeconds}.
289     * <p>
290     * This is available in the configurator in case the user wants
291     * to initialize their device entirely without passing a device
292     * reference down to the code that performs the initialization.
293     * In this case, the user passes down the configurator object
294     * and performs all the initialization code on the object.
295     *
296     * @param newValue Value to set to.
297     * @return StatusCode of the set command
298     */
299    public StatusCode setYaw(double newValue) {
300        return setYaw(newValue, defaultTimeoutSeconds);
301    }
302    /**
303     * The yaw to set the Pigeon2 to right now.
304     * <p>
305     * This is available in the configurator in case the user wants
306     * to initialize their device entirely without passing a device
307     * reference down to the code that performs the initialization.
308     * In this case, the user passes down the configurator object
309     * and performs all the initialization code on the object.
310     *
311     * @param newValue Value to set to.
312     * @param timeoutSeconds Maximum time to wait up to in seconds.
313     * @return StatusCode of the set command
314     */
315    public StatusCode setYaw(double newValue, double timeoutSeconds) {
316        String serialized = ConfigJNI.Serializedouble(1012, newValue);
317        return setConfigsPrivate(serialized, timeoutSeconds, false, true);
318    }
319    
320    /**
321     * Clear the sticky faults in the device.
322     * <p>
323     * This typically has no impact on the device functionality.  Instead,
324     * it just clears telemetry faults that are accessible via API and
325     * Tuner Self-Test.
326     * <p>
327     * This will wait up to {@link #defaultTimeoutSeconds}.
328     * <p>
329     * This is available in the configurator in case the user wants
330     * to initialize their device entirely without passing a device
331     * reference down to the code that performs the initialization.
332     * In this case, the user passes down the configurator object
333     * and performs all the initialization code on the object.
334     * @return StatusCode of the set command
335     */
336    public StatusCode clearStickyFaults() {
337        return clearStickyFaults(defaultTimeoutSeconds);
338    }
339    /**
340     * Clear the sticky faults in the device.
341     * <p>
342     * This typically has no impact on the device functionality.  Instead,
343     * it just clears telemetry faults that are accessible via API and
344     * Tuner Self-Test.
345     * <p>
346     * This is available in the configurator in case the user wants
347     * to initialize their device entirely without passing a device
348     * reference down to the code that performs the initialization.
349     * In this case, the user passes down the configurator object
350     * and performs all the initialization code on the object.
351     * @param timeoutSeconds Maximum time to wait up to in seconds.
352     * @return StatusCode of the set command
353     */
354    public StatusCode clearStickyFaults(double timeoutSeconds) {
355        String serialized = ConfigJNI.Serializedouble(1476, 0);
356        return setConfigsPrivate(serialized, timeoutSeconds, false, true);
357    }
358}