001package com.ctre.phoenix.motorcontrol;
002
003import java.util.HashMap;
004
005/**
006 * Choose the limit switch source for a motor controller
007 */
008public enum LimitSwitchSource {
009        /**
010         * Use a limit switch connected directly
011         * to the motor controller
012         */
013        FeedbackConnector(0), 
014    /**
015     * Use the limit switch connected
016     * to a Talon
017     */
018        RemoteTalon(1), 
019    /**
020     * Use the limit switch connected
021     * to a TalonSRX
022     */
023        RemoteTalonSRX(1), 
024    /**
025     * Use the limit switch connected
026     * to a CANifier 
027     */ 
028        RemoteCANifier(2), 
029    /**
030     * Don't use a limit switch
031     */
032        Deactivated(3);
033
034        /**
035         * Value of LimitSwitchSource
036         */
037        public final int value;
038
039        /**
040         * Create LimitSwitchSource of specified value
041         * @param value Value of LimitSwitchSource
042         */
043        LimitSwitchSource(int value) {
044                this.value = value;
045        }
046    /** Keep singleton map to quickly lookup enum via int */
047    private static HashMap<Integer, LimitSwitchSource> _map = null;
048        /** static c'tor, prepare the map */
049    static {
050        _map = new HashMap<Integer, LimitSwitchSource>();
051                for (LimitSwitchSource type : LimitSwitchSource.values()) {
052                        _map.put(type.value, type);
053                }
054        }
055        /**
056         * Get LimitSwitchSource of specified value
057         * @param value Value of LimitSwitchSource
058         * @return LimitSwitchSource of specified value
059         */
060        public static LimitSwitchSource valueOf(int value) {
061                LimitSwitchSource retval = _map.get(value);
062                if (retval != null)
063                        return retval;
064                return FeedbackConnector;
065        }
066        /**
067         * Get LimitSwitchSource of specified value
068         * @param value Value of LimitSwitchSource
069         * @return LimitSwitchSource of specified value
070         */
071    public static LimitSwitchSource valueOf(double value) {
072        return valueOf((int) value); 
073        }
074        /**
075         * @return RemoteLimitSwitchSource of LimitSwitchSource
076         */
077        public RemoteLimitSwitchSource getRemote() {
078                switch (value) {
079                        case 1: return RemoteLimitSwitchSource.RemoteTalon;
080                        case 2: return RemoteLimitSwitchSource.RemoteCANifier;
081                        default: return RemoteLimitSwitchSource.Deactivated;
082                }
083        } 
084        /**
085         * @return String representation of LimitSwitchSource
086         */
087    public String toString() {
088        switch(value) {
089            case 0 : return "LimitSwitchSource.FeedbackConnector";
090            case 1 : return "LimitSwitchSource.RemoteTalon";
091            case 2 : return "LimitSwitchSource.RemoteCANifier";
092            case 3 : return "LimitSwitchSource.Deactivated";
093            default : return "InvalidValue";
094        }
095
096    }
097
098};