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