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