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 range, sensor direction, and the magnet offset. 039 */ 040 public MagnetSensorConfigs MagnetSensor = new MagnetSensorConfigs(); 041 042 /** 043 * Modifies this configuration's MagnetSensor parameter and returns itself for 044 * method-chaining and easier to use config API. 045 * <p> 046 * Configs that affect the magnet sensor and how to interpret it. 047 * <p> 048 * Includes sensor range, sensor direction, and the magnet offset. 049 * 050 * @param newMagnetSensor Parameter to modify 051 * @return Itself 052 */ 053 public CANcoderConfiguration withMagnetSensor(MagnetSensorConfigs newMagnetSensor) 054 { 055 MagnetSensor = newMagnetSensor; 056 return this; 057 } 058 059 @Override 060 public String toString() 061 { 062 String ss = ""; 063 ss += MagnetSensor.toString(); 064 return ss; 065 } 066 067 /** 068 * Get the serialized form of this configuration 069 * 070 * @return Serialized form of this config group 071 */ 072 public String serialize() 073 { 074 String ss = ""; 075 ss += MagnetSensor.serialize(); 076 return ss; 077 } 078 079 /** 080 * Take a string and deserialize it to this configuration 081 * 082 * @return Return code of the deserialize method 083 */ 084 public StatusCode deserialize(String to_deserialize) 085 { 086 StatusCode err = StatusCode.OK; 087 err = MagnetSensor.deserialize(to_deserialize); 088 return err; 089 } 090};