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;
010
011/**
012 * Class for CANcoder, a CAN based magnetic encoder that provides absolute and
013 * relative position along with filtered velocity.
014 *
015 * This handles the configurations for the {@link com.ctre.phoenix6.hardware.CANcoder}
016 */
017public class CANcoderConfiguration implements ParentConfiguration
018{
019    /**
020     * True if we should factory default newer unsupported configs,
021     * false to leave newer unsupported configs alone.
022     * <p>
023     * This flag addresses a corner case where the device may have
024     * firmware with newer configs that didn't exist when this
025     * version of the API was built. If this occurs and this
026     * flag is true, unsupported new configs will be factory
027     * defaulted to avoid unexpected behavior.
028     * <p>
029     * This is also the behavior in Phoenix 5, so this flag
030     * is defaulted to true to match.
031     */
032    public boolean FutureProofConfigs = true;
033
034    
035    /**
036     * Configs that affect the magnet sensor and how to interpret it.
037     * <p>
038     * Includes sensor direction, the sensor discontinuity point, and the
039     * magnet offset.
040     * <p>
041     * Parameter list:
042     * 
043     * <ul>
044     *   <li> {@link MagnetSensorConfigs#SensorDirection}
045     *   <li> {@link MagnetSensorConfigs#MagnetOffset}
046     *   <li> {@link MagnetSensorConfigs#AbsoluteSensorDiscontinuityPoint}
047     * </ul>
048     * 
049     */
050    public MagnetSensorConfigs MagnetSensor = new MagnetSensorConfigs();
051    
052    /**
053     * Custom Params.
054     * <p>
055     * Custom paramaters that have no real impact on controller.
056     * <p>
057     * Parameter list:
058     * 
059     * <ul>
060     *   <li> {@link CustomParamsConfigs#CustomParam0}
061     *   <li> {@link CustomParamsConfigs#CustomParam1}
062     * </ul>
063     * 
064     */
065    public CustomParamsConfigs CustomParams = new CustomParamsConfigs();
066    
067    /**
068     * Modifies this configuration's MagnetSensor parameter and returns itself for
069     * method-chaining and easier to use config API.
070     * <p>
071     * Configs that affect the magnet sensor and how to interpret it.
072     * <p>
073     * Includes sensor direction, the sensor discontinuity point, and the
074     * magnet offset.
075     * <p>
076     * Parameter list:
077     * 
078     * <ul>
079     *   <li> {@link MagnetSensorConfigs#SensorDirection}
080     *   <li> {@link MagnetSensorConfigs#MagnetOffset}
081     *   <li> {@link MagnetSensorConfigs#AbsoluteSensorDiscontinuityPoint}
082     * </ul>
083     * 
084     *
085     * @param newMagnetSensor Parameter to modify
086     * @return Itself
087     */
088    public CANcoderConfiguration withMagnetSensor(MagnetSensorConfigs newMagnetSensor)
089    {
090        MagnetSensor = newMagnetSensor;
091        return this;
092    }
093    
094    /**
095     * Modifies this configuration's CustomParams parameter and returns itself for
096     * method-chaining and easier to use config API.
097     * <p>
098     * Custom Params.
099     * <p>
100     * Custom paramaters that have no real impact on controller.
101     * <p>
102     * Parameter list:
103     * 
104     * <ul>
105     *   <li> {@link CustomParamsConfigs#CustomParam0}
106     *   <li> {@link CustomParamsConfigs#CustomParam1}
107     * </ul>
108     * 
109     *
110     * @param newCustomParams Parameter to modify
111     * @return Itself
112     */
113    public CANcoderConfiguration withCustomParams(CustomParamsConfigs newCustomParams)
114    {
115        CustomParams = newCustomParams;
116        return this;
117    }
118
119    @Override
120    public String toString()
121    {
122        String ss = "CANcoderConfiguration\n";
123        ss += MagnetSensor.toString();
124        ss += CustomParams.toString();
125        return ss;
126    }
127
128    /**
129     * Get the serialized form of this configuration
130     *
131     * @return Serialized form of this config group
132     */
133    public String serialize()
134    {
135        String ss = "";
136        ss += MagnetSensor.serialize();
137        ss += CustomParams.serialize();
138        return ss;
139    }
140
141    /**
142     * Take a string and deserialize it to this configuration
143     *
144     * @return Return code of the deserialize method
145     */
146    public StatusCode deserialize(String to_deserialize)
147    {
148        StatusCode err = StatusCode.OK;
149        err = MagnetSensor.deserialize(to_deserialize);
150        err = CustomParams.deserialize(to_deserialize);
151        return err;
152    }
153};