001package com.ctre.phoenix.motorcontrol;
002
003import java.util.HashMap;
004
005/**
006 * Choose the feedback device for a selected sensor
007 */
008public enum TalonFXFeedbackDevice {     
009        /**
010         * TalonFX supports an integrated sensor.
011         */
012        IntegratedSensor(1),
013        /**
014         * Sum0 + Sum1
015         */
016        SensorSum(9),
017        /**
018         * Diff0 - Diff1
019         */
020        SensorDifference(10),
021        /**
022         * Sensor configured in RemoteFilter0
023         */
024        RemoteSensor0(11),
025        /**
026         * Sensor configured in RemoteFilter1
027         */
028        RemoteSensor1(12),
029        /**
030         * Position and velocity will read 0.
031         */
032        None(14),
033        /**
034         * Motor Controller will fake a sensor based on applied motor output.
035         */
036        SoftwareEmulatedSensor(15);
037        
038        /** Value of Feedback Device */
039        public final int value;
040
041        /**
042         * Create Feedback device of initValue
043         * @param initValue Value of TalonFXFeedbackDevice
044         */
045        TalonFXFeedbackDevice(int initValue)
046        {
047                this.value = initValue;
048        }
049    /** Keep singleton map to quickly lookup enum via int */
050    private static HashMap<Integer, TalonFXFeedbackDevice> _map = null;
051        /** static c'tor, prepare the map */
052    static {
053        _map = new HashMap<Integer, TalonFXFeedbackDevice>();
054                for (TalonFXFeedbackDevice type : TalonFXFeedbackDevice.values()) {
055                        _map.put(type.value, type);
056                }
057    }
058        /**
059         * Get TalonFXFeedbackDevice from specified value
060         * @param value Value of TalonFXFeedbackDevice
061         * @return TalonFXFeedbackDevice of specified value
062         */
063        public static TalonFXFeedbackDevice valueOf(int value) {
064                TalonFXFeedbackDevice retval = _map.get(value);
065                if (retval != null)
066                        return retval;
067                return IntegratedSensor;
068        }
069        /**
070         * Get TalonFXFeedbackDevice from specified value
071         * @param value Value of TalonFXFeedbackDevice
072         * @return TalonFXFeedbackDevice of specified value
073         */
074    public static TalonFXFeedbackDevice valueOf(double value) {
075        return valueOf((int) value); 
076        }
077        
078        /**
079         * @return string representation of specified TalonFXFeedbackDevice
080         */
081    public String toString() {
082        switch(value) {
083            case 1 : return "TalonFXFeedbackDevice.IntegratedSensor";
084            case 9 : return "TalonFXFeedbackDevice.SensorSum";
085            case 10: return "TalonFXFeedbackDevice.SensorDifference";
086            case 11: return "TalonFXFeedbackDevice.RemoteSensor0";
087            case 12: return "TalonFXFeedbackDevice.RemoteSensor1";
088                        case 14: return "TalonFXFeedbackDevice.None";
089            case 15: return "TalonFXFeedbackDevice.SoftwareEmulatedSensor";
090            default: return "InvalidValue";
091
092        }
093
094        }
095        
096        /**
097         * Helper method to convert to generic FeedbackDevice enum.
098         * @return value cast as FeedbackDevice
099         */
100        public FeedbackDevice toFeedbackDevice(){
101                switch(value) {
102                        case 1 : return FeedbackDevice.IntegratedSensor;
103                        case 9 : return FeedbackDevice.SensorSum;
104                        case 10: return FeedbackDevice.SensorDifference;
105                        case 11: return FeedbackDevice.RemoteSensor0;
106                        case 12: return FeedbackDevice.RemoteSensor1;
107                        case 14: return FeedbackDevice.None;
108                        case 15: return FeedbackDevice.SoftwareEmulatedSensor;
109                        default: return FeedbackDevice.IntegratedSensor;
110                }
111        }
112
113};