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