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.phoenix6.configs.jni.ConfigJNI;
011import com.ctre.phoenix6.spns.*;
012import com.ctre.phoenixpro.signals.*;
013
014/**
015 *  Configs that affect the magnet sensor and how to interpret it.
016 * <p>
017 *  Includes sensor range and other configs related to sensor.
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 MagnetSensorConfigs implements ParentConfiguration
024{
025    /**
026     * Direction of the sensor to determine positive facing the LED side
027     * of the CANcoder.
028     *
029     */
030    public SensorDirectionValue SensorDirection = SensorDirectionValue.CounterClockwise_Positive;
031    /**
032     * This offset is added to the reported position, allowing the
033     * application to trim the zero position.  When set to the default
034     * value of zero, position reports zero when magnet north pole aligns
035     * with the LED.
036     *
037     *  <ul>
038     *  <li> <b>Minimum Value:</b> -1
039     *  <li> <b>Maximum Value:</b> 1
040     *  <li> <b>Default Value:</b> 0
041     *  <li> <b>Units:</b> rotations
042     *  </ul>
043     */
044    public double MagnetOffset = 0;
045    /**
046     * The range of the absolute sensor, either [0, 1) or [-0.5, 0.5).
047     *
048     */
049    public AbsoluteSensorRangeValue AbsoluteSensorRange = AbsoluteSensorRangeValue.Unsigned_0To1;
050
051    @Override
052    public String toString()
053    {
054        String ss = "Config Group: MagnetSensor\n";
055        ss += "Name: \"SensorDirection\" Value: \"" + SensorDirection + "\"" + "\n";
056        ss += "Name: \"MagnetOffset\" Value: \"" + MagnetOffset + "rotations\"" + "\n";
057        ss += "Name: \"AbsoluteSensorRange\" Value: \"" + AbsoluteSensorRange + "\"" + "\n";
058        return ss;
059    }
060
061    /**
062     *
063     */
064    public StatusCode deserialize(String string)
065    {
066        SensorDirection = SensorDirectionValue.valueOf(ConfigJNI.Deserializeint(SpnValue.CANcoder_SensorDirection.value, string));
067        MagnetOffset = ConfigJNI.Deserializedouble(SpnValue.CANCoder_MagnetOffset.value, string);
068        AbsoluteSensorRange = AbsoluteSensorRangeValue.valueOf(ConfigJNI.Deserializeint(SpnValue.CANcoder_AbsoluteSensorRange.value, string));
069        return  StatusCode.OK;
070    }
071
072    /**
073     *
074     */
075    public String serialize()
076    {
077        String ss = "";
078        ss += ConfigJNI.Serializeint(821, SensorDirection.value);
079        ss += ConfigJNI.Serializedouble(1003, MagnetOffset);
080        ss += ConfigJNI.Serializeint(1004, AbsoluteSensorRange.value);
081        return ss;
082    }
083}
084