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