001package com.ctre.phoenix.motorcontrol;
002
003import java.util.HashMap;
004
005/**
006 * Choose the feedback device for a selected sensor
007 */
008public enum TalonSRXFeedbackDevice {    
009        /**
010         * Quadrature encoder
011         */
012        QuadEncoder(0),
013        /**
014         * Analog potentiometer/encoder
015         */
016        Analog(2),
017        /**
018         * Tachometer
019         */
020        Tachometer(4),
021        /**
022         * CTRE Mag Encoder in Relative mode or
023         * any other device that uses PWM to encode its output
024         */
025        PulseWidthEncodedPosition(8),
026
027        /**
028         * Sum0 + Sum1
029         */
030        SensorSum(9),
031        /**
032         * Diff0 - Diff1
033         */
034        SensorDifference(10),
035        /**
036         * Sensor configured in RemoteFilter0
037         */
038        RemoteSensor0(11),
039        /**
040         * Sensor configured in RemoteFilter1
041         */
042        RemoteSensor1(12),
043        /**
044         * Position and velocity will read 0.
045         */
046        None(14),
047        /**
048         * Motor Controller will fake a sensor based on applied motor output.
049         */
050        SoftwareEmulatedSensor(15),
051
052        /**
053         * CTR mag encoder configured in absolute, is the same 
054         * as a PWM sensor.
055         */
056        CTRE_MagEncoder_Absolute(8),
057        /**
058         * CTR mag encoder configured in relative, is the same 
059         * as an quadrature encoder sensor.
060         */
061        CTRE_MagEncoder_Relative(0);
062        
063        /** Value of Feedback Device */
064        public final int value;
065
066        /**
067         * Create Feedback device of initValue
068         * @param initValue Value of TalonSRXFeedbackDevice
069         */
070        TalonSRXFeedbackDevice(int initValue)
071        {
072                this.value = initValue;
073        }
074    /** Keep singleton map to quickly lookup enum via int */
075    private static HashMap<Integer, TalonSRXFeedbackDevice> _map = null;
076        /** static c'tor, prepare the map */
077    static {
078        _map = new HashMap<Integer, TalonSRXFeedbackDevice>();
079                for (TalonSRXFeedbackDevice type : TalonSRXFeedbackDevice.values()) {
080                        _map.put(type.value, type);
081                }
082    }
083        /**
084         * Get TalonSRXFeedbackDevice from specified value
085         * @param value Value of TalonSRXFeedbackDevice
086         * @return TalonSRXFeedbackDevice of specified value
087         */
088        public static TalonSRXFeedbackDevice valueOf(int value) {
089                TalonSRXFeedbackDevice retval = _map.get(value);
090                if (retval != null)
091                        return retval;
092                return QuadEncoder;
093        }
094        /**
095         * Get TalonSRXFeedbackDevice from specified value
096         * @param value Value of TalonSRXFeedbackDevice
097         * @return TalonSRXFeedbackDevice of specified value
098         */
099    public static TalonSRXFeedbackDevice valueOf(double value) {
100        return valueOf((int) value); 
101        }
102        
103        /**
104         * @return string representation of specified TalonSRXFeedbackDevice
105         */
106    public String toString() {
107        switch(value) {
108            case 0 : return "TalonSRXFeedbackDevice.QuadEncoder";
109            case 2 : return "TalonSRXFeedbackDevice.Analog";
110            case 4 : return "TalonSRXFeedbackDevice.Tachometer";
111            case 8 : return "TalonSRXFeedbackDevice.PulseWidthEncodedPosition";
112            case 9 : return "TalonSRXFeedbackDevice.SensorSum";
113            case 10: return "TalonSRXFeedbackDevice.SensorDifference";
114            case 11: return "TalonSRXFeedbackDevice.RemoteSensor0";
115            case 12: return "TalonSRXFeedbackDevice.RemoteSensor1";
116                        case 14: return "TalonSRXFeedbackDevice.None";
117            case 15: return "TalonSRXFeedbackDevice.SoftwareEmulatedSensor";
118            default: return "InvalidValue";
119
120        }
121
122    }
123        
124        /**
125         * Helper method to convert to generic FeedbackDevice enum.
126         * @return value cast as FeedbackDevice
127         */
128        public FeedbackDevice toFeedbackDevice(){
129                switch(value) {
130                        case 0 : return FeedbackDevice.QuadEncoder;
131                        case 2 : return FeedbackDevice.Analog;
132                        case 4 : return FeedbackDevice.Tachometer;
133                        case 8 : return FeedbackDevice.PulseWidthEncodedPosition;
134                        case 9 : return FeedbackDevice.SensorSum;
135                        case 10: return FeedbackDevice.SensorDifference;
136                        case 11: return FeedbackDevice.RemoteSensor0;
137                        case 12: return FeedbackDevice.RemoteSensor1;
138                        case 14: return FeedbackDevice.None;
139                        case 15: return FeedbackDevice.SoftwareEmulatedSensor;
140                        default: return FeedbackDevice.QuadEncoder;
141                }
142        }
143
144};