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