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