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 * Custom Params.
015 * <p>
016 * Custom paramaters that have no real impact on controller.
017 */
018public class CustomParamsConfigs implements ParentConfiguration, Cloneable {
019    /**
020     * Custom parameter 0.  This is provided to allow end-applications to
021     * store persistent information in the device.
022     * 
023     * <ul>
024     *   <li> <b>Minimum Value:</b> -32768
025     *   <li> <b>Maximum Value:</b> 32767
026     *   <li> <b>Default Value:</b> 0
027     *   <li> <b>Units:</b> 
028     * </ul>
029     */
030    public int CustomParam0 = 0;
031    /**
032     * Custom parameter 1.  This is provided to allow end-applications to
033     * store persistent information in the device.
034     * 
035     * <ul>
036     *   <li> <b>Minimum Value:</b> -32768
037     *   <li> <b>Maximum Value:</b> 32767
038     *   <li> <b>Default Value:</b> 0
039     *   <li> <b>Units:</b> 
040     * </ul>
041     */
042    public int CustomParam1 = 0;
043    
044    /**
045     * Modifies this configuration's CustomParam0 parameter and returns itself for
046     * method-chaining and easier to use config API.
047     * <p>
048     * Custom parameter 0.  This is provided to allow end-applications to
049     * store persistent information in the device.
050     * 
051     * <ul>
052     *   <li> <b>Minimum Value:</b> -32768
053     *   <li> <b>Maximum Value:</b> 32767
054     *   <li> <b>Default Value:</b> 0
055     *   <li> <b>Units:</b> 
056     * </ul>
057     *
058     * @param newCustomParam0 Parameter to modify
059     * @return Itself
060     */
061    public final CustomParamsConfigs withCustomParam0(int newCustomParam0)
062    {
063        CustomParam0 = newCustomParam0;
064        return this;
065    }
066    
067    /**
068     * Modifies this configuration's CustomParam1 parameter and returns itself for
069     * method-chaining and easier to use config API.
070     * <p>
071     * Custom parameter 1.  This is provided to allow end-applications to
072     * store persistent information in the device.
073     * 
074     * <ul>
075     *   <li> <b>Minimum Value:</b> -32768
076     *   <li> <b>Maximum Value:</b> 32767
077     *   <li> <b>Default Value:</b> 0
078     *   <li> <b>Units:</b> 
079     * </ul>
080     *
081     * @param newCustomParam1 Parameter to modify
082     * @return Itself
083     */
084    public final CustomParamsConfigs withCustomParam1(int newCustomParam1)
085    {
086        CustomParam1 = newCustomParam1;
087        return this;
088    }
089
090    
091
092    @Override
093    public String toString() {
094        String ss = "Config Group: CustomParams\n";
095        ss += "    CustomParam0: " + CustomParam0 + "\n";
096        ss += "    CustomParam1: " + CustomParam1 + "\n";
097        return ss;
098    }
099
100    /**
101     * Get the serialized form of this configuration group.
102     *
103     * @return Serialized form of this config group
104     */
105    @Override
106    public final String serialize() {
107        String ss = "";
108        ss += ConfigJNI.Serializeint(SpnValue.CustomParam0.value, CustomParam0);
109        ss += ConfigJNI.Serializeint(SpnValue.CustomParam1.value, CustomParam1);
110        return ss;
111    }
112
113    /**
114     * Take a string and deserialize it to this configuration group.
115     *
116     * @return Return code of the deserialize method
117     */
118    @Override
119    public final StatusCode deserialize(String to_deserialize) {
120        CustomParam0 = ConfigJNI.Deserializeint(SpnValue.CustomParam0.value, to_deserialize);
121        CustomParam1 = ConfigJNI.Deserializeint(SpnValue.CustomParam1.value, to_deserialize);
122        return  StatusCode.OK;
123    }
124
125    @Override
126    public CustomParamsConfigs clone() {
127        try {
128            return (CustomParamsConfigs)super.clone();
129        } catch (CloneNotSupportedException ex) {
130            /* this should never happen */
131            throw new RuntimeException(ex);
132        }
133    }
134}
135